-
Notifications
You must be signed in to change notification settings - Fork 10
/
Copy pathmain.py
executable file
·119 lines (88 loc) · 2.99 KB
/
main.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
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
#!/usr/bin/env python3
import logging
import signal
import sys
import gi
from lib.system_health_reporter import SystemHealthReporter
gi.require_version('Gst', '1.0')
gi.require_version('GstNet', '1.0')
from gi.repository import Gst, GObject
# import local classes
from lib.loghandler import LogHandler
from lib.pipeline import Pipeline
from lib.status_server import StatusServer
import lib.args
import lib.config
# check min-version
minGst = (1, 5)
minPy = (3, 0)
Gst.init([])
if Gst.version() < minGst:
raise Exception('GStreamer version', Gst.version(),
'is too old, at least', minGst, 'is required')
if sys.version_info < minPy:
raise Exception('Python version', sys.version_info,
'is too old, at least', minPy, 'is required')
# init GObject & Co. before importing local classes
GObject.threads_init()
class Backuptool(object):
def __init__(self, config):
"""
:type config lib.config.VocConfigParser
"""
self.config = config
# initialize mainloop
self.log = logging.getLogger('Main')
self.log.debug('creating GObject-MainLoop')
self.mainloop = GObject.MainLoop()
# initialize subsystem
self.log.debug('creating Status-Server')
self.statusServer = StatusServer(config)
self.log.debug('creating System-Health Reporter')
self.systemHealthReporter = SystemHealthReporter(config, self.statusServer)
self.log.debug('creating Audio-Pipeline')
self.pipeline = Pipeline(config, self.statusServer)
def run(self):
self.log.info('starting Pipeline')
self.pipeline.start()
try:
self.log.info('running GObject-MainLoop')
self.mainloop.run()
except KeyboardInterrupt:
self.log.info('Terminated via Ctrl-C')
def quit(self):
self.log.info('quitting GObject-MainLoop')
self.mainloop.quit()
# run mainclass
def main():
# parse command-line args
args = lib.args.parse()
docolor = (args.color == 'always') \
or (args.color == 'auto' and sys.stderr.isatty())
handler = LogHandler(docolor, args.timestamp)
logging.root.handlers = [handler]
if args.verbose >= 2:
level = logging.DEBUG
elif args.verbose == 1:
level = logging.INFO
else:
level = logging.WARNING
logging.root.setLevel(level)
# make killable by ctrl-c
logging.debug('setting SIGINT handler')
signal.signal(signal.SIGINT, signal.SIG_DFL)
logging.info('Python Version: %s', sys.version_info)
logging.info('GStreamer Version: %s', Gst.version())
logging.debug('loading Config')
config = lib.config.load(args)
# init main-class and main-loop
logging.debug('initializing AES67-Backup')
backup_tool = Backuptool(config)
logging.debug('running AES67-Backup')
backup_tool.run()
if __name__ == '__main__':
try:
main()
except RuntimeError as e:
logging.error(str(e))
sys.exit(1)