Add basic setup about the package generation
This commit is contained in:
1 parent
8e6392a84c
commit
821332508f
4 files changed
+151
No files matched your search
@@ -73,3 +73,6 @@ Thumbs.db
|
||||
|
||||
# Log de tools/deploy.py
|
||||
deploy.log
|
||||
|
||||
# Paquets FreeStore (tools/package.py)
|
||||
dist/
|
||||
@@ -20,6 +20,8 @@ There is no build system or test suite.
|
||||
- **Reproduce the box's loading mode**: the Player loads the app over HTTP, which behaves differently from local files (see constraints below). Check with `python3 -m http.server 8765 --directory .` then `QT_QPA_PLATFORM=offscreen qmlscene -I ../libfbxqml http://127.0.0.1:8765/Jellyfin.qml` — it must print no warnings.
|
||||
- The desktop has Qt 5.15 while the box targets QtQuick 2.5: code that runs locally can still use APIs too new for the box.
|
||||
|
||||
**FreeStore package**: `tools/package.py` → `dist/<identifier>.tar.gz` (gitignored). Replicates the QtCreator plugin's "Make FreeStore Package": same file selection as `Jellyfin.fbxproject` (QML/JS/images/fonts/`qmldir`/`manifest.json`, excluding `tools/` and hidden dirs), manifest checks (identifier `\w+(\.\w+)+`, entry-point files present), `qmllint` on all sources, ustar tar with directory entries, gzipped. Upload is manual on the FreeFactory console (http://factory.free.fr), followed by Free's review.
|
||||
|
||||
**Deploying a test build to the Freebox**: `tools/deploy.py` (Python stdlib only; Player must be in developer mode). It discovers the Player via SSDP (`fbx:devel`) or takes `--box <IP>`, serves the repo over HTTP, calls JSON-RPC `debug_qml_app` on `http://<box>/pub/devel`, and streams the app's stdout/stderr until it exits. `--server <host>` and `--user name[:password]` (both repeatable) serve a virtual `dev-config.json` next to the app; at startup `Session.loadDevConfig()` adds each listed server and stores users in `Session.devUsers`, which `UserSelectView` merges with public users (one-click sign-in when a password is given; never log passwords) (only when the app is loaded over HTTP; 404 otherwise, ignored) — the workaround for the lack of persistence in dev mode. Output is also written to `deploy.log` (repo root, gitignored, overwritten each run) — read it to diagnose on-box failures. The Player fetches files lazily from that HTTP server, so the script must keep running while the app is in use. This replicates the "Run" of the official QtCreator plugin, whose own setup is:
|
||||
|
||||
- SDK setup: https://dev.freebox.fr/sdk/player.html (Windows: https://github.com/fbx/freebox-qtcreator-plugin/issues/8)
|
||||
|
||||
@@ -36,3 +36,10 @@ En mode développement, la box n'enregistre aucune donnée de l'application. Pou
|
||||
- `--user <nom>[:<mot de passe>]` (répétable) : le compte apparaît sur « Qui regarde ? », même si le serveur masque ses comptes. Avec un mot de passe, la connexion se fait en un clic ; sans, l'écran de connexion s'ouvre avec le nom pré-rempli. Le mot de passe n'apparaît pas dans les logs, mais il transite en clair sur le réseau local.
|
||||
|
||||
Le script sert les fichiers du projet au Player et affiche les logs de l'application. Il doit rester ouvert pendant le test (Ctrl+C pour arrêter).
|
||||
|
||||
## Publier sur le FreeStore
|
||||
```bash
|
||||
tools/package.py # crée dist/com.stilobique.jellyfin.tar.gz
|
||||
```
|
||||
|
||||
Le script reproduit « Make FreeStore Package » du plugin QtCreator : il vérifie `manifest.json` et la syntaxe QML/JS (`qmllint`), puis crée l'archive à téléverser sur la console [FreeFactory](http://factory.free.fr) (compte développeur requis, validation par Free avant publication).
|
||||
Executable
+139
@@ -0,0 +1,139 @@
|
||||
#!/usr/bin/env python3
|
||||
"""Fabrique le paquet FreeStore (.tar.gz) à téléverser sur la console FreeFactory.
|
||||
|
||||
Reproduit « Outils > Freebox SDK > Make FreeStore Package » du plugin QtCreator Freebox
|
||||
(github.com/fbx/freebox-qtcreator-plugin, src/freestorepackager.cc) :
|
||||
- fichiers inclus comme dans Jellyfin.fbxproject : QML, JS, images, polices, qmldir et
|
||||
manifest.json (tools/ est exclu : l'aperçu PC n'a rien à faire sur la box) ;
|
||||
- vérifications : manifest.json (identifiant, points d'entrée existants), JSON valides,
|
||||
syntaxe QML/JS (qmllint, s'il est installé) ;
|
||||
- archive tar (format ustar, avec les entrées de dossiers) compressée en gzip.
|
||||
|
||||
Usage : tools/package.py [--output dist/paquet.tar.gz]
|
||||
"""
|
||||
import argparse
|
||||
import io
|
||||
import json
|
||||
import os
|
||||
import re
|
||||
import shutil
|
||||
import subprocess
|
||||
import sys
|
||||
import tarfile
|
||||
import time
|
||||
|
||||
PROJECT_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
|
||||
|
||||
# Types de fichiers repris de Jellyfin.fbxproject (QmlFiles, JavaScriptFiles, ImageFiles, Files).
|
||||
EXTENSIONS = {".qml", ".js", ".png", ".jpg", ".jpeg", ".gif", ".svg", ".bmp", ".webp",
|
||||
".ttf", ".otf", ".woff"}
|
||||
NAMES = {"qmldir", "manifest.json"}
|
||||
EXCLUDED_DIRS = {"tools", "dist"}
|
||||
|
||||
|
||||
def collect_files():
|
||||
files = []
|
||||
for root, dirs, names in os.walk(PROJECT_DIR):
|
||||
rel_root = os.path.relpath(root, PROJECT_DIR)
|
||||
# Dossiers cachés (.git, .idea…) et dossiers d'outillage exclus.
|
||||
dirs[:] = sorted(d for d in dirs if not d.startswith(".")
|
||||
and not (rel_root == "." and d in EXCLUDED_DIRS))
|
||||
for name in sorted(names):
|
||||
if name in NAMES or os.path.splitext(name)[1].lower() in EXTENSIONS:
|
||||
files.append(os.path.normpath(os.path.join(rel_root, name)))
|
||||
return files
|
||||
|
||||
|
||||
def check_manifest(files):
|
||||
"""Mêmes règles que fileformat/manifest.cc du plugin. Renvoie le manifest."""
|
||||
path = os.path.join(PROJECT_DIR, "manifest.json")
|
||||
if not os.path.exists(path):
|
||||
raise ValueError("manifest.json manquant")
|
||||
manifest = json.load(open(path, encoding="utf-8"))
|
||||
identifier = manifest.get("identifier")
|
||||
if not isinstance(identifier, str) or not re.fullmatch(r"\w+(\.\w+)+", identifier):
|
||||
raise ValueError("manifest.json : « identifier » absent ou invalide (forme attendue : a.b.c)")
|
||||
entry_points = manifest.get("entryPoints")
|
||||
if not isinstance(entry_points, dict) or not entry_points:
|
||||
raise ValueError("manifest.json : « entryPoints » absent ou invalide")
|
||||
defaults = 0
|
||||
for key, entry in entry_points.items():
|
||||
if not isinstance(entry, dict) or not isinstance(entry.get("file"), str):
|
||||
raise ValueError("manifest.json : entryPoints.%s.file doit être un fichier" % key)
|
||||
if not re.fullmatch(r"[/\w.+~-]+", entry["file"]):
|
||||
raise ValueError("manifest.json : caractères invalides dans entryPoints.%s.file" % key)
|
||||
if entry["file"] not in files:
|
||||
raise ValueError("manifest.json : entryPoints.%s.file « %s » absent du paquet" % (key, entry["file"]))
|
||||
if "uiFlavor" in entry and entry["uiFlavor"] not in ("multi", "classic"):
|
||||
raise ValueError("manifest.json : entryPoints.%s.uiFlavor doit valoir multi ou classic" % key)
|
||||
if entry.get("default") is True:
|
||||
defaults += 1
|
||||
if defaults > 1:
|
||||
raise ValueError("manifest.json : un seul point d'entrée peut avoir « default »: true")
|
||||
icon = manifest.get("icon")
|
||||
if icon and icon not in files:
|
||||
raise ValueError("manifest.json : icône « %s » absente du paquet" % icon)
|
||||
return manifest
|
||||
|
||||
|
||||
def check_sources(files):
|
||||
for name in files:
|
||||
if name.endswith(".json"):
|
||||
json.load(open(os.path.join(PROJECT_DIR, name), encoding="utf-8"))
|
||||
qmllint = shutil.which("qmllint")
|
||||
if not qmllint:
|
||||
print("Attention : qmllint introuvable, syntaxe QML/JS non vérifiée.")
|
||||
return
|
||||
sources = [os.path.join(PROJECT_DIR, f) for f in files if f.endswith((".qml", ".js"))]
|
||||
result = subprocess.run([qmllint] + sources, capture_output=True, text=True)
|
||||
if result.returncode != 0:
|
||||
raise ValueError("erreurs de syntaxe QML/JS :\n" + (result.stdout + result.stderr).strip())
|
||||
|
||||
|
||||
def build_archive(files, output):
|
||||
def info(name, is_dir, size=0):
|
||||
entry = tarfile.TarInfo(name + ("/" if is_dir else ""))
|
||||
entry.type = tarfile.DIRTYPE if is_dir else tarfile.REGTYPE
|
||||
entry.mode = 0o755 if is_dir else 0o644
|
||||
entry.size = size
|
||||
entry.mtime = int(time.time())
|
||||
entry.uid = entry.gid = 0
|
||||
entry.uname = entry.gname = ""
|
||||
return entry
|
||||
|
||||
os.makedirs(os.path.dirname(os.path.abspath(output)), exist_ok=True)
|
||||
seen_dirs = set()
|
||||
with tarfile.open(output, "w:gz", format=tarfile.USTAR_FORMAT) as archive:
|
||||
for name in files:
|
||||
# Entrées de dossiers (comme le plugin), du parent vers l'enfant.
|
||||
parts = name.split(os.sep)[:-1]
|
||||
for depth in range(1, len(parts) + 1):
|
||||
directory = "/".join(parts[:depth])
|
||||
if directory not in seen_dirs:
|
||||
seen_dirs.add(directory)
|
||||
archive.addfile(info(directory, True))
|
||||
data = open(os.path.join(PROJECT_DIR, name), "rb").read()
|
||||
archive.addfile(info(name.replace(os.sep, "/"), False, len(data)), io.BytesIO(data))
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("--output", help="archive à créer (défaut : dist/<identifier>.tar.gz)")
|
||||
args = parser.parse_args()
|
||||
|
||||
files = collect_files()
|
||||
try:
|
||||
manifest = check_manifest(files)
|
||||
check_sources(files)
|
||||
except (ValueError, json.JSONDecodeError) as error:
|
||||
sys.exit("Paquet non créé : %s" % error)
|
||||
|
||||
output = args.output or os.path.join(PROJECT_DIR, "dist", manifest["identifier"] + ".tar.gz")
|
||||
build_archive(files, output)
|
||||
print("Paquet créé : %s (%d fichiers, %.1f Ko)" % (
|
||||
os.path.relpath(output, os.getcwd()), len(files), os.path.getsize(output) / 1024))
|
||||
print("À téléverser sur la console FreeFactory (http://factory.free.fr).")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in new issue
Block a user