Shift functions around for poetry

This commit is contained in:
Timothy Allen 2024-03-21 20:58:30 +02:00
parent be75d8fd88
commit ae26cdf3c6

View File

@ -29,6 +29,7 @@ try:
writeapi = None writeapi = None
except: except:
can_export_influxdb = False can_export_influxdb = False
influxclient = None
DAEMON_UPDATE_PERIOD = 30 DAEMON_UPDATE_PERIOD = 30
SERIALPORT = "/dev/ttyUSB0" SERIALPORT = "/dev/ttyUSB0"
@ -550,21 +551,6 @@ def collect_data():
return data return data
def main():
global debug
data = dict()
while bool(data) is False:
data = collect_data()
time.sleep(1)
if args.report_json:
print(json.dumps(data))
elif args.report_print:
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(data)
def prometheus_export(daemonize=True, filename=None): def prometheus_export(daemonize=True, filename=None):
global debug global debug
if not can_export_prometheus: if not can_export_prometheus:
@ -738,12 +724,7 @@ def influxdb_create_snapshot(data):
return points return points
def parse_args():
if __name__ == '__main__':
debug = 0
atexit.register(cleanup)
atexit.register(shutdown)
try:
parser = argparse.ArgumentParser( parser = argparse.ArgumentParser(
description='Query JBD BMS and report status', description='Query JBD BMS and report status',
add_help=True, add_help=True,
@ -769,6 +750,13 @@ if __name__ == '__main__':
parser.add_argument('--verbose', '-v', action='count', parser.add_argument('--verbose', '-v', action='count',
default=0, help='Print more verbose information (can be specified multiple times)') default=0, help='Print more verbose information (can be specified multiple times)')
args = parser.parse_args() args = parser.parse_args()
return args
def main():
global debug
try:
args = parse_args()
debug=args.verbose debug=args.verbose
@ -791,6 +779,24 @@ if __name__ == '__main__':
elif args.report_textfile: elif args.report_textfile:
prometheus_export(daemonize=False, filename=args.report_textfile) prometheus_export(daemonize=False, filename=args.report_textfile)
else: else:
main() data = dict()
while bool(data) is False:
data = collect_data()
time.sleep(1)
if args.report_json:
print(json.dumps(data))
elif args.report_print:
pp = pprint.PrettyPrinter(indent=4)
pp.pprint(data)
except KeyboardInterrupt: except KeyboardInterrupt:
cleanup() cleanup()
if __name__ == '__main__':
debug = 0
atexit.register(cleanup)
atexit.register(shutdown)
main()