aboutsummaryrefslogtreecommitdiff
path: root/rwa/support/sessionservice
diff options
context:
space:
mode:
authorJonathan Weth <git@jonathanweth.de>2021-06-28 11:59:29 +0200
committerJonathan Weth <git@jonathanweth.de>2021-06-28 11:59:29 +0200
commite67b9b7ef03ad48aad62dd82b48fb7fdfe3949a8 (patch)
treedb4a4897185ac618fa7b046c20e032ecb0fc4a63 /rwa/support/sessionservice
parent9ec08cbc84b01ce82f58892556637d8934ede0a5 (diff)
parentd81082efdea8b603914f04b6690d11c28fc8fcf7 (diff)
downloadRWA.Support.SessionService-e67b9b7ef03ad48aad62dd82b48fb7fdfe3949a8.tar.gz
RWA.Support.SessionService-e67b9b7ef03ad48aad62dd82b48fb7fdfe3949a8.tar.bz2
RWA.Support.SessionService-e67b9b7ef03ad48aad62dd82b48fb7fdfe3949a8.zip
Merge branch 'master' into feature/multiple-hosts
Diffstat (limited to 'rwa/support/sessionservice')
-rwxr-xr-xrwa/support/sessionservice/service.py49
-rw-r--r--rwa/support/sessionservice/session.py2
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()