diff options
Diffstat (limited to 'test_client.py')
-rwxr-xr-x | test_client.py | 74 |
1 files changed, 69 insertions, 5 deletions
diff --git a/test_client.py b/test_client.py index 850e8d3..deeb67b 100755 --- a/test_client.py +++ b/test_client.py @@ -3,7 +3,7 @@ # This file is part of Remote Support Desktop # https://gitlab.das-netzwerkteam.de/RemoteWebApp/rwa.support.sessionservice # Copyright 2020, 2021 Jonathan Weth <dev@jonathanweth.de> -# Copyright 2020 Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> +# Copyright 2020, 2021 Daniel Teichmann <daniel.teichmann@das-netzwerkteam.de> # Copyright 2020 Mike Gabriel <mike.gabriel@das-netzwerkteam.de> # SPDX-License-Identifier: GPL-2.0-or-later # @@ -25,11 +25,75 @@ # 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 +from typing import Union + import dbus -bus = dbus.SessionBus() -time = bus.get_object("org.ArcticaProject.RWASupportSessionService", "/RWASupportSessionService") +def str2bool(v: Union[str, bool, int]) -> bool: + """Return true or false if the given string can be interpreted as a boolean. + + If it fails, 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.") + + +def main(): + parser = argparse.ArgumentParser(description="D-Bus Session Service API test client") + arguments = parser.add_mutually_exclusive_group() + arguments.add_argument( + "-s", + "--start", + const=True, + nargs="?", + default=True, + help="Starts a new support session by calling the D-Bus Session Service (default)", + ) + arguments.add_argument("-x", "--stop", help="Stops <PID>, an existing support session.") + arguments.add_argument( + "-r", "--refresh_status", help="Refreshes the status of <PID>, an existing support session." + ) + arguments.add_argument( + "-i", "--status", help="Gets the status of <PID>, an existing support session." + ) + args = parser.parse_args() + + start = args.start + stop_pid = args.stop + status_pid = args.status + refresh_pid = args.refresh_status + + bus = dbus.SessionBus() + req = bus.get_object("org.ArcticaProject.RWASupportSessionService", "/RWASupportSessionService") + + if stop_pid: + print(f"Sending D-Bus request 'stop': {stop_pid}") + response = req.stop(stop_pid) + print(f"Your response is: {response}") + elif status_pid: + print(f"Sending D-Bus request 'status': {status_pid}") + response = req.status(status_pid) + print(f"Your response is: {response}") + elif refresh_pid: + print(f"Sending D-Bus request 'refresh_status': {refresh_pid}") + response = req.refresh_status(refresh_pid) + print(f"Your response is: {response}") + elif start: + print("Sending D-Bus request 'start'") + response = req.start() + print(f"Your response is: {response}") + else: + print("No valid input!") + return + -curr = time.start() -print("Your VNC session is", curr) +if __name__ == "__main__": + main() |