From d81082efdea8b603914f04b6690d11c28fc8fcf7 Mon Sep 17 00:00:00 2001 From: Jonathan Weth Date: Mon, 28 Jun 2021 11:58:01 +0200 Subject: Use click in Session Service --- rwa/support/sessionservice/service.py | 49 ++++++++++++++--------------------- 1 file changed, 20 insertions(+), 29 deletions(-) diff --git a/rwa/support/sessionservice/service.py b/rwa/support/sessionservice/service.py index c50da26..3e9900d 100755 --- a/rwa/support/sessionservice/service.py +++ b/rwa/support/sessionservice/service.py @@ -25,7 +25,6 @@ # You should have received a copy of the GNU General Public License # along with this program. If not, see . -import argparse import json import logging import signal @@ -33,6 +32,7 @@ import time from threading import Thread from typing import Union +import click import dbus import dbus.mainloop.glib import dbus.service @@ -284,7 +284,23 @@ def str2bool(v: Union[str, bool, int]) -> bool: raise argparse.ArgumentTypeError("Boolean value expected.") -def main(): +@click.command() +@click.option( + "-m", + "--mockup", + is_flag=True, + default=False, + help="Activates mock up mode. Acts like the real Session Service " + "but don't do changes or call RWA.Support.WebApp.", +) +@click.option( + "-o", + "--once", + is_flag=True, + default=False, + help="Runs as one-time-service. Stops after one session.", +) +def main(mockup, once): # Check for lock file if is_locked(): logging.error("The service is already running.") @@ -293,38 +309,13 @@ def main(): # Create lock file lock() - parser = argparse.ArgumentParser(description="D-Bus Session Service for RWA.Support") - parser.add_argument( - "-m", - "--mockup-mode", - type=str2bool, - nargs="?", - const=True, - default=False, - help="Activates mock up mode. Acts like the real session service " - "but don't do changes or call RWA.", - ) - parser.add_argument( - "-o", - "--one-time", - type=str2bool, - nargs="?", - const=True, - default=False, - help="Runs as one-time-service. Stops after one session.", - ) - - args = parser.parse_args() - mockup_mode = args.mockup_mode - one_time = args.one_time - - if mockup_mode: + if mockup: logging.warning("All API responses are faked and should NOT BE USED IN PRODUCTION!") dbus.mainloop.glib.DBusGMainLoop(set_as_default=True) loop = GLib.MainLoop() - service_object = RWASupportSessionService(loop, mockup_mode, one_time) + service_object = RWASupportSessionService(loop, mockup, once) def signal_handler(sig, frame): logging.info("Service was terminated.") -- cgit v1.2.3