summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAndrew Cady <d@jerkface.net>2018-06-03 20:47:33 +0000
committerAndrew Cady <d@jerkface.net>2018-06-03 20:47:33 +0000
commit38b5fba79e6626a0fa4869c0781271eaf7d12fdd (patch)
treedd89360d8f9957206d9554d53f976f8fb31a04b7
parenta36b3bae80e82a48a29238f433ca201016d775fe (diff)
use /etc/dracos.conf to specify dracos server address
-rw-r--r--Makefile3
-rwxr-xr-xdexcom_reader/dexcom_dumper.py19
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:
9 rm -f $(TARGETS) 9 rm -f $(TARGETS)
10 10
11DEXCOM_READER_PATH=$(PWD)/dexcom_reader 11DEXCOM_READER_PATH=$(PWD)/dexcom_reader
12SERVICE_CMDLINE=$(DEXCOM_READER_PATH)/dexcom_dumper.py -v --poll --http=$(REMOTE_HOST) 12SERVICE_CMDLINE=$(DEXCOM_READER_PATH)/dexcom_dumper.py -v --poll --client
13 13
14install-rules: ModemManager.rules 14install-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
17draco.service: draco.service.in 17draco.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
21install-draco: draco.service 20install-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
4import sys 4import sys
5import json 5import json
6import traceback 6import traceback
7import subprocess
7from devicer import simple_devicer 8from 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
9from sys import stdout, stderr 10from sys import stdout, stderr
@@ -17,6 +18,13 @@ from optparse import OptionParser
17 18
18G5_IS_DEFAULT = True 19G5_IS_DEFAULT = True
19 20
21def 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
20parser = OptionParser() 28parser = OptionParser()
21parser.add_option("--g4", action="store_false", dest="g5", default=G5_IS_DEFAULT, help="use Dexcom G4 instead of Dexcom G5") 29parser.add_option("--g4", action="store_false", dest="g5", default=G5_IS_DEFAULT, help="use Dexcom G4 instead of Dexcom G5")
22parser.add_option("--g5", action="store_true", dest="g5", default=G5_IS_DEFAULT, help="use Dexcom G5 instead of Dexcom G4") 30parser.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="
31parser.add_option("-H", "--human", action="store_true", dest="human", help="print human-readable times") 39parser.add_option("-H", "--human", action="store_true", dest="human", help="print human-readable times")
32parser.add_option("-j", "--json", action="store_true", dest="json", help="print JSON output") 40parser.add_option("-j", "--json", action="store_true", dest="json", help="print JSON output")
33parser.add_option("--http", type="string", dest="host", help="submit via HTTP") 41parser.add_option("--http", type="string", dest="host", help="submit via HTTP")
42parser.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
40JSON = options.json 49JSON = options.json
41HOST = options.host 50HOST = options.host
42 51
52if 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
43if command is 'dump_cgm' and options.num_records is None and not options.hours: 60if command is 'dump_cgm' and options.num_records is None and not options.hours:
44 options.hours = 2 61 options.hours = 2
45if options.num_records <= 0: 62if options.num_records <= 0:
@@ -185,6 +202,8 @@ def poll_remote():
185 202
186def poll(): 203def 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'