summaryrefslogtreecommitdiff
path: root/gpsfake.py
diff options
context:
space:
mode:
authorEric S. Raymond <esr@thyrsus.com>2007-12-19 22:28:08 +0000
committerEric S. Raymond <esr@thyrsus.com>2007-12-19 22:28:08 +0000
commit493072ac784c97946a5c42965cf53ecf5d6d2e7a (patch)
treea4fd93477a1f6d84bd884c0a5640bb96a8b12e07 /gpsfake.py
parent3b357a9a07fd924aa07645828b005c2fb5e107e9 (diff)
downloadgpsd-493072ac784c97946a5c42965cf53ecf5d6d2e7a.tar.gz
Better path handling for gpsfake (patch by bzed).
Diffstat (limited to 'gpsfake.py')
-rw-r--r--gpsfake.py15
1 files changed, 14 insertions, 1 deletions
diff --git a/gpsfake.py b/gpsfake.py
index b7e13aed..3268d716 100644
--- a/gpsfake.py
+++ b/gpsfake.py
@@ -312,6 +312,8 @@ class FakeGPS:
class DaemonError(exceptions.Exception):
def __init__(self, msg):
self.msg = msg
+ def __str__(self):
+ return repr(self.msg)
class DaemonInstance:
"Control a gpsd instance."
@@ -325,10 +327,21 @@ class DaemonInstance:
self.pidfile = "/tmp/gpsfake_pid-%s" % os.getpid()
def spawn(self, options, port, background=False, prefix=""):
"Spawn a daemon instance."
+ self.spawncmd = None
+ if not '/usr/sbin' in os.environ['PATH']:
+ 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):
+ self.spawncmd = _spawncmd
+ break
+
+ if not self.spawncmd:
+ raise DaemonError("Cannot execute gpsd: executeable not found.")
# The -b option to suppress hanging on probe returns is needed to cope
# with OpenBSD (and possibly other non-Linux systems) that don't support
# anything we can use to implement the FakeGPS.read() method
- self.spawncmd = "gpsd -b -N -S %s -F %s -P %s %s" % (port, self.control_socket, self.pidfile, options)
+ self.spawncmd += " -b -N -S %s -F %s -P %s %s" % (port, self.control_socket, self.pidfile, options)
if prefix:
self.spawncmd = prefix + " " + self.spawncmd.strip()
if background: