diff options
Diffstat (limited to 'service.py')
-rwxr-xr-x | service.py | 38 |
1 files changed, 22 insertions, 16 deletions
@@ -1,16 +1,15 @@ #!/usr/bin/env python3 import argparse - import json import time from threading import Thread +from typing import Union import dbus import dbus.service from session import Session -from typing import Union class RWAService(dbus.service.Object): def __init__(self, mockup_mode: bool): @@ -90,33 +89,40 @@ class RWAService(dbus.service.Object): self.update_service_running = False # TODO Probably kill daemon here (quit main loop) + def str2bool(v: Union[str, bool, int]) -> bool: """Return true or false if the given string can be interpreted as a boolean otherwise raise an exception.""" if isinstance(v, bool): - return v - if v.lower() in ('yes', 'true', 't', 'y', '1', 1): + return v + if v.lower() in ("yes", "true", "t", "y", "1", 1): return True - elif v.lower() in ('no', 'false', 'f', 'n', '0', 0): + elif v.lower() in ("no", "false", "f", "n", "0", 0): return False else: - raise argparse.ArgumentTypeError('Boolean value expected.') + raise argparse.ArgumentTypeError("Boolean value expected.") + if __name__ == "__main__": - parser = argparse.ArgumentParser(description='DBus session service for ' + - 'ArcticaProject\'s ' + - 'Remote Web App') - parser.add_argument("-m", "--mockup-mode", type=str2bool, nargs='?', - const=True, default=False, - help="Activate mockup mode. Act like the session " + - "service but don\'t do changes or call other " + - "parts of RWA.") + parser = argparse.ArgumentParser( + description="DBus session service for " + "ArcticaProject's " + "Remote Web App" + ) + parser.add_argument( + "-m", + "--mockup-mode", + type=str2bool, + nargs="?", + const=True, + default=False, + help="Activate mockup mode. Act like the session " + + "service but don't do changes or call other " + + "parts of RWA.", + ) args = parser.parse_args() mockup_mode = args.mockup_mode if mockup_mode: - print("All API responses are faked and should NOT BE USED IN " + - "PRODUCTION!") + print("All API responses are faked and should NOT BE USED IN " + "PRODUCTION!") import dbus.mainloop.glib from gi.repository import GLib |