diff options
author | Jonathan Weth <git@jonathanweth.de> | 2021-06-28 11:58:01 +0200 |
---|---|---|
committer | Jonathan Weth <git@jonathanweth.de> | 2021-06-28 11:58:01 +0200 |
commit | d81082efdea8b603914f04b6690d11c28fc8fcf7 (patch) | |
tree | ce35e8cd1514c178e7f16c73b5980a1783d7513c | |
parent | cc4e3d56a1e8dd3338c1a0efb01e443ff5730521 (diff) | |
download | RWA.Support.SessionService-d81082efdea8b603914f04b6690d11c28fc8fcf7.tar.gz RWA.Support.SessionService-d81082efdea8b603914f04b6690d11c28fc8fcf7.tar.bz2 RWA.Support.SessionService-d81082efdea8b603914f04b6690d11c28fc8fcf7.zip |
Use click in Session Service
-rwxr-xr-x | rwa/support/sessionservice/service.py | 49 |
1 files 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 <https://www.gnu.org/licenses/>. -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.") |