annotate flatpak/libervia_wrapper.py @ 175:73053fcc74c2

association: ajout du compte rendu de l'AG extraordinaire du 30 octobre 2021
author Goffi <goffi@goffi.org>
date Thu, 02 Dec 2021 21:21:36 +0100
parents a213053a03be
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
171
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
1 #!/usr/bin/env python3
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
2 """This script launch Libervia backend if it's not before running command"""
138
274af514a5cf flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff changeset
3
274af514a5cf flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff changeset
4 import os
274af514a5cf flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff changeset
5 import sys
274af514a5cf flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff changeset
6 import subprocess
171
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
7 from sat.tools import config
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
8 from pathlib import Path
138
274af514a5cf flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff changeset
9
274af514a5cf flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff changeset
10 command = "##COMMAND##"
171
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
11
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
12 local_path = Path(config.getConfig(
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
13 config.parseMainConf(),
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
14 "",
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
15 "local_dir"
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
16 ))
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
17 socket_path = local_path / "bridge_pb"
138
274af514a5cf flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff changeset
18
142
2602c690806b flatpak (sat_wrapper): don't use packages from $HOME in PYTHONPATH to avoid conflicts:
Goffi <goffi@goffi.org>
parents: 138
diff changeset
19 # we remove any path with "/home" from PYTHONPATH because we have
171
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
20 # "--filesystem=home" permission and packages in .local/lib/pythonX/site-packages may
142
2602c690806b flatpak (sat_wrapper): don't use packages from $HOME in PYTHONPATH to avoid conflicts:
Goffi <goffi@goffi.org>
parents: 138
diff changeset
21 # conflict with the ones from flatpak
2602c690806b flatpak (sat_wrapper): don't use packages from $HOME in PYTHONPATH to avoid conflicts:
Goffi <goffi@goffi.org>
parents: 138
diff changeset
22 clean_pythonpath = ':'.join(p for p in sys.path if p and not p.startswith('/home'))
2602c690806b flatpak (sat_wrapper): don't use packages from $HOME in PYTHONPATH to avoid conflicts:
Goffi <goffi@goffi.org>
parents: 138
diff changeset
23 os.environ['PYTHONPATH'] = clean_pythonpath
2602c690806b flatpak (sat_wrapper): don't use packages from $HOME in PYTHONPATH to avoid conflicts:
Goffi <goffi@goffi.org>
parents: 138
diff changeset
24 os.environ['PYTHONNOUSERSITE'] = '1'
138
274af514a5cf flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff changeset
25
171
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
26 if not socket_path.is_socket():
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
27 # backend is not launched we need to launch it
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
28 print("Launching Libervia backend")
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
29 subprocess.check_call("libervia-backend")
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
30 backend_launched = True
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
31 else:
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
32 backend_launched = False
138
274af514a5cf flatpak: reworked packages + made a building script:
Goffi <goffi@goffi.org>
parents:
diff changeset
33
171
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
34 subprocess.run([command, *sys.argv[1:]])
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
35 if backend_launched:
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
36 print("Stopping Libervia backend")
a213053a03be flatpak: update files following names change + Python 3 update:
Goffi <goffi@goffi.org>
parents: 142
diff changeset
37 subprocess.check_call(["libervia-backend", "stop"])