Mercurial > sat_docs
comparison flatpak/libervia_wrapper-dbus.py @ 171:a213053a03be
flatpak: update files following names change + Python 3 update:
- `build_manifest.py` has been fixed to work with recent SàT/Libervia
- filenames/scripts have been udpated to reflect project name change
- installation now uses `requirements.txt` when dev version is requested
- there are now 3 types of commands wrapper:
* `libervia_wrapper.py` uses `pb` bridge, starts backend before frontend, and stops it
when frontend is stopped. It's used by `Libervia Desktop` (Cagou)
* `libervia_wrapper-dbus.py` uses `dbus` bridge, starts backend before frontend, and
stops it when frontend is stopped. It's used for `Libervia TUI` (Primitivus)
* `libervia_wrapper-dbus.py` uses `dbus` bridge, starts backend if necessary and
doesn't stop it (to avoid waiting for backend start next time). It's used by
`Libervia CLI` (jp).
author | Goffi <goffi@goffi.org> |
---|---|
date | Tue, 30 Nov 2021 21:42:06 +0100 |
parents | |
children |
comparison
equal
deleted
inserted
replaced
170:e38a968cb873 | 171:a213053a03be |
---|---|
1 #!/usr/bin/env python3 | |
2 """This script launch Libervia backend if it's not before running command""" | |
3 | |
4 import os | |
5 import sys | |
6 import dbus | |
7 import subprocess | |
8 from sat.tools import config | |
9 | |
10 command = "##COMMAND##" | |
11 const_INT_PREFIX = "org.libervia.LiberviaCLI" | |
12 const_OBJ_PATH = '/org/libervia/Libervia/bridge' | |
13 | |
14 const_INT_PREFIX = config.getConfig( | |
15 config.parseMainConf(), | |
16 "", | |
17 "bridge_dbus_int_prefix", | |
18 "org.libervia.Libervia") | |
19 | |
20 # we remove any path with "/home" from PYTHONPATH because we have | |
21 # "--filesystem=home" permission and packages in .local/lib/pythonX/site-packages may | |
22 # conflict with the ones from flatpak | |
23 clean_pythonpath = ':'.join(p for p in sys.path if p and not p.startswith('/home')) | |
24 os.environ['PYTHONPATH'] = clean_pythonpath | |
25 os.environ['PYTHONNOUSERSITE'] = '1' | |
26 | |
27 try: | |
28 sessions_bus = dbus.SessionBus() | |
29 db_object = sessions_bus.get_object(const_INT_PREFIX, | |
30 const_OBJ_PATH) | |
31 except dbus.exceptions.DBusException as e: | |
32 if e._dbus_error_name != 'org.freedesktop.DBus.Error.ServiceUnknown': | |
33 raise e | |
34 # backend not found, we need to launch it | |
35 print("Launching Libervia backend") | |
36 subprocess.check_call("libervia-backend") | |
37 backend_launched = True | |
38 else: | |
39 backend_launched = False | |
40 | |
41 subprocess.run([command, *sys.argv[1:]]) | |
42 if backend_launched: | |
43 print("Stopping Libervia backend") | |
44 subprocess.check_call(["libervia-backend", "stop"]) |