Add command line argument parsing with '-c' option
Only print satellite info to standard output if -c / --console-output flag is given.
This commit is contained in:
parent
16379cb745
commit
1f8a09c4f4
|
@ -1,4 +1,5 @@
|
|||
#!/usr/bin/env python3
|
||||
import argparse
|
||||
import gi
|
||||
import gpxpy
|
||||
import os
|
||||
|
@ -37,6 +38,15 @@ class SatelliteApp(Gtk.Application):
|
|||
self, *args, application_id="page.codeberg.tpikonen.satellite",
|
||||
flags=Gio.ApplicationFlags.FLAGS_NONE, **kwargs)
|
||||
Handy.init()
|
||||
|
||||
desc = "Displays navigation satellite data and saves GPX tracks"
|
||||
parser = argparse.ArgumentParser(description=desc)
|
||||
parser.add_argument(
|
||||
'-c', '--console-output', dest='console_output',
|
||||
action='store_true', default=False,
|
||||
help='Output satellite data to console')
|
||||
self.args = parser.parse_args()
|
||||
|
||||
GLib.unix_signal_add(GLib.PRIORITY_DEFAULT, signal.SIGINT,
|
||||
self.sigint_handler)
|
||||
|
||||
|
@ -363,7 +373,8 @@ class SatelliteApp(Gtk.Application):
|
|||
value = fun(data[key])
|
||||
descs.append(desc)
|
||||
vals.append(value)
|
||||
print(f"{desc}: {value}")
|
||||
if self.args.console_output:
|
||||
print(f"{desc}: {value}")
|
||||
|
||||
if self.dataframe.rows != len(descs):
|
||||
self.dataframe.set_rowtitles(descs)
|
||||
|
@ -491,7 +502,8 @@ class SatelliteApp(Gtk.Application):
|
|||
data["updateage"] = ((time.time() - self.last_update)
|
||||
if self.last_update else None)
|
||||
barchart = self.format_satellite_data(data)
|
||||
print(barchart)
|
||||
if self.args.console_output:
|
||||
print(barchart)
|
||||
self.infolabel.set_markup("<tt>" + barchart + "</tt>")
|
||||
self.set_values(data)
|
||||
mode = data["mode"]
|
||||
|
|
Loading…
Reference in a new issue