diff options
author | Andrew Cady <d@jerkface.net> | 2018-06-03 20:47:33 +0000 |
---|---|---|
committer | Andrew Cady <d@jerkface.net> | 2018-06-03 20:47:33 +0000 |
commit | 38b5fba79e6626a0fa4869c0781271eaf7d12fdd (patch) | |
tree | dd89360d8f9957206d9554d53f976f8fb31a04b7 | |
parent | a36b3bae80e82a48a29238f433ca201016d775fe (diff) |
use /etc/dracos.conf to specify dracos server address
-rw-r--r-- | Makefile | 3 | ||||
-rwxr-xr-x | dexcom_reader/dexcom_dumper.py | 19 |
2 files changed, 20 insertions, 2 deletions
@@ -9,13 +9,12 @@ clean: | |||
9 | rm -f $(TARGETS) | 9 | rm -f $(TARGETS) |
10 | 10 | ||
11 | DEXCOM_READER_PATH=$(PWD)/dexcom_reader | 11 | DEXCOM_READER_PATH=$(PWD)/dexcom_reader |
12 | SERVICE_CMDLINE=$(DEXCOM_READER_PATH)/dexcom_dumper.py -v --poll --http=$(REMOTE_HOST) | 12 | SERVICE_CMDLINE=$(DEXCOM_READER_PATH)/dexcom_dumper.py -v --poll --client |
13 | 13 | ||
14 | install-rules: ModemManager.rules | 14 | install-rules: ModemManager.rules |
15 | install -m0644 ModemManager.rules /etc/udev/rules.d/77-mm-usb-device-blacklist.rules | 15 | install -m0644 ModemManager.rules /etc/udev/rules.d/77-mm-usb-device-blacklist.rules |
16 | 16 | ||
17 | draco.service: draco.service.in | 17 | draco.service: draco.service.in |
18 | $(if $(REMOTE_HOST),,$(error "You must define $$REMOTE_HOST")) | ||
19 | sed -e "s?^\(ExecStart=\).*?\1$(SERVICE_CMDLINE)?" < $< > $@ | 18 | sed -e "s?^\(ExecStart=\).*?\1$(SERVICE_CMDLINE)?" < $< > $@ |
20 | 19 | ||
21 | install-draco: draco.service | 20 | 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 | |||
4 | import sys | 4 | import sys |
5 | import json | 5 | import json |
6 | import traceback | 6 | import traceback |
7 | import subprocess | ||
7 | from devicer import simple_devicer | 8 | from devicer import simple_devicer |
8 | # import requests # As this takes SEVEN SECONDS, it's delayed until needed | 9 | # import requests # As this takes SEVEN SECONDS, it's delayed until needed |
9 | from sys import stdout, stderr | 10 | from sys import stdout, stderr |
@@ -17,6 +18,13 @@ from optparse import OptionParser | |||
17 | 18 | ||
18 | G5_IS_DEFAULT = True | 19 | G5_IS_DEFAULT = True |
19 | 20 | ||
21 | def get_dracos_host(): | ||
22 | res = subprocess.check_output([ | ||
23 | 'sh', | ||
24 | '-c', | ||
25 | '[ -e /etc/dracos.conf ] && . /etc/dracos.conf && printf "%s" "$dracos_host" || true']) | ||
26 | return res.decode('utf-8') | ||
27 | |||
20 | parser = OptionParser() | 28 | parser = OptionParser() |
21 | parser.add_option("--g4", action="store_false", dest="g5", default=G5_IS_DEFAULT, help="use Dexcom G4 instead of Dexcom G5") | 29 | parser.add_option("--g4", action="store_false", dest="g5", default=G5_IS_DEFAULT, help="use Dexcom G4 instead of Dexcom G5") |
22 | parser.add_option("--g5", action="store_true", dest="g5", default=G5_IS_DEFAULT, help="use Dexcom G5 instead of Dexcom G4") | 30 | 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=" | |||
31 | parser.add_option("-H", "--human", action="store_true", dest="human", help="print human-readable times") | 39 | parser.add_option("-H", "--human", action="store_true", dest="human", help="print human-readable times") |
32 | parser.add_option("-j", "--json", action="store_true", dest="json", help="print JSON output") | 40 | parser.add_option("-j", "--json", action="store_true", dest="json", help="print JSON output") |
33 | parser.add_option("--http", type="string", dest="host", help="submit via HTTP") | 41 | parser.add_option("--http", type="string", dest="host", help="submit via HTTP") |
42 | parser.add_option("--client", action="store_true", dest="client", help="act as client to dracos") | ||
34 | 43 | ||
35 | (options, args) = parser.parse_args() | 44 | (options, args) = parser.parse_args() |
36 | 45 | ||
@@ -40,6 +49,14 @@ HUMAN = options.human | |||
40 | JSON = options.json | 49 | JSON = options.json |
41 | HOST = options.host | 50 | HOST = options.host |
42 | 51 | ||
52 | if options.client and not HOST: | ||
53 | dracos_host = get_dracos_host() | ||
54 | if dracos_host: | ||
55 | HOST = "http://" + dracos_host | ||
56 | else: | ||
57 | raise ValueError("Option '--client' specified but 'dracos_host' not specified in '/etc/dracos.conf'") | ||
58 | |||
59 | |||
43 | if command is 'dump_cgm' and options.num_records is None and not options.hours: | 60 | if command is 'dump_cgm' and options.num_records is None and not options.hours: |
44 | options.hours = 2 | 61 | options.hours = 2 |
45 | if options.num_records <= 0: | 62 | if options.num_records <= 0: |
@@ -185,6 +202,8 @@ def poll_remote(): | |||
185 | 202 | ||
186 | def poll(): | 203 | def poll(): |
187 | print_verbose('Started dexcom_dumper.') | 204 | print_verbose('Started dexcom_dumper.') |
205 | if HOST: | ||
206 | print_verbose("Acting as client to dracos server at " + HOST) | ||
188 | poll_once = poll_remote if HOST else poll_stdout | 207 | poll_once = poll_remote if HOST else poll_stdout |
189 | 208 | ||
190 | dexcom_g5_product = '22a3/47/100' | 209 | dexcom_g5_product = '22a3/47/100' |