Refactor to reduce the amount of duplicate code
Combined the history and status scripts for each data backend and moved some of the shared code into a separate module. Since the existing script names were not appropriate for the new combined versions, the main entry point scripts now have new names, which better conform with Python module name conventions: dish_grpc_text.py, dish_grpc_mqtt.py, and dish_grpc_influx.py. pylint seems happier with those names, at any rate.
Switched the argument parsing from getopt to argparse, since that better facilitates sharing the common bits. The whole command line interface is now different in that the selection of data groups to process must be made as required arg(s) rather than option flags, but for the most part, the scripts support choosing an arbitrary list of groups and will process them all.
Split the monster main() functions into a more reasonable set of functions.
Added new functions to starlink_grpc to support getting the status, which returns the data in a form similar to the history data functions. Reformatted the starlink_grpc module docstring to render better with pydoc. Also changed the way sequence data field names are reported so that the consuming scripts can name them correctly without resorting to hacky special casing based on specific field names. This would subtly break the old scripts that had been expecting the old naming, but those scripts are now gone.
The code is harder to follow now, IMO, but this should allow adding of new features and/or data backends without having to make the same change in 6 places as had been the case. To that end, dish_grpc_text now supports bulk history mode, since it was trivial to add once I had it implemented in order to support that feature for dish_grpc_influx.
2021-01-29 21:25:23 -06:00
|
|
|
#!/usr/bin/python3
|
|
|
|
"""Publish Starlink user terminal data to a MQTT broker.
|
|
|
|
|
|
|
|
This script pulls the current status info and/or metrics computed from the
|
|
|
|
history data and publishes them to the specified MQTT broker either once or
|
|
|
|
in a periodic loop.
|
2021-02-27 18:39:28 -06:00
|
|
|
|
|
|
|
Data will be published to the following topic names:
|
|
|
|
|
|
|
|
: starlink/dish_status/*id_value*/*field_name* : Current status data
|
|
|
|
: starlink/dish_ping_stats/*id_value*/*field_name* : Ping history statistics
|
|
|
|
: starlink/dish_usage/*id_value*/*field_name* : Usage history statistics
|
|
|
|
|
|
|
|
Where *id_value* is the *id* value from the dish status information.
|
2022-03-02 17:10:31 -06:00
|
|
|
|
|
|
|
Unless the --json command line option is used, in which case, JSON-formatted
|
|
|
|
data will be published to topic name:
|
|
|
|
|
|
|
|
: starlink/*id_value*
|
Refactor to reduce the amount of duplicate code
Combined the history and status scripts for each data backend and moved some of the shared code into a separate module. Since the existing script names were not appropriate for the new combined versions, the main entry point scripts now have new names, which better conform with Python module name conventions: dish_grpc_text.py, dish_grpc_mqtt.py, and dish_grpc_influx.py. pylint seems happier with those names, at any rate.
Switched the argument parsing from getopt to argparse, since that better facilitates sharing the common bits. The whole command line interface is now different in that the selection of data groups to process must be made as required arg(s) rather than option flags, but for the most part, the scripts support choosing an arbitrary list of groups and will process them all.
Split the monster main() functions into a more reasonable set of functions.
Added new functions to starlink_grpc to support getting the status, which returns the data in a form similar to the history data functions. Reformatted the starlink_grpc module docstring to render better with pydoc. Also changed the way sequence data field names are reported so that the consuming scripts can name them correctly without resorting to hacky special casing based on specific field names. This would subtly break the old scripts that had been expecting the old naming, but those scripts are now gone.
The code is harder to follow now, IMO, but this should allow adding of new features and/or data backends without having to make the same change in 6 places as had been the case. To that end, dish_grpc_text now supports bulk history mode, since it was trivial to add once I had it implemented in order to support that feature for dish_grpc_influx.
2021-01-29 21:25:23 -06:00
|
|
|
"""
|
|
|
|
|
2022-03-02 16:32:33 -06:00
|
|
|
import json
|
Refactor to reduce the amount of duplicate code
Combined the history and status scripts for each data backend and moved some of the shared code into a separate module. Since the existing script names were not appropriate for the new combined versions, the main entry point scripts now have new names, which better conform with Python module name conventions: dish_grpc_text.py, dish_grpc_mqtt.py, and dish_grpc_influx.py. pylint seems happier with those names, at any rate.
Switched the argument parsing from getopt to argparse, since that better facilitates sharing the common bits. The whole command line interface is now different in that the selection of data groups to process must be made as required arg(s) rather than option flags, but for the most part, the scripts support choosing an arbitrary list of groups and will process them all.
Split the monster main() functions into a more reasonable set of functions.
Added new functions to starlink_grpc to support getting the status, which returns the data in a form similar to the history data functions. Reformatted the starlink_grpc module docstring to render better with pydoc. Also changed the way sequence data field names are reported so that the consuming scripts can name them correctly without resorting to hacky special casing based on specific field names. This would subtly break the old scripts that had been expecting the old naming, but those scripts are now gone.
The code is harder to follow now, IMO, but this should allow adding of new features and/or data backends without having to make the same change in 6 places as had been the case. To that end, dish_grpc_text now supports bulk history mode, since it was trivial to add once I had it implemented in order to support that feature for dish_grpc_influx.
2021-01-29 21:25:23 -06:00
|
|
|
import logging
|
2022-03-02 16:32:33 -06:00
|
|
|
import math
|
2022-03-01 23:15:37 -06:00
|
|
|
import os
|
|
|
|
import signal
|
Refactor to reduce the amount of duplicate code
Combined the history and status scripts for each data backend and moved some of the shared code into a separate module. Since the existing script names were not appropriate for the new combined versions, the main entry point scripts now have new names, which better conform with Python module name conventions: dish_grpc_text.py, dish_grpc_mqtt.py, and dish_grpc_influx.py. pylint seems happier with those names, at any rate.
Switched the argument parsing from getopt to argparse, since that better facilitates sharing the common bits. The whole command line interface is now different in that the selection of data groups to process must be made as required arg(s) rather than option flags, but for the most part, the scripts support choosing an arbitrary list of groups and will process them all.
Split the monster main() functions into a more reasonable set of functions.
Added new functions to starlink_grpc to support getting the status, which returns the data in a form similar to the history data functions. Reformatted the starlink_grpc module docstring to render better with pydoc. Also changed the way sequence data field names are reported so that the consuming scripts can name them correctly without resorting to hacky special casing based on specific field names. This would subtly break the old scripts that had been expecting the old naming, but those scripts are now gone.
The code is harder to follow now, IMO, but this should allow adding of new features and/or data backends without having to make the same change in 6 places as had been the case. To that end, dish_grpc_text now supports bulk history mode, since it was trivial to add once I had it implemented in order to support that feature for dish_grpc_influx.
2021-01-29 21:25:23 -06:00
|
|
|
import sys
|
|
|
|
import time
|
|
|
|
|
|
|
|
try:
|
|
|
|
import ssl
|
|
|
|
ssl_ok = True
|
|
|
|
except ImportError:
|
|
|
|
ssl_ok = False
|
|
|
|
|
|
|
|
import paho.mqtt.publish
|
|
|
|
|
|
|
|
import dish_common
|
|
|
|
|
|
|
|
HOST_DEFAULT = "localhost"
|
|
|
|
|
2022-03-02 16:32:33 -06:00
|
|
|
|
2022-03-01 23:15:37 -06:00
|
|
|
class Terminated(Exception):
|
|
|
|
pass
|
|
|
|
|
|
|
|
|
|
|
|
def handle_sigterm(signum, frame):
|
|
|
|
# Turn SIGTERM into an exception so main loop can clean up
|
|
|
|
raise Terminated
|
|
|
|
|
Refactor to reduce the amount of duplicate code
Combined the history and status scripts for each data backend and moved some of the shared code into a separate module. Since the existing script names were not appropriate for the new combined versions, the main entry point scripts now have new names, which better conform with Python module name conventions: dish_grpc_text.py, dish_grpc_mqtt.py, and dish_grpc_influx.py. pylint seems happier with those names, at any rate.
Switched the argument parsing from getopt to argparse, since that better facilitates sharing the common bits. The whole command line interface is now different in that the selection of data groups to process must be made as required arg(s) rather than option flags, but for the most part, the scripts support choosing an arbitrary list of groups and will process them all.
Split the monster main() functions into a more reasonable set of functions.
Added new functions to starlink_grpc to support getting the status, which returns the data in a form similar to the history data functions. Reformatted the starlink_grpc module docstring to render better with pydoc. Also changed the way sequence data field names are reported so that the consuming scripts can name them correctly without resorting to hacky special casing based on specific field names. This would subtly break the old scripts that had been expecting the old naming, but those scripts are now gone.
The code is harder to follow now, IMO, but this should allow adding of new features and/or data backends without having to make the same change in 6 places as had been the case. To that end, dish_grpc_text now supports bulk history mode, since it was trivial to add once I had it implemented in order to support that feature for dish_grpc_influx.
2021-01-29 21:25:23 -06:00
|
|
|
|
|
|
|
def parse_args():
|
|
|
|
parser = dish_common.create_arg_parser(output_description="publish it to a MQTT broker",
|
|
|
|
bulk_history=False)
|
|
|
|
|
|
|
|
group = parser.add_argument_group(title="MQTT broker options")
|
|
|
|
group.add_argument("-n",
|
|
|
|
"--hostname",
|
|
|
|
default=HOST_DEFAULT,
|
|
|
|
help="Hostname of MQTT broker, default: " + HOST_DEFAULT)
|
|
|
|
group.add_argument("-p", "--port", type=int, help="Port number to use on MQTT broker")
|
|
|
|
group.add_argument("-P", "--password", help="Set password for username/password authentication")
|
|
|
|
group.add_argument("-U", "--username", help="Set username for authentication")
|
2022-02-27 06:03:31 -06:00
|
|
|
group.add_argument("-J", "--json", action="store_true", help="Publish data as JSON")
|
Refactor to reduce the amount of duplicate code
Combined the history and status scripts for each data backend and moved some of the shared code into a separate module. Since the existing script names were not appropriate for the new combined versions, the main entry point scripts now have new names, which better conform with Python module name conventions: dish_grpc_text.py, dish_grpc_mqtt.py, and dish_grpc_influx.py. pylint seems happier with those names, at any rate.
Switched the argument parsing from getopt to argparse, since that better facilitates sharing the common bits. The whole command line interface is now different in that the selection of data groups to process must be made as required arg(s) rather than option flags, but for the most part, the scripts support choosing an arbitrary list of groups and will process them all.
Split the monster main() functions into a more reasonable set of functions.
Added new functions to starlink_grpc to support getting the status, which returns the data in a form similar to the history data functions. Reformatted the starlink_grpc module docstring to render better with pydoc. Also changed the way sequence data field names are reported so that the consuming scripts can name them correctly without resorting to hacky special casing based on specific field names. This would subtly break the old scripts that had been expecting the old naming, but those scripts are now gone.
The code is harder to follow now, IMO, but this should allow adding of new features and/or data backends without having to make the same change in 6 places as had been the case. To that end, dish_grpc_text now supports bulk history mode, since it was trivial to add once I had it implemented in order to support that feature for dish_grpc_influx.
2021-01-29 21:25:23 -06:00
|
|
|
if ssl_ok:
|
|
|
|
|
|
|
|
def wrap_ca_arg(arg):
|
|
|
|
return {"ca_certs": arg}
|
|
|
|
|
|
|
|
group.add_argument("-C",
|
|
|
|
"--ca-cert",
|
|
|
|
type=wrap_ca_arg,
|
|
|
|
dest="tls",
|
|
|
|
help="Enable SSL/TLS using specified CA cert to verify broker",
|
|
|
|
metavar="FILENAME")
|
|
|
|
group.add_argument("-I",
|
|
|
|
"--insecure",
|
|
|
|
action="store_const",
|
|
|
|
const={"cert_reqs": ssl.CERT_NONE},
|
|
|
|
dest="tls",
|
|
|
|
help="Enable SSL/TLS but disable certificate verification (INSECURE!)")
|
|
|
|
group.add_argument("-S",
|
|
|
|
"--secure",
|
|
|
|
action="store_const",
|
|
|
|
const={},
|
|
|
|
dest="tls",
|
|
|
|
help="Enable SSL/TLS using default CA cert")
|
|
|
|
else:
|
|
|
|
parser.epilog += "\nSSL support options not available due to missing ssl module"
|
|
|
|
|
2022-03-01 23:15:37 -06:00
|
|
|
env_map = (
|
|
|
|
("MQTT_HOST", "hostname"),
|
|
|
|
("MQTT_PORT", "port"),
|
|
|
|
("MQTT_USERNAME", "username"),
|
|
|
|
("MQTT_PASSWORD", "password"),
|
|
|
|
("MQTT_SSL", "tls"),
|
|
|
|
)
|
|
|
|
env_defaults = {}
|
|
|
|
for var, opt in env_map:
|
|
|
|
# check both set and not empty string
|
|
|
|
val = os.environ.get(var)
|
|
|
|
if val:
|
|
|
|
if var == "MQTT_SSL":
|
2022-03-02 16:32:33 -06:00
|
|
|
if ssl_ok and val != "false":
|
|
|
|
if val == "insecure":
|
|
|
|
env_defaults[opt] = {"cert_reqs": ssl.CERT_NONE}
|
|
|
|
elif val == "secure":
|
|
|
|
env_defaults[opt] = {}
|
|
|
|
else:
|
|
|
|
env_defaults[opt] = {"ca_certs": val}
|
2022-03-01 23:15:37 -06:00
|
|
|
else:
|
|
|
|
env_defaults[opt] = val
|
|
|
|
parser.set_defaults(**env_defaults)
|
|
|
|
|
Refactor to reduce the amount of duplicate code
Combined the history and status scripts for each data backend and moved some of the shared code into a separate module. Since the existing script names were not appropriate for the new combined versions, the main entry point scripts now have new names, which better conform with Python module name conventions: dish_grpc_text.py, dish_grpc_mqtt.py, and dish_grpc_influx.py. pylint seems happier with those names, at any rate.
Switched the argument parsing from getopt to argparse, since that better facilitates sharing the common bits. The whole command line interface is now different in that the selection of data groups to process must be made as required arg(s) rather than option flags, but for the most part, the scripts support choosing an arbitrary list of groups and will process them all.
Split the monster main() functions into a more reasonable set of functions.
Added new functions to starlink_grpc to support getting the status, which returns the data in a form similar to the history data functions. Reformatted the starlink_grpc module docstring to render better with pydoc. Also changed the way sequence data field names are reported so that the consuming scripts can name them correctly without resorting to hacky special casing based on specific field names. This would subtly break the old scripts that had been expecting the old naming, but those scripts are now gone.
The code is harder to follow now, IMO, but this should allow adding of new features and/or data backends without having to make the same change in 6 places as had been the case. To that end, dish_grpc_text now supports bulk history mode, since it was trivial to add once I had it implemented in order to support that feature for dish_grpc_influx.
2021-01-29 21:25:23 -06:00
|
|
|
opts = dish_common.run_arg_parser(parser, need_id=True)
|
|
|
|
|
|
|
|
if opts.username is None and opts.password is not None:
|
|
|
|
parser.error("Password authentication requires username to be set")
|
|
|
|
|
|
|
|
opts.mqargs = {}
|
|
|
|
for key in ["hostname", "port", "tls"]:
|
|
|
|
val = getattr(opts, key)
|
|
|
|
if val is not None:
|
|
|
|
opts.mqargs[key] = val
|
|
|
|
|
|
|
|
if opts.username is not None:
|
|
|
|
opts.mqargs["auth"] = {"username": opts.username}
|
|
|
|
if opts.password is not None:
|
|
|
|
opts.mqargs["auth"]["password"] = opts.password
|
|
|
|
|
|
|
|
return opts
|
|
|
|
|
|
|
|
|
|
|
|
def loop_body(opts, gstate):
|
|
|
|
msgs = []
|
|
|
|
|
2022-02-27 06:03:31 -06:00
|
|
|
if opts.json:
|
|
|
|
|
|
|
|
data = {}
|
|
|
|
|
|
|
|
def cb_add_item(key, val, category):
|
|
|
|
if not "dish_{0}".format(category) in data:
|
|
|
|
data["dish_{0}".format(category)] = {}
|
|
|
|
|
2022-03-02 05:22:01 -06:00
|
|
|
# Skip NaN values that occur on startup because they can upset Javascript JSON parsers
|
|
|
|
if not ((type(val) == float) and math.isnan(val)):
|
|
|
|
data["dish_{0}".format(category)].update({key: val})
|
2022-02-27 06:03:31 -06:00
|
|
|
|
|
|
|
def cb_add_sequence(key, val, category, _):
|
|
|
|
if not "dish_{0}".format(category) in data:
|
|
|
|
data["dish_{0}".format(category)] = {}
|
|
|
|
|
|
|
|
data["dish_{0}".format(category)].update({key: list(val)})
|
|
|
|
|
|
|
|
else:
|
2022-03-02 16:32:33 -06:00
|
|
|
|
2022-02-27 06:03:31 -06:00
|
|
|
def cb_add_item(key, val, category):
|
|
|
|
msgs.append(("starlink/dish_{0}/{1}/{2}".format(category, gstate.dish_id,
|
|
|
|
key), val, 0, False))
|
|
|
|
|
|
|
|
def cb_add_sequence(key, val, category, _):
|
2022-03-02 17:02:29 -06:00
|
|
|
msgs.append(("starlink/dish_{0}/{1}/{2}".format(category, gstate.dish_id, key),
|
|
|
|
",".join("" if x is None else str(x) for x in val), 0, False))
|
Refactor to reduce the amount of duplicate code
Combined the history and status scripts for each data backend and moved some of the shared code into a separate module. Since the existing script names were not appropriate for the new combined versions, the main entry point scripts now have new names, which better conform with Python module name conventions: dish_grpc_text.py, dish_grpc_mqtt.py, and dish_grpc_influx.py. pylint seems happier with those names, at any rate.
Switched the argument parsing from getopt to argparse, since that better facilitates sharing the common bits. The whole command line interface is now different in that the selection of data groups to process must be made as required arg(s) rather than option flags, but for the most part, the scripts support choosing an arbitrary list of groups and will process them all.
Split the monster main() functions into a more reasonable set of functions.
Added new functions to starlink_grpc to support getting the status, which returns the data in a form similar to the history data functions. Reformatted the starlink_grpc module docstring to render better with pydoc. Also changed the way sequence data field names are reported so that the consuming scripts can name them correctly without resorting to hacky special casing based on specific field names. This would subtly break the old scripts that had been expecting the old naming, but those scripts are now gone.
The code is harder to follow now, IMO, but this should allow adding of new features and/or data backends without having to make the same change in 6 places as had been the case. To that end, dish_grpc_text now supports bulk history mode, since it was trivial to add once I had it implemented in order to support that feature for dish_grpc_influx.
2021-01-29 21:25:23 -06:00
|
|
|
|
2022-02-20 15:39:07 -06:00
|
|
|
rc = dish_common.get_data(opts, gstate, cb_add_item, cb_add_sequence)[0]
|
Refactor to reduce the amount of duplicate code
Combined the history and status scripts for each data backend and moved some of the shared code into a separate module. Since the existing script names were not appropriate for the new combined versions, the main entry point scripts now have new names, which better conform with Python module name conventions: dish_grpc_text.py, dish_grpc_mqtt.py, and dish_grpc_influx.py. pylint seems happier with those names, at any rate.
Switched the argument parsing from getopt to argparse, since that better facilitates sharing the common bits. The whole command line interface is now different in that the selection of data groups to process must be made as required arg(s) rather than option flags, but for the most part, the scripts support choosing an arbitrary list of groups and will process them all.
Split the monster main() functions into a more reasonable set of functions.
Added new functions to starlink_grpc to support getting the status, which returns the data in a form similar to the history data functions. Reformatted the starlink_grpc module docstring to render better with pydoc. Also changed the way sequence data field names are reported so that the consuming scripts can name them correctly without resorting to hacky special casing based on specific field names. This would subtly break the old scripts that had been expecting the old naming, but those scripts are now gone.
The code is harder to follow now, IMO, but this should allow adding of new features and/or data backends without having to make the same change in 6 places as had been the case. To that end, dish_grpc_text now supports bulk history mode, since it was trivial to add once I had it implemented in order to support that feature for dish_grpc_influx.
2021-01-29 21:25:23 -06:00
|
|
|
|
2022-02-27 06:03:31 -06:00
|
|
|
if opts.json:
|
|
|
|
msgs.append(("starlink/{0}".format(gstate.dish_id), json.dumps(data), 0, False))
|
|
|
|
|
Refactor to reduce the amount of duplicate code
Combined the history and status scripts for each data backend and moved some of the shared code into a separate module. Since the existing script names were not appropriate for the new combined versions, the main entry point scripts now have new names, which better conform with Python module name conventions: dish_grpc_text.py, dish_grpc_mqtt.py, and dish_grpc_influx.py. pylint seems happier with those names, at any rate.
Switched the argument parsing from getopt to argparse, since that better facilitates sharing the common bits. The whole command line interface is now different in that the selection of data groups to process must be made as required arg(s) rather than option flags, but for the most part, the scripts support choosing an arbitrary list of groups and will process them all.
Split the monster main() functions into a more reasonable set of functions.
Added new functions to starlink_grpc to support getting the status, which returns the data in a form similar to the history data functions. Reformatted the starlink_grpc module docstring to render better with pydoc. Also changed the way sequence data field names are reported so that the consuming scripts can name them correctly without resorting to hacky special casing based on specific field names. This would subtly break the old scripts that had been expecting the old naming, but those scripts are now gone.
The code is harder to follow now, IMO, but this should allow adding of new features and/or data backends without having to make the same change in 6 places as had been the case. To that end, dish_grpc_text now supports bulk history mode, since it was trivial to add once I had it implemented in order to support that feature for dish_grpc_influx.
2021-01-29 21:25:23 -06:00
|
|
|
if msgs:
|
|
|
|
try:
|
|
|
|
paho.mqtt.publish.multiple(msgs, client_id=gstate.dish_id, **opts.mqargs)
|
|
|
|
if opts.verbose:
|
|
|
|
print("Successfully published to MQTT broker")
|
|
|
|
except Exception as e:
|
|
|
|
dish_common.conn_error(opts, "Failed publishing to MQTT broker: %s", str(e))
|
|
|
|
rc = 1
|
|
|
|
|
|
|
|
return rc
|
|
|
|
|
|
|
|
|
|
|
|
def main():
|
|
|
|
opts = parse_args()
|
|
|
|
|
|
|
|
logging.basicConfig(format="%(levelname)s: %(message)s")
|
|
|
|
|
2021-02-15 20:50:22 -06:00
|
|
|
gstate = dish_common.GlobalState(target=opts.target)
|
Refactor to reduce the amount of duplicate code
Combined the history and status scripts for each data backend and moved some of the shared code into a separate module. Since the existing script names were not appropriate for the new combined versions, the main entry point scripts now have new names, which better conform with Python module name conventions: dish_grpc_text.py, dish_grpc_mqtt.py, and dish_grpc_influx.py. pylint seems happier with those names, at any rate.
Switched the argument parsing from getopt to argparse, since that better facilitates sharing the common bits. The whole command line interface is now different in that the selection of data groups to process must be made as required arg(s) rather than option flags, but for the most part, the scripts support choosing an arbitrary list of groups and will process them all.
Split the monster main() functions into a more reasonable set of functions.
Added new functions to starlink_grpc to support getting the status, which returns the data in a form similar to the history data functions. Reformatted the starlink_grpc module docstring to render better with pydoc. Also changed the way sequence data field names are reported so that the consuming scripts can name them correctly without resorting to hacky special casing based on specific field names. This would subtly break the old scripts that had been expecting the old naming, but those scripts are now gone.
The code is harder to follow now, IMO, but this should allow adding of new features and/or data backends without having to make the same change in 6 places as had been the case. To that end, dish_grpc_text now supports bulk history mode, since it was trivial to add once I had it implemented in order to support that feature for dish_grpc_influx.
2021-01-29 21:25:23 -06:00
|
|
|
|
2022-03-01 23:15:37 -06:00
|
|
|
signal.signal(signal.SIGTERM, handle_sigterm)
|
|
|
|
|
2022-03-02 16:48:51 -06:00
|
|
|
rc = 0
|
2021-01-30 13:24:17 -06:00
|
|
|
try:
|
|
|
|
next_loop = time.monotonic()
|
|
|
|
while True:
|
|
|
|
rc = loop_body(opts, gstate)
|
|
|
|
if opts.loop_interval > 0.0:
|
|
|
|
now = time.monotonic()
|
|
|
|
next_loop = max(next_loop + opts.loop_interval, now)
|
|
|
|
time.sleep(next_loop - now)
|
|
|
|
else:
|
|
|
|
break
|
2022-03-02 16:48:51 -06:00
|
|
|
except (KeyboardInterrupt, Terminated):
|
2022-03-01 23:15:37 -06:00
|
|
|
pass
|
2021-01-30 13:24:17 -06:00
|
|
|
finally:
|
|
|
|
gstate.shutdown()
|
2022-03-02 16:48:51 -06:00
|
|
|
|
|
|
|
sys.exit(rc)
|
Refactor to reduce the amount of duplicate code
Combined the history and status scripts for each data backend and moved some of the shared code into a separate module. Since the existing script names were not appropriate for the new combined versions, the main entry point scripts now have new names, which better conform with Python module name conventions: dish_grpc_text.py, dish_grpc_mqtt.py, and dish_grpc_influx.py. pylint seems happier with those names, at any rate.
Switched the argument parsing from getopt to argparse, since that better facilitates sharing the common bits. The whole command line interface is now different in that the selection of data groups to process must be made as required arg(s) rather than option flags, but for the most part, the scripts support choosing an arbitrary list of groups and will process them all.
Split the monster main() functions into a more reasonable set of functions.
Added new functions to starlink_grpc to support getting the status, which returns the data in a form similar to the history data functions. Reformatted the starlink_grpc module docstring to render better with pydoc. Also changed the way sequence data field names are reported so that the consuming scripts can name them correctly without resorting to hacky special casing based on specific field names. This would subtly break the old scripts that had been expecting the old naming, but those scripts are now gone.
The code is harder to follow now, IMO, but this should allow adding of new features and/or data backends without having to make the same change in 6 places as had been the case. To that end, dish_grpc_text now supports bulk history mode, since it was trivial to add once I had it implemented in order to support that feature for dish_grpc_influx.
2021-01-29 21:25:23 -06:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
main()
|