From 38b5fba79e6626a0fa4869c0781271eaf7d12fdd Mon Sep 17 00:00:00 2001 From: Andrew Cady Date: Sun, 3 Jun 2018 20:47:33 +0000 Subject: use /etc/dracos.conf to specify dracos server address --- Makefile | 3 +-- dexcom_reader/dexcom_dumper.py | 19 +++++++++++++++++++ 2 files changed, 20 insertions(+), 2 deletions(-) diff --git a/Makefile b/Makefile index a319531..9f3242f 100644 --- a/Makefile +++ b/Makefile @@ -9,13 +9,12 @@ clean: rm -f $(TARGETS) DEXCOM_READER_PATH=$(PWD)/dexcom_reader -SERVICE_CMDLINE=$(DEXCOM_READER_PATH)/dexcom_dumper.py -v --poll --http=$(REMOTE_HOST) +SERVICE_CMDLINE=$(DEXCOM_READER_PATH)/dexcom_dumper.py -v --poll --client install-rules: ModemManager.rules install -m0644 ModemManager.rules /etc/udev/rules.d/77-mm-usb-device-blacklist.rules draco.service: draco.service.in - $(if $(REMOTE_HOST),,$(error "You must define $$REMOTE_HOST")) sed -e "s?^\(ExecStart=\).*?\1$(SERVICE_CMDLINE)?" < $< > $@ install-draco: draco.service diff --git a/dexcom_reader/dexcom_dumper.py b/dexcom_reader/dexcom_dumper.py index 3c60a88..bc6c5b0 100755 --- a/dexcom_reader/dexcom_dumper.py +++ b/dexcom_reader/dexcom_dumper.py @@ -4,6 +4,7 @@ import readdata import sys import json import traceback +import subprocess from devicer import simple_devicer # import requests # As this takes SEVEN SECONDS, it's delayed until needed from sys import stdout, stderr @@ -17,6 +18,13 @@ from optparse import OptionParser G5_IS_DEFAULT = True +def get_dracos_host(): + res = subprocess.check_output([ + 'sh', + '-c', + '[ -e /etc/dracos.conf ] && . /etc/dracos.conf && printf "%s" "$dracos_host" || true']) + return res.decode('utf-8') + parser = OptionParser() parser.add_option("--g4", action="store_false", dest="g5", default=G5_IS_DEFAULT, help="use Dexcom G4 instead of Dexcom G5") parser.add_option("--g5", action="store_true", dest="g5", default=G5_IS_DEFAULT, help="use Dexcom G5 instead of Dexcom G4") @@ -31,6 +39,7 @@ parser.add_option("-v", "--verbose", action="store_true", dest="verbose", help=" parser.add_option("-H", "--human", action="store_true", dest="human", help="print human-readable times") parser.add_option("-j", "--json", action="store_true", dest="json", help="print JSON output") parser.add_option("--http", type="string", dest="host", help="submit via HTTP") +parser.add_option("--client", action="store_true", dest="client", help="act as client to dracos") (options, args) = parser.parse_args() @@ -40,6 +49,14 @@ HUMAN = options.human JSON = options.json HOST = options.host +if options.client and not HOST: + dracos_host = get_dracos_host() + if dracos_host: + HOST = "http://" + dracos_host + else: + raise ValueError("Option '--client' specified but 'dracos_host' not specified in '/etc/dracos.conf'") + + if command is 'dump_cgm' and options.num_records is None and not options.hours: options.hours = 2 if options.num_records <= 0: @@ -185,6 +202,8 @@ def poll_remote(): def poll(): print_verbose('Started dexcom_dumper.') + if HOST: + print_verbose("Acting as client to dracos server at " + HOST) poll_once = poll_remote if HOST else poll_stdout dexcom_g5_product = '22a3/47/100' -- cgit v1.2.3