-
Notifications
You must be signed in to change notification settings - Fork 4
/
openadms-launcher.pyw
120 lines (99 loc) · 4.09 KB
/
openadms-launcher.pyw
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
120
#!/usr/bin/env python3.6
"""OpenADMS Node Graphical Launcher
This Python script starts OpenADMS Node by using a graphical launcher. You have
to install the Python modules `wxPython` and `Gooey` with pip at first::
$ pipenv install Gooey
For more information, please visit https://www.dabamos.de/.
"""
__author__ = 'Philipp Engel'
__copyright__ = 'Copyright (c) 2017 Hochschule Neubrandenburg'
__license__ = 'BSD-2-Clause'
import argparse
import logging
import signal
import sys
from gooey import Gooey, GooeyParser
from core.system import System
from openadms import (exception_hook, main, setup_logging,
setup_thread_exception_hook, sighup_handler,
sigint_handler, start_mqtt_message_broker, valid_path)
logger = logging.getLogger()
@Gooey(advanced=True,
language='english',
program_name=('OpenADMS Node {} - '
'Open Automatic Deformation Monitoring System'
.format(System.get_openadms_version())),
default_size=(610, 580),
monospace_display=True,
image_dir='./extra')
def mainw() -> None:
"""Wrapper routine to run OpenADMS Node windowed."""
parser = GooeyParser(
description='OpenADMS Node {} - Open Automatic Deformation Monitoring '
'System'.format(System.get_openadms_version()))
parser.add_argument('-c', '--config',
metavar='Configuration File',
help='Path to the configuration file',
dest='config_file_path',
action='store',
default='./config/config.json',
required=True,
widget='FileChooser')
parser.add_argument('-v', '--verbosity',
metavar='Verbosity Level (1 - 9)',
help='Log more diagnostic messages',
dest='verbosity',
action='count',
default=6)
parser.add_argument('-d', '--debug',
metavar='Debug',
help='Print debug messages',
dest='is_debug',
action='store_true',
default=False)
parser.add_argument('-m', '--with-mqtt-broker',
metavar='MQTT',
help='Run internal MQTT message broker',
dest='is_mqtt_broker',
action='store_true',
default=True)
parser.add_argument('-l', '--log-file',
metavar='Log File',
help='Path to log file',
dest='log_file',
action='store',
default='openadms.log',
widget='FileChooser')
parser.add_argument('-b', '--bind',
metavar='Host',
help='IP address or FQDN of MQTT message broker',
dest='host',
action='store',
default='127.0.0.1')
parser.add_argument('-p', '--port',
metavar='Port',
help='Port of MQTT message broker',
dest='port',
action='store',
type=int,
default=1883)
args = parser.parse_args()
try:
valid_path(args.config_file_path)
except argparse.ArgumentTypeError as e:
logger.error(e)
return
setup_logging(args.is_debug, args.verbosity, args.log_file)
# Use internal MQTT message broker (HBMQTT).
if args.is_mqtt_broker:
start_mqtt_message_broker(args.host, args.port)
main(args.config_file_path)
if __name__ == '__main__':
setup_thread_exception_hook()
sys.excepthook = exception_hook
# Use signal handlers to quit gracefully and restart on SIGHUP.
signal.signal(signal.SIGINT, sigint_handler)
if not System.is_windows():
signal.signal(signal.SIGINT, sighup_handler)
# Run wrapper.
mainw()