diff options
author | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2013-12-08 00:53:27 +0100 |
---|---|---|
committer | Diego Elio Pettenò <flameeyes@flameeyes.eu> | 2013-12-08 00:53:27 +0100 |
commit | e95befcc1c7ddd707639946b220b367089d9ec19 (patch) | |
tree | 7c31fb8e543185f6dabf0a083bed4748944f35e7 | |
parent | Add a new command to dump the identification of the glucometer. (diff) | |
download | glucometerutils-e95befcc1c7ddd707639946b220b367089d9ec19.tar glucometerutils-e95befcc1c7ddd707639946b220b367089d9ec19.tar.gz glucometerutils-e95befcc1c7ddd707639946b220b367089d9ec19.tar.bz2 glucometerutils-e95befcc1c7ddd707639946b220b367089d9ec19.tar.lz glucometerutils-e95befcc1c7ddd707639946b220b367089d9ec19.tar.xz glucometerutils-e95befcc1c7ddd707639946b220b367089d9ec19.tar.zst glucometerutils-e95befcc1c7ddd707639946b220b367089d9ec19.zip |
-rwxr-xr-x | glucometer.py | 44 | ||||
-rw-r--r-- | glucometerutils/drivers/otultra2.py | 2 |
2 files changed, 24 insertions, 22 deletions
diff --git a/glucometer.py b/glucometer.py index d9fbf68..18b7ad3 100755 --- a/glucometer.py +++ b/glucometer.py @@ -14,6 +14,7 @@ import sys from dateutil import parser as date_parser from glucometerutils import common +from glucometerutils import exceptions from glucometerutils.drivers import otultra2 def main(): @@ -49,29 +50,30 @@ def main(): driver = importlib.import_module('glucometerutils.drivers.' + args.driver) device = driver.Device(args.device) - if args.action == 'info': - print(device.get_information_string()) - elif args.action == 'dump': - for reading in device.get_readings(): - print('%s,%.2f,%s' % (reading.timestamp, reading.get_value_as(args.unit), - reading.comment)) - elif args.action == 'datetime': - if args.set == 'now': - print(device.set_datetime()) - elif args.set: - try: - print(device.set_datetime(date_parser.parse(args.set))) - except ValueError: - print('%s: not a valid date' % args.set, file=sys.stderr) - else: - print(device.get_datetime()) - elif args.action == 'zero': - try: + try: + if args.action == 'info': + print(device.get_information_string()) + elif args.action == 'dump': + for reading in device.get_readings(): + print('%s,%.2f,%s' % (reading.timestamp, reading.get_value_as(args.unit), + reading.comment)) + elif args.action == 'datetime': + if args.set == 'now': + print(device.set_datetime()) + elif args.set: + try: + print(device.set_datetime(date_parser.parse(args.set))) + except ValueError: + print('%s: not a valid date' % args.set, file=sys.stderr) + else: + print(device.get_datetime()) + elif args.action == 'zero': device.zero_log() print('Device data log zeroed.') - except Exception as e: - print('Error while zeroing device log: %s' % e) - else: + else: + return 1 + except exceptions.Error as err: + print('Error while executing \'%s\': %s' % (args.action, str(err))) return 1 if __name__ == "__main__": diff --git a/glucometerutils/drivers/otultra2.py b/glucometerutils/drivers/otultra2.py index 4f275ba..500ce17 100644 --- a/glucometerutils/drivers/otultra2.py +++ b/glucometerutils/drivers/otultra2.py @@ -110,7 +110,7 @@ class Device(object): response = self._send_oneliner_command('DM?') if response[0] != '?': - raise InvalidResponse(response) + raise exceptions.InvalidResponse(response) return response[1:] |