summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-04-15 16:08:33 +0200
committerDiego Elio Pettenò <flameeyes@flameeyes.eu>2017-04-15 16:08:33 +0200
commit032cd0cf3b58dcbb80d066c5409ea15c2af258ff (patch)
treee2fac1c868c21f145220488f5d7fa6098160a1b0
parentAdd a --vlog option to enable verbose logging. (diff)
downloadglucometerutils-032cd0cf3b58dcbb80d066c5409ea15c2af258ff.tar
glucometerutils-032cd0cf3b58dcbb80d066c5409ea15c2af258ff.tar.gz
glucometerutils-032cd0cf3b58dcbb80d066c5409ea15c2af258ff.tar.bz2
glucometerutils-032cd0cf3b58dcbb80d066c5409ea15c2af258ff.tar.lz
glucometerutils-032cd0cf3b58dcbb80d066c5409ea15c2af258ff.tar.xz
glucometerutils-032cd0cf3b58dcbb80d066c5409ea15c2af258ff.tar.zst
glucometerutils-032cd0cf3b58dcbb80d066c5409ea15c2af258ff.zip
-rwxr-xr-xglucometer.py5
-rw-r--r--glucometerutils/drivers/accuchek_reports.py5
-rw-r--r--glucometerutils/drivers/fsoptium.py5
-rw-r--r--glucometerutils/drivers/otultra2.py5
-rw-r--r--glucometerutils/drivers/otultraeasy.py5
-rw-r--r--glucometerutils/drivers/otverio2015.py5
-rw-r--r--glucometerutils/drivers/sdcodefree.py5
-rw-r--r--glucometerutils/exceptions.py7
-rw-r--r--glucometerutils/support/freestyle.py5
9 files changed, 45 insertions, 2 deletions
diff --git a/glucometer.py b/glucometer.py
index be8fb02..63ea8fc 100755
--- a/glucometer.py
+++ b/glucometer.py
@@ -25,8 +25,9 @@ def main():
'--driver', action='store', required=True,
help='Select the driver to use for connecting to the glucometer.')
parser.add_argument(
- '--device', action='store', required=True,
- help='Select the path to the glucometer device.')
+ '--device', action='store', required=False,
+ help=('Select the path to the glucometer device. Some devices require this '
+ 'argument, others will try autodetection.'))
parser.add_argument(
'--vlog', action='store', required=False, type=int,
diff --git a/glucometerutils/drivers/accuchek_reports.py b/glucometerutils/drivers/accuchek_reports.py
index a678736..bf97064 100644
--- a/glucometerutils/drivers/accuchek_reports.py
+++ b/glucometerutils/drivers/accuchek_reports.py
@@ -46,6 +46,11 @@ _DATETIME_FORMAT = ' '.join((_DATE_FORMAT, _TIME_FORMAT))
class Device(object):
def __init__(self, device):
+ if not device or not os.path.isdir(device):
+ raise exceptions.CommandLineError(
+ '--device parameter is required, should point to mount path for the '
+ 'meter.')
+
report_files = glob.glob(os.path.join(device, '*', 'Reports', '*.csv'))
if not report_files:
raise exceptions.ConnectionFailed(
diff --git a/glucometerutils/drivers/fsoptium.py b/glucometerutils/drivers/fsoptium.py
index fd4c791..92ee76d 100644
--- a/glucometerutils/drivers/fsoptium.py
+++ b/glucometerutils/drivers/fsoptium.py
@@ -79,6 +79,11 @@ def _parse_clock(datestr):
class Device(object):
def __init__(self, device):
+ if not device:
+ raise exceptions.CommandLineError(
+ '--device parameter is required, should point to the serial device '
+ 'connected to the meter.')
+
self.serial_ = serial.Serial(
port=device, baudrate=19200, bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
diff --git a/glucometerutils/drivers/otultra2.py b/glucometerutils/drivers/otultra2.py
index 1c8ee10..21d6743 100644
--- a/glucometerutils/drivers/otultra2.py
+++ b/glucometerutils/drivers/otultra2.py
@@ -124,6 +124,11 @@ def _parse_datetime(response):
class Device(object):
def __init__(self, device):
+ if not device:
+ raise exceptions.CommandLineError(
+ '--device parameter is required, should point to the serial device '
+ 'connected to the meter.')
+
self.serial_ = serial.Serial(
port=device, baudrate=9600, bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
diff --git a/glucometerutils/drivers/otultraeasy.py b/glucometerutils/drivers/otultraeasy.py
index 50a6020..ce68625 100644
--- a/glucometerutils/drivers/otultraeasy.py
+++ b/glucometerutils/drivers/otultraeasy.py
@@ -177,6 +177,11 @@ class _Packet(object):
class Device(object):
def __init__(self, device):
+ if not device:
+ raise exceptions.CommandLineError(
+ '--device parameter is required, should point to the serial device '
+ 'connected to the meter.')
+
self.serial_ = serial.Serial(
port=device, baudrate=9600, bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
diff --git a/glucometerutils/drivers/otverio2015.py b/glucometerutils/drivers/otverio2015.py
index 80de6ed..55ffbd2 100644
--- a/glucometerutils/drivers/otverio2015.py
+++ b/glucometerutils/drivers/otverio2015.py
@@ -99,6 +99,11 @@ def _convert_timestamp(timestamp):
class Device(object):
def __init__(self, device):
+ if not device:
+ raise exceptions.CommandLineError(
+ '--device parameter is required, should point to the disk device '
+ 'representing the meter.')
+
self.device_name_ = device
self.scsi_device_ = SCSIDevice(device, readwrite=True)
self.scsi_ = SCSI(self.scsi_device_)
diff --git a/glucometerutils/drivers/sdcodefree.py b/glucometerutils/drivers/sdcodefree.py
index c89d894..19644f6 100644
--- a/glucometerutils/drivers/sdcodefree.py
+++ b/glucometerutils/drivers/sdcodefree.py
@@ -65,6 +65,11 @@ def xor_checksum(msg):
class Device(object):
def __init__(self, device):
+ if not device:
+ raise exceptions.CommandLineError(
+ '--device parameter is required, should point to the serial '
+ 'device connected to the meter.')
+
self.serial_ = serial.Serial(
port=device, baudrate=38400, bytesize=serial.EIGHTBITS,
parity=serial.PARITY_NONE, stopbits=serial.STOPBITS_ONE,
diff --git a/glucometerutils/exceptions.py b/glucometerutils/exceptions.py
index 1290d9a..52c4e94 100644
--- a/glucometerutils/exceptions.py
+++ b/glucometerutils/exceptions.py
@@ -13,6 +13,13 @@ class Error(Exception):
return self.message
+class CommandLineError(Error):
+ """Error with commandline parameters provided."""
+
+ def __init__(self, message=''):
+ self.message = message
+
+
class ConnectionFailed(Error):
"""It was not possible to connect to the meter."""
diff --git a/glucometerutils/support/freestyle.py b/glucometerutils/support/freestyle.py
index 307cf64..6c6e294 100644
--- a/glucometerutils/support/freestyle.py
+++ b/glucometerutils/support/freestyle.py
@@ -69,6 +69,11 @@ class FreeStyleHidDevice(object):
TEXT_REPLY_CMD = 0x60
def __init__(self, device):
+ if not device:
+ raise exceptions.CommandLineError(
+ '--device parameter is required, should point to /dev/hidraw '
+ 'for the meter')
+
if not os.path.exists(device):
raise exceptions.ConnectionFailed(
message='Path %s does not exist.' % device)