diff options
author | Jon Schlueter <jschlueter@redhat.com> | 2016-02-06 23:42:56 -0500 |
---|---|---|
committer | Jon Schlueter <jschlueter@redhat.com> | 2016-02-09 21:12:53 -0500 |
commit | f9a3fb0b26a407b9be87c87f39fcf94301b72d11 (patch) | |
tree | 095d74ad28ef1f53b6539989381297efd58709d4 | |
parent | 093473653817f7fd4da19453d02f84e1979170a5 (diff) | |
download | gpsd-f9a3fb0b26a407b9be87c87f39fcf94301b72d11.tar.gz |
[pep8] autopep8 whitespace cleanup
large scale autopep8 cleanup of several
pep8 whitespace warnings
-rwxr-xr-x | gegps | 3 | ||||
-rw-r--r-- | gps/client.py | 3 | ||||
-rw-r--r-- | gps/fake.py | 59 | ||||
-rwxr-xr-x | gps/gps.py | 9 | ||||
-rw-r--r-- | gps/misc.py | 6 | ||||
-rw-r--r-- | gpscap.py | 1 | ||||
-rwxr-xr-x | gpscat | 3 | ||||
-rwxr-xr-x | gpsprof | 2 | ||||
-rwxr-xr-x | xgps | 2 |
9 files changed, 77 insertions, 11 deletions
@@ -37,6 +37,7 @@ KML_OPEN_IN_GE = '''\ </kml> ''' + def kmlize(tpv): '''http://code.google.com/apis/kml/documentation/kmlreference.html for official kml document''' @@ -63,7 +64,7 @@ def kmlize(tpv): <coordinates>%s,%s,%s</coordinates> </Point> </Placemark> -</kml>""" % (speed,heading,longitude,latitude,longitude,latitude,altitude) +</kml>""" % (speed, heading, longitude, latitude, longitude, latitude, altitude) if __name__ == "__main__": diff --git a/gps/client.py b/gps/client.py index 94e3972c..6a996714 100644 --- a/gps/client.py +++ b/gps/client.py @@ -20,6 +20,7 @@ class json_error(exceptions.Exception): class gpscommon: "Isolate socket handling and buffering from the protocol interpretation." + def __init__(self, host="127.0.0.1", port=GPSD_PORT, verbose=0): self.sock = None # in case we blow up in connect self.linebuffer = "" @@ -139,6 +140,7 @@ WATCH_DEVICE = 0x000800 # watch specific device class gpsjson: "Basic JSON decoding." + def __iter__(self): return self @@ -197,6 +199,7 @@ class gpsjson: class dictwrapper: "Wrapper that yields both class and dictionary behavior," + def __init__(self, ddict): self.__dict__ = ddict diff --git a/gps/fake.py b/gps/fake.py index d6768626..1b49aeba 100644 --- a/gps/fake.py +++ b/gps/fake.py @@ -106,13 +106,16 @@ WRITE_PAD_SLOWDOWN = 0.01 # If a test takes longer than this, we deem it to have timed out TEST_TIMEOUT = 60 + class TestLoadError(exceptions.Exception): def __init__(self, msg): exceptions.Exception.__init__(self) self.msg = msg + class TestLoad: "Digest a logfile into a list of sentences we can cycle through." + def __init__(self, logfp, predump=False, slow=False, oneshot=False): self.sentences = [] # This is the interesting part if type(logfp) == type(""): @@ -161,7 +164,7 @@ class TestLoad: else: raise ValueError except (ValueError, IndexError): - raise TestLoadError("bad serial-parameter spec in %s"%\ + raise TestLoadError("bad serial-parameter spec in %s" %\ self.name) self.serial = (baud, databits, parity, stopbits) elif "Transport: UDP" in packet: @@ -175,7 +178,7 @@ class TestLoad: (_dummy, self.delimiter, delay) = packet.strip().split() self.delay = float(delay) except ValueError: - raise TestLoadError("bad Delay-Cookie line in %s"%\ + raise TestLoadError("bad Delay-Cookie line in %s" %\ self.name) self.resplit = True else: @@ -184,7 +187,7 @@ class TestLoad: if self.predump: print repr(packet) if not packet: - raise TestLoadError("zero-length packet from %s"%\ + raise TestLoadError("zero-length packet from %s" %\ self.name) self.sentences.append(packet) # Look at the first packet to grok the GPS type @@ -200,11 +203,13 @@ class TestLoad: if oneshot: self.sentences.append("# EOF\n") + class PacketError(exceptions.Exception): def __init__(self, msg): exceptions.Exception.__init__(self) self.msg = msg + class FakeGPS: def __init__(self, testload, progress=None): self.testload = testload @@ -230,8 +235,10 @@ class FakeGPS: time.sleep(self.testload.delay) self.index += 1 + class FakePTY(FakeGPS): "A FakePTY is a pty with a test log ready to be cycled to it." + def __init__(self, testload, speed=4800, databits=8, parity='N', stopbits=1, progress=None): @@ -269,8 +276,8 @@ class FakePTY(FakeGPS): cflag &= ~(termios.PARENB | termios.PARODD | termios.CRTSCTS) cflag |= termios.CREAD | termios.CLOCAL iflag = oflag = lflag = 0 - iflag &=~ (termios.PARMRK | termios.INPCK) - cflag &=~ (termios.CSIZE | termios.CSTOPB | termios.PARENB | termios.PARODD) + iflag &= ~ (termios.PARMRK | termios.INPCK) + cflag &= ~ (termios.CSIZE | termios.CSTOPB | termios.PARENB | termios.PARODD) if databits == 7: cflag |= termios.CS7 else: @@ -291,6 +298,7 @@ class FakePTY(FakeGPS): except termios.error: raise TestLoadError("error attempting to set serial mode to %s %s%s%s" \ % (speed, databits, parity, stopbits)) + def read(self): "Discard control strings written by gpsd." # A tcflush implementation works on Linux but fails on OpenBSD 4. @@ -312,6 +320,7 @@ class FakePTY(FakeGPS): "Wait for the associated device to drain (e.g. before closing)." termios.tcdrain(self.fd) + def cleansocket(host, port): "Get a socket that we can re-use cleanly after it's closed." cs = socket.socket(socket.AF_INET, socket.SOCK_STREAM) @@ -321,8 +330,10 @@ def cleansocket(host, port): cs.bind((host, port)) return cs + class FakeTCP(FakeGPS): "A TCP serverlet with a test log ready to be cycled to it." + def __init__(self, testload, host, port, progress=None): @@ -361,8 +372,10 @@ class FakeTCP(FakeGPS): if s != self.dispatcher: s.shutdown(socket.SHUT_RDWR) + class FakeUDP(FakeGPS): "A UDP broadcaster with a test log ready to be cycled to it." + def __init__(self, testload, ipaddr, port, progress=None): @@ -384,15 +397,19 @@ class FakeUDP(FakeGPS): "Wait for the associated device to drain (e.g. before closing)." pass # shutdown() fails on UDP + class DaemonError(exceptions.Exception): def __init__(self, msg): exceptions.Exception.__init__(self) self.msg = msg + def __str__(self): return repr(self.msg) + class DaemonInstance: "Control a gpsd instance." + def __init__(self, control_socket=None): self.sockfile = None self.pid = None @@ -402,11 +419,12 @@ class DaemonInstance: else: self.control_socket = "%s/gpsfake-%d.sock" % (self.tmpdir, os.getpid()) self.pidfile = "%s/gpsfake-%d.pid" % (self.tmpdir, os.getpid()) + def spawn(self, options, port, background=False, prefix=""): "Spawn a daemon instance." self.spawncmd = None - # Look for gpsd in GPSD_HOME env variable + # Look for gpsd in GPSD_HOME env variable if os.environ.get('GPSD_HOME'): for path in os.environ['GPSD_HOME'].split(':'): _spawncmd = "%s/gpsd" % path @@ -414,10 +432,10 @@ class DaemonInstance: self.spawncmd = _spawncmd break - # if we could not find it yet try PATH env variable for it + # if we could not find it yet try PATH env variable for it if not self.spawncmd: if not '/usr/sbin' in os.environ['PATH']: - os.environ['PATH']=os.environ['PATH'] + ":/usr/sbin" + os.environ['PATH'] = os.environ['PATH'] + ":/usr/sbin" for path in os.environ['PATH'].split(':'): _spawncmd = "%s/gpsd" % path if os.path.isfile(_spawncmd) and os.access(_spawncmd, os.X_OK): @@ -437,6 +455,7 @@ class DaemonInstance: status = os.system(self.spawncmd) if os.WIFSIGNALED(status) or os.WEXITSTATUS(status): raise DaemonError("daemon exited with status %d" % status) + def wait_pid(self): "Wait for the daemon, get its PID and a control-socket connection." while True: @@ -454,6 +473,7 @@ class DaemonInstance: continue # Avoid race condition -- PID not yet written fp.close() break + def __get_control_socket(self): # Now we know it's running, get a connection to the control socket. if not os.path.exists(self.control_socket): @@ -466,6 +486,7 @@ class DaemonInstance: self.sock.close() self.sock = None return self.sock + def is_alive(self): "Is the daemon still alive?" try: @@ -473,18 +494,21 @@ class DaemonInstance: return True except OSError: return False + def add_device(self, path): "Add a device to the daemon's internal search list." if self.__get_control_socket(): self.sock.sendall("+%s\r\n\x00" % path) self.sock.recv(12) self.sock.close() + def remove_device(self, path): "Remove a device from the daemon's internal search list." if self.__get_control_socket(): self.sock.sendall("-%s\r\n\x00" % path) self.sock.recv(12) self.sock.close() + def kill(self): "Kill the daemon instance." if self.pid: @@ -498,13 +522,16 @@ class DaemonInstance: pass self.pid = None + class TestSessionError(exceptions.Exception): def __init__(self, msg): exceptions.Exception.__init__(self) self.msg = msg + class TestSession: "Manage a session including a daemon with fake GPSes and clients." + def __init__(self, prefix=None, port=None, options=None, verbose=0, predump=False, udp=False, tcp=False, slow=False): "Initialize the test session by launching the daemon." self.prefix = prefix @@ -535,14 +562,17 @@ class TestSession: self.default_predicate = None self.fd_set = [] self.threadlock = None + def spawn(self): for sig in (signal.SIGQUIT, signal.SIGINT, signal.SIGTERM): signal.signal(sig, lambda unused, dummy: self.cleanup()) self.daemon.spawn(background=True, prefix=self.prefix, port=self.port, options=self.options) self.daemon.wait_pid() + def set_predicate(self, pred): "Set a default go predicate for the session." self.default_predicate = pred + def gps_add(self, logfile, speed=19200, pred=None, oneshot=False): "Add a simulated GPS being fed by the specified logfile." self.progress("gpsfake: gps_add(%s, %d)\n" % (logfile, speed)) @@ -570,6 +600,7 @@ class TestSession: newgps.exhausted = 0 self.daemon.add_device(newgps.byname) return newgps.byname + def gps_remove(self, name): "Remove a simulated GPS from the daemon's search list." self.progress("gpsfake: gps_remove(%s)\n" % name) @@ -577,6 +608,7 @@ class TestSession: self.remove(self.fakegpslist[name]) self.daemon.remove_device(name) del self.fakegpslist[name] + def client_add(self, commands): "Initiate a client session and force connection to a fake GPS." self.progress("gpsfake: client_add()\n") @@ -584,10 +616,11 @@ class TestSession: self.append(newclient) newclient.id = self.client_id + 1 self.client_id += 1 - self.progress("gpsfake: client %d has %s\n" % (self.client_id,newclient.device)) + self.progress("gpsfake: client %d has %s\n" % (self.client_id, newclient.device)) if commands: self.initialize(newclient, commands) return self.client_id + def client_remove(self, cid): "Terminate a client session." self.progress("gpsfake: client_remove(%d)\n" % cid) @@ -596,21 +629,25 @@ class TestSession: self.remove(obj) return True return False + def wait(self, seconds): "Wait, doing nothing." self.progress("gpsfake: wait(%d)\n" % seconds) time.sleep(seconds) + def gather(self, seconds): "Wait, doing nothing but watching for sentences." self.progress("gpsfake: gather(%d)\n" % seconds) #mark = time.time() time.sleep(seconds) + def cleanup(self): "We're done, kill the daemon." self.progress("gpsfake: cleanup()\n") if self.daemon: self.daemon.kill() self.daemon = None + def run(self): "Run the tests." try: @@ -670,6 +707,7 @@ class TestSession: self.readers += 1 if self.threadlock: self.threadlock.release() + def remove(self, obj): "Remove a producer or consumer from the object list." if self.threadlock: @@ -682,6 +720,7 @@ class TestSession: self.index = min(len(self.runqueue)-1, self.index) if self.threadlock: self.threadlock.release() + def choose(self): "Atomically get the next object scheduled to do something." if self.threadlock: @@ -692,6 +731,7 @@ class TestSession: if self.threadlock: self.threadlock.release() return self.runqueue[chosen] + def initialize(self, client, commands): "Arrange for client to ship specified commands when it goes active." client.enqueued = "" @@ -699,6 +739,7 @@ class TestSession: client.send(commands) else: client.enqueued = commands + def start(self): self.threadlock = threading.Lock() threading.Thread(target=self.run) @@ -18,6 +18,8 @@ from client import * from misc import isotime NaN = float('nan') + + def isnan(x): return str(x) == 'nan' # Don't hand-hack this list, it's generated. @@ -96,6 +98,7 @@ class gpsfix: self.eps = NaN self.epc = NaN + class gpsdata: "Position, track, velocity and status information returned by a GPS." @@ -106,6 +109,7 @@ class gpsdata: self.azimuth = azimuth self.ss = ss self.used = used + def __repr__(self): return "PRN: %3d E: %3d Az: %3d Ss: %3d Used: %s" % ( self.PRN, self.elevation, self.azimuth, self.ss, "ny"[self.used] @@ -164,8 +168,10 @@ class gpsdata: st += " %r\n" % sat return st + class gps(gpscommon, gpsdata, gpsjson): "Client interface to a running gpsd instance." + def __init__(self, host="127.0.0.1", port=GPSD_PORT, verbose=0, mode=0): gpscommon.__init__(self, host, port, verbose) gpsdata.__init__(self) @@ -332,7 +338,7 @@ class gps(gpscommon, gpsdata, gpsjson): def stream(self, flags=0, devpath=None): "Ask gpsd to stream reports at your client." - if (flags & (WATCH_JSON|WATCH_OLDSTYLE|WATCH_NMEA|WATCH_RAW)) == 0: + if (flags & (WATCH_JSON | WATCH_OLDSTYLE | WATCH_NMEA | WATCH_RAW)) == 0: flags |= WATCH_JSON if flags & WATCH_DISABLE: if flags & WATCH_OLDSTYLE: @@ -351,6 +357,7 @@ class gps(gpscommon, gpsdata, gpsjson): else: gpsjson.stream(self, flags, devpath) + def is_sbas(prn): "Is this the NMEA ID of an SBAS satellite?" return prn >= 120 and prn <= 158 diff --git a/gps/misc.py b/gps/misc.py index 240a9465..2fa2b5b5 100644 --- a/gps/misc.py +++ b/gps/misc.py @@ -18,14 +18,17 @@ MPS_TO_KNOTS = 1.9438445 # Meters per second to knots # EarthDistance code swiped from Kismet and corrected + def Deg2Rad(x): "Degrees to radians." return x * (math.pi/180) + def Rad2Deg(x): "Radians to degress." return x * (180/math.pi) + def CalcRad(lat): "Radius of curvature in meters at specified latitude." a = 6378.137 @@ -51,6 +54,7 @@ def CalcRad(lat): r = r * 1000.0 # Convert to meters return r + def EarthDistance((lat1, lon1), (lat2, lon2)): "Distance in meters between two points specified in degrees." x1 = CalcRad(lat1) * math.cos(Deg2Rad(lon1)) * math.sin(Deg2Rad(90-lat1)) @@ -68,6 +72,7 @@ def EarthDistance((lat1, lon1), (lat2, lon2)): elif a < -1: a = -1 return CalcRad((lat1+lat2) / 2) * math.acos(a) + def MeterOffset((lat1, lon1), (lat2, lon2)): "Return offset in meters of second arg from first." dx = EarthDistance((lat1, lon1), (lat1, lon2)) @@ -76,6 +81,7 @@ def MeterOffset((lat1, lon1), (lat2, lon2)): if lon1 < lon2: dx *= -1 return (dx, dy) + def isotime(s): "Convert timestamps in ISO8661 format to and from Unix time." if type(s) == type(1): @@ -7,6 +7,7 @@ BSD terms apply: see the file COPYING in the distribution root for details. """ import ConfigParser + class GPSDictionary(ConfigParser.RawConfigParser): def __init__(self, *files): "Initialize the capability dictionary" @@ -16,6 +16,7 @@ BASELEVEL = sniffer.LOG_IO highhalf_latch = True + def hexdump(st): dmp = "" for (_i, ch) in enumerate(st): @@ -27,10 +28,12 @@ def hexdump(st): debuglevel = 0 + def reporter(errlevel, msg): if errlevel <= debuglevel: sys.stdout.write(msg) + def printusage(): sys.stderr.write("usage: gpscat [-s speed] [-p] [-t] [-D debuglevel] serial-port\n") @@ -19,6 +19,7 @@ import time class Baton: "Ship progress indication to stderr." + def __init__(self, prompt, endmsg=None): self.stream = sys.stderr self.stream.write(prompt + "...") @@ -52,6 +53,7 @@ class Baton: class plotter: "Generic class for gathering and plotting sensor statistics." + def __init__(self): self.fixes = [] self.start_time = int(time.time()) @@ -37,6 +37,7 @@ SKY_VIEW_SORT_FIELDS = ('-used', 'PRN') class unit_adjustments: "Encapsulate adjustments for unit systems." + def __init__(self, units=None): self.altfactor = gps.METERS_TO_FEET self.altunits = "ft" @@ -306,6 +307,7 @@ class NoiseView: class MaidenheadView: "Encapsulate view object for watching Maidenhead grid location." + def __init__(self): self.widget = gtk.Entry() self.widget.set_editable(False) |