Skip to content

Commit 56ac544

Browse files
committed
Startup: Add argument parser, option to enable debug output.
1 parent 90a59c1 commit 56ac544

File tree

5 files changed

+23
-11
lines changed

5 files changed

+23
-11
lines changed

bin/warpinator

+12-3
Original file line numberDiff line numberDiff line change
@@ -1,20 +1,29 @@
11
#!/usr/bin/python3
22

33
import sys
4+
import argparse
5+
46
from gi.repository import Gio
57

6-
if len(sys.argv) > 1 and sys.argv[1] == "autostart":
8+
parser = argparse.ArgumentParser(description="Send and Receive Files across the Network")
9+
parser.add_argument("-d", "--debug", help="Print debugging information.",
10+
action="store_true")
11+
parser.add_argument("-a", "--autostart", help="Exit if (dconf) org.x.warpinator.preferences 'autostart' is false.",
12+
action="store_true")
13+
args = parser.parse_args()
14+
15+
if args.autostart:
716
settings = Gio.Settings(schema_id="org.x.warpinator.preferences")
817
if not settings.get_boolean("autostart"):
918
sys.exit(0)
1019

11-
del sys.argv[1]
20+
del sys.argv[1:]
1221

1322
sys.path.insert(0, "/usr/libexec/warpinator/")
1423

1524
try:
1625
import warpinator
17-
sys.exit(warpinator.main())
26+
sys.exit(warpinator.main(debug=args.debug))
1827
except Exception as e:
1928
print(e)
2029
sys.exit(1)

data/warpinator-autostart.desktop

+1-1
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,6 @@ Icon=warpinator
66

77
# the autostart argument tells /usr/bin/warpinator to check our autostart gsettings key and either keeps
88
# going or exits immediately.
9-
Exec=warpinator autostart
9+
Exec=warpinator --autostart
1010

1111
Categories=GNOME;GTK;Utility;

src/server.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,8 @@ def Ping(self, request, context):
266266
try:
267267
remote = self.remote_machines[request.id]
268268
except KeyError as e:
269-
logging.warning("Received ping from unknown remote '%s': %s" % (request.readable_name, e))
269+
logging.debug("Received ping from unknown remote (or not fully online yet) '%s': %s"
270+
% (request.readable_name, e))
270271
return void
271272

272273
# If we receive a ping, assume no transfer is happening, set clear busy flag from our respective

src/warpinator.py

+7-5
Original file line numberDiff line numberDiff line change
@@ -1312,18 +1312,20 @@ def send_status_icon_selection_to_machine(self, uri, remote_machine=None):
13121312
def on_tray_icon_activate(self, icon, button, time):
13131313
self.window.toggle_visibility(time)
13141314

1315-
def main(test = False):
1315+
def main(test=False, debug=False):
13161316
import signal
13171317

13181318
logging.basicConfig(format="%(asctime)-15s::warpinator::%(levelname)s: %(message)s -- %(filename)s (line %(lineno)d)")
1319-
logging.root.setLevel(logging.DEBUG)
1320-
args = sys.argv
13211319

1322-
w = WarpApplication(test)
1320+
if debug:
1321+
logging.root.setLevel(logging.DEBUG)
1322+
else:
1323+
logging.root.setLevel(logging.INFO)
13231324

1325+
w = WarpApplication(test)
13241326
signal.signal(signal.SIGINT, lambda s, f: w.shutdown())
13251327

1326-
return w.run(args)
1328+
return w.run(sys.argv)
13271329

13281330
if __name__ == "__main__":
13291331
main()

testing/testrun

+1-1
Original file line numberDiff line numberDiff line change
@@ -13,4 +13,4 @@ os.environ["GSETTINGS_BACKEND"] = "memory"
1313
sys.path.insert(0, "/usr/libexec/warpinator")
1414

1515
import warpinator
16-
warpinator.main(True) # testmode
16+
warpinator.main(test=True)

0 commit comments

Comments
 (0)