aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorDaniel Teichmann <daniel.teichmann@das-netzwerkteam.de>2021-06-24 19:41:03 +0200
committerJonathan Weth <git@jonathanweth.de>2021-06-28 11:10:42 +0200
commit0ee14ff59311838af5d8d96d9ce763169979e9fd (patch)
treec96d4ec4bacbf260226801fd33416cb81003c7e4
parent3526def9614ac5275f176a42938d11736233f108 (diff)
downloadRWA.Support.SessionService-0ee14ff59311838af5d8d96d9ce763169979e9fd.tar.gz
RWA.Support.SessionService-0ee14ff59311838af5d8d96d9ce763169979e9fd.tar.bz2
RWA.Support.SessionService-0ee14ff59311838af5d8d96d9ce763169979e9fd.zip
Update test_client.py to existing API-features
-rwxr-xr-xtest_client.py74
-rw-r--r--tox.ini10
2 files changed, 74 insertions, 10 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()
diff --git a/tox.ini b/tox.ini
index db4d9c2..7bf007e 100644
--- a/tox.ini
+++ b/tox.ini
@@ -15,9 +15,9 @@ commands =
[testenv:lint]
commands =
- poetry run black --check --diff rwa/
- poetry run isort -c --diff --stdout rwa/
- poetry run flake8 {posargs} rwa/
+ poetry run black --check --diff rwa/ test_client.py
+ poetry run isort -c --diff --stdout rwa/ test_client.py
+ poetry run flake8 {posargs} rwa/ test_client.py
[testenv:security]
commands =
@@ -34,8 +34,8 @@ commands = poetry run make -C docs/ html {posargs}
[testenv:reformat]
commands =
- poetry run isort rwa/
- poetry run black rwa/
+ poetry run isort rwa/ test_client.py
+ poetry run black rwa/ test_client.py
[flake8]
max_line_length = 100