This repository has been archived by the owner on Jul 13, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
Copy patharnu-tester.py
executable file
·95 lines (71 loc) · 2.91 KB
/
arnu-tester.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
#!/usr/bin/env python
"""
Test tool for parsing ARNU messages
Copyright (C) 2015 Geert Wirken
This program is free software: you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation, either version 3 of the License, or
(at your option) any later version.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program. If not, see <http://www.gnu.org/licenses/>.
"""
import sys
import os
import logging
import logging.config
import yaml
import argparse
from datetime import datetime
import serviceinfo.arnu
import serviceinfo.iff
import serviceinfo.service_store
import serviceinfo.common
def load_dummy_messages(filename):
logger = logging.getLogger(__name__)
logger.debug('Initializing store')
iff = serviceinfo.iff.IffSource(serviceinfo.common.configuration['iff_database'])
store = serviceinfo.service_store.ServiceStore(serviceinfo.common.configuration['schedule_store'])
logger.info('Loading message dump')
line_counter = 0
msg_counter = 0
service_counter = 0
try:
with open(filename, 'r') as f:
for line in f:
line_counter = line_counter + 1
services = serviceinfo.arnu.parse_arnu_message(line, iff)
if services == None:
logger.warning('Could not process line %s', line_counter)
else:
msg_counter = msg_counter + 1
for service, action in services:
service_counter = service_counter + 1
serviceinfo.arnu.process_arnu_service(service, action, store, store.TYPE_ACTUAL)
logger.info('Finished processing %s services from %s ARNU messages' % (service_counter, msg_counter))
except IOError as e:
logger.error('File %s could not be opened: %s' % (filename, e))
sys.exit(1)
def main():
"""
Main loop
"""
global config
# Initialize argparse
parser = argparse.ArgumentParser(description='RDT Serviceinfo / ARNU realtime message tester')
parser.add_argument('-c', '--config', dest='configFile', default='config/serviceinfo.yaml',
action='store', help='Configuration file')
parser.add_argument('FILE', nargs=1, action='store', help='ARNU message file (one XML message per line)')
args = parser.parse_args()
# Load configuration:
serviceinfo.common.load_config(args.configFile)
serviceinfo.common.setup_logging('arnu-tester')
# Get logger instance:
logger = logging.getLogger(__name__)
logger.info('Test tool starting')
load_dummy_messages(args.FILE[0])
if __name__ == "__main__":
main()