3 """A script to start a typical breadcrumb session."""
5 # Copyright (C) 2008 Laurens Van Houtven <lvh at laurensvh.be>
6 # This program is free software: you can redistribute it and/or modify
7 # it under the terms of the GNU General Public License as published by
8 # the Free Software Foundation, either version 3 of the License, or
9 # (at your option) any later version.
11 # This program is distributed in the hope that it will be useful,
12 # but WITHOUT ANY WARRANTY; without even the implied warranty of
13 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 # GNU General Public License for more details.
16 # You should have received a copy of the GNU General Public License
17 # along with this program. If not, see <http://www.gnu.org/licenses/>.
23 import breadcrumb
.client
.gps
as gps
24 import breadcrumb
.client
.tracking
as tracking
26 def main(manual_args
= None):
27 """Tries to start a typical breadcrumb client.
29 The optional manual_args arument should be a list that looks somewhat like
30 sys.argv[1:] (a list of arguments). It is provided because WinCE doesn't
31 have system() -- this provides a workaround so you can start this function
32 with different a different set of argvs using a small Python script.
34 opts
= getopt(manual_args
)
37 logging
.info('Breadcrumb client')
39 tracker
= tracking
.Tracker(host
= opts
.host
, port
= opts
.port
)
42 logging
.debug("fake GPS specified...")
43 gpsdevice
= gps
.connect(platform
= 'fake',
44 sentence_filename
= opts
.fake_file
)
45 elif opts
.gpsd_host
and opts
.gpsd_port
:
46 logging
.debug("gpsd GPS specified...")
47 gpsdevice
= gps
.connect(platform
= 'gpsd',
48 host
= opts
.gpsd_host
,
49 port
= opts
.gpsd_port
)
51 logging
.debug("No GPS specified...")
52 host
, port
= opts
.gpsd_host
, opts
.serial_port
53 gpsdevice
= gps
.connect(host
= host
, port
= port
)
55 tracker
.gps
= gpsdevice
60 logging
.debug("Closed the GPS port.")
62 def getopt(manual_args
):
63 """Gets the command line options."""
65 ('-F', '--fake-gps'): {
67 'action': 'store_true',
68 'help': 'Replay sentences with a simulated ("fake") GPS.'
71 ('', '--fake-file'): {
74 'help': 'Uses a non-standard sentence file.',
79 'help': 'The host to connect to.',
86 'help': 'The TCP/UDP port the server is listening on.',
90 ('-s', '--serial-port'): {
92 'dest': 'serial_port',
93 'help': 'The serial port the GPS is on.',
97 ('-g', '--gpsd-host'): {
100 'help': 'The hostname of the gpsd server.',
104 ('-p', '--gpsd-port'): {
107 'help': 'The port of the gpsd server.',
111 ('-v', '--verbose'): {
113 'action': 'store_true',
114 'help': 'Show debug messages.',
119 'action': 'store_true',
120 'help': 'Only show errors.',
123 ('-Q', '--very-quiet'): {
125 'action': 'store_true',
126 'help': "Don't even show errors (not recommended).",
130 optparser
= optparse
.OptionParser()
131 for flags
, options
in optparser_config
.iteritems():
132 optparser
.add_option(*flags
, **options
)
134 # We have no positional arguments:
135 if manual_args
is None:
136 return optparser
.parse_args()[0]
138 return optparser
.parse_args(manual_args
)[0]
140 def set_verbosity(opts
):
141 """Sets the verbosity level of the logging module from optparser input."""
143 logging
.getLogger().setLevel(logging
.DEBUG
)
145 logging
.getLogger().setLevel(logging
.ERROR
)
147 logging
.getLogger().disable()
149 logging
.getLogger().setLevel(logging
.INFO
)
151 if __name__
== "__main__":