summaryrefslogtreecommitdiff
path: root/zerk
diff options
context:
space:
mode:
authorFred Wright <fw@fwright.net>2019-03-27 16:45:19 -0700
committerFred Wright <fw@fwright.net>2019-03-27 20:27:05 -0700
commit7fc42e4d1c881e6c88c3f01b4b19080dcdf8378b (patch)
treeddf12684c2c03f60258b13ac01ad6f5981f15267 /zerk
parent4b80866539305242d6fe96bf385efd30d95da6a7 (diff)
downloadgpsd-7fc42e4d1c881e6c88c3f01b4b19080dcdf8378b.tar.gz
ubxtool/zerk: Makes PySerial a "soft" dependency.
This allows the absence of the PySerial ('serial') module, as long as the -f option is not used. This not only avoids the PySerial dependency for informational options like -h and -V, but also allows full functionality in the "via gpsd" mode. The 'gps_io' class was taking the 'serial' module (mistakenly referred to as a class as an init argument, but wasn't making any use of that flexibility. Since fully supporting that would complicate the error message, it's simply removed instead. The zerk changes are untested, due to the lack of appropriate hardware. However, they are identical to the changes in the corresponding code in ubxtool, which is tested. The manpages are updated to mention the pyserial dependency for -f. The install of ubxtool and zerk is no longer conditional on PySerial. TESTED: Tested ubxtool with PySerial 2.7, 3.0, 3.4, and none at all, verifying that -f works with all three versions, and other modes work without. Also tested with Python 3.4-3.7 (PySerial 3.4 only).
Diffstat (limited to 'zerk')
-rwxr-xr-xzerk15
1 files changed, 8 insertions, 7 deletions
diff --git a/zerk b/zerk
index 9041b123..ef6cef80 100755
--- a/zerk
+++ b/zerk
@@ -52,9 +52,7 @@ PROG_NAME = 'zerk'
try:
import serial
except ImportError:
- # treat serial as special since it is not part of standard Python
- sys.stderr.write("%s: failed to import pyserial\n" % PROG_NAME)
- sys.exit(2)
+ serial = None # Defer complaining until we know we need it.
try:
import gps
@@ -1458,11 +1456,11 @@ class gps_io(object):
ser = None
input_is_device = False
- def __init__(self, serial_class):
+ def __init__(self):
"Initialize class"
- Serial = serial_class
- Serial_v3 = Serial.VERSION.split('.')[0] >= '3'
+ Serial = serial
+ Serial_v3 = Serial and Serial.VERSION.split('.')[0] >= '3'
# buffer to hold read data
self.out = b''
@@ -1536,6 +1534,9 @@ class gps_io(object):
timeout=0.05,
**{write_timeout_arg: 0.5}
)
+ except AttributeError:
+ sys.stderr.write('%s: failed to import pyserial\n' % PROG_NAME)
+ sys.exit(2)
except Serial.serialutil.SerialException:
# this exception happens on bad serial port device name
sys.stderr.write('%s: failed to open serial port "%s"\n'
@@ -1853,7 +1854,7 @@ try:
sys.exit(1)
# create the I/O instance
- io_handle = gps_io(serial)
+ io_handle = gps_io()
# keep it simple, only one of -O, -c -d -e or -S
if opts['oaf_name'] is not None: