diff options
Diffstat (limited to 'rwa/support')
-rwxr-xr-x | rwa/support/sessionservice/service.py | 49 | ||||
-rw-r--r-- | rwa/support/sessionservice/session.py | 2 |
2 files changed, 22 insertions, 29 deletions
diff --git a/rwa/support/sessionservice/service.py b/rwa/support/sessionservice/service.py index 4798df6..2bc727d 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 @@ -354,7 +354,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.") @@ -363,38 +379,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.") diff --git a/rwa/support/sessionservice/session.py b/rwa/support/sessionservice/session.py index 81584ea..11c418e 100644 --- a/rwa/support/sessionservice/session.py +++ b/rwa/support/sessionservice/session.py @@ -143,6 +143,7 @@ class Session: }, ) except requests.exceptions.ConnectionError: + self.stop(triggered=True) raise ConnectionError() logging.info( @@ -151,6 +152,7 @@ class Session: ) if r.status_code != 200: + self.stop(triggered=True) raise ConnectionError() self.meta = r.json() |