aboutsummaryrefslogtreecommitdiff
path: root/service.py
diff options
context:
space:
mode:
authorDaniel Teichmann <daniel.teichmann@das-netzwerkteam.de>2020-07-22 14:56:40 +0200
committerDaniel Teichmann <daniel.teichmann@das-netzwerkteam.de>2020-07-22 14:56:40 +0200
commit2269d143c43ff5c14061cf26fa8adc6e93393ec4 (patch)
tree6304922f938ca7de679985ab821e6396ee315bcc /service.py
parent6a6ac63ecc6539362b470b98a5f15717fad7ca6b (diff)
downloadRWA.Support.SessionService-2269d143c43ff5c14061cf26fa8adc6e93393ec4.tar.gz
RWA.Support.SessionService-2269d143c43ff5c14061cf26fa8adc6e93393ec4.tar.bz2
RWA.Support.SessionService-2269d143c43ff5c14061cf26fa8adc6e93393ec4.zip
Add -m/--mockup-mode feature to service.py and session.py
Diffstat (limited to 'service.py')
-rwxr-xr-xservice.py36
1 files changed, 33 insertions, 3 deletions
diff --git a/service.py b/service.py
index 45cb17a..eb6d311 100755
--- a/service.py
+++ b/service.py
@@ -1,4 +1,6 @@
#!/usr/bin/env python3
+import argparse
+
import json
import time
from threading import Thread
@@ -8,9 +10,12 @@ import dbus.service
from session import Session
+from typing import Union
class RWAService(dbus.service.Object):
- def __init__(self):
+ def __init__(self, mockup_mode: bool):
+ self.mockup_mode = mockup_mode
+
self.bus = dbus.SessionBus()
name = dbus.service.BusName("org.ArcticaProject.RWA", bus=self.bus)
@@ -22,7 +27,7 @@ class RWAService(dbus.service.Object):
def start(self):
"""Start a new remote session."""
# Start session
- session = Session()
+ session = Session(mockup_mode)
# Add session to sessions list
self.sessions[session.pid] = session
@@ -85,13 +90,38 @@ 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 True
+ elif v.lower() in ('no', 'false', 'f', 'n', '0', 0):
+ return False
+ else:
+ 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.")
+
+ 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!")
import dbus.mainloop.glib
from gi.repository import GLib
dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
loop = GLib.MainLoop()
- object = RWAService()
+ object = RWAService(mockup_mode)
loop.run()