Refactoring, create a src folders with the python toolchain
This commit is contained in:
1 parent
2790d92a60
commit
33e4fe0c4e
19 files changed
+246
-122
No files matched your search
@@ -0,0 +1,75 @@
|
||||
"""Charge l'application comme le Freebox Player (fichiers servis en HTTP) et échoue si Qt
|
||||
signale une erreur ou un avertissement venant de l'app.
|
||||
|
||||
En HTTP, Qt ne peut pas lister les dossiers : c'est là qu'apparaissent les « X is not a type »
|
||||
(qmldir manquant) ou « Cyclic dependency » (singletons), invisibles en lançant depuis le disque.
|
||||
"""
|
||||
import argparse
|
||||
import functools
|
||||
import http.server
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
import tempfile
|
||||
import threading
|
||||
|
||||
from .project import PROJECT_DIR, libfbxqml, qmlscene
|
||||
|
||||
# Messages attendus hors de la box : Settings de libfbxqml (pas d'objet App sur PC).
|
||||
EXPECTED = ("/libfbxqml/", "qml: Setting", "qml: Getting settings failed")
|
||||
|
||||
|
||||
class _Quiet(http.server.SimpleHTTPRequestHandler):
|
||||
def log_message(self, *args):
|
||||
pass
|
||||
|
||||
|
||||
class _Server(http.server.ThreadingHTTPServer):
|
||||
def handle_error(self, request, client_address):
|
||||
pass # qmlscene qui s'arrête en plein téléchargement (BrokenPipe) : sans intérêt
|
||||
|
||||
|
||||
def problems(output):
|
||||
"""Lignes de sortie de qmlscene qui ne sont pas attendues."""
|
||||
return [line for line in output.splitlines()
|
||||
if line.strip() and not any(marker in line for marker in EXPECTED)]
|
||||
|
||||
|
||||
def run(duration):
|
||||
lib, scene = libfbxqml(), qmlscene()
|
||||
server = _Server(
|
||||
("127.0.0.1", 0), functools.partial(_Quiet, directory=str(PROJECT_DIR)))
|
||||
threading.Thread(target=server.serve_forever, daemon=True).start()
|
||||
url = "http://127.0.0.1:%d/Jellyfin.qml" % server.server_address[1]
|
||||
print("Chargement de %s pendant %g s…" % (url, duration), flush=True)
|
||||
try:
|
||||
with tempfile.TemporaryDirectory() as runtime:
|
||||
os.chmod(runtime, 0o700)
|
||||
# Rendu logiciel : la CI (conteneur) n'a pas d'OpenGL.
|
||||
env = dict(os.environ, XDG_RUNTIME_DIR=runtime,
|
||||
QT_QPA_PLATFORM="offscreen", QT_QUICK_BACKEND="software")
|
||||
try:
|
||||
result = subprocess.run([scene, "-I", str(lib), url], env=env, timeout=duration,
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT, text=True)
|
||||
output = result.stdout
|
||||
except subprocess.TimeoutExpired as expired: # cas normal : l'app reste ouverte
|
||||
output = expired.stdout or ""
|
||||
if isinstance(output, bytes):
|
||||
output = output.decode(errors="replace")
|
||||
finally:
|
||||
server.shutdown()
|
||||
|
||||
unexpected = problems(output)
|
||||
if unexpected:
|
||||
print("Échec : messages inattendus au chargement :", file=sys.stderr)
|
||||
print("\n".join(unexpected), file=sys.stderr)
|
||||
return 1
|
||||
print("OK : chargement sans erreur.")
|
||||
return 0
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser(prog="freebox-jellyfin check", description=__doc__.splitlines()[0])
|
||||
parser.add_argument("--duration", type=float, default=6, help="durée du chargement en secondes (défaut : 6)")
|
||||
args = parser.parse_args(argv)
|
||||
return run(args.duration)
|
||||
Reference in new issue
Block a user