Prepare EPS graphics and BibTeX references for desktop previews

This commit is contained in:
gloamxun committed 2026-12-02 10:41:10 +08:00
1 parent 715ad81bcf
commit b38e39416e
8 files changed
+787 -7

No files matched your search

+28 -3
View File
@@ -13,6 +13,7 @@ import shutil
import signal
import subprocess
import sys
import tarfile
import tempfile
@@ -21,6 +22,7 @@ WEB_FILES = ("index.html", "styles.css", "favicon.svg", "app.js")
NATIVE_FILES = ("latex.tfx", "format-resources.json")
EDITOR = "bin/native_editor"
RECEIPT = "desktop-bundle.json"
EPS_TOOLS = "eps-tools.tar"
PAYLOAD = (
EDITOR, *NATIVE_FILES, "bundle.json", "native-beta.py", "wsl-launch.py",
*(f"web/{name}" for name in WEB_FILES),
@@ -54,7 +56,10 @@ def package_receipt(directory):
data = (directory / RECEIPT).read_bytes()
receipt = json.loads(data)
files = receipt.get("sha256", {})
require(receipt.get("schema") == 1 and set(files) == set(PAYLOAD), "Invalid desktop bundle receipt")
expected = set(PAYLOAD)
if EPS_TOOLS in files:
expected.add(EPS_TOOLS)
require(receipt.get("schema") == 1 and set(files) == expected, "Invalid desktop bundle receipt")
require(all(is_sha(value) for value in files.values()), "Invalid desktop bundle hashes")
return data, files
@@ -116,6 +121,9 @@ def prepare(args, repo):
write_json(bundle / "bundle.json", manifest)
hashes = {EDITOR: editor_sha, **native_sha}
hashes.update({name: digest(bundle / name) for name in PAYLOAD if name not in hashes})
if args.eps_tools:
shutil.copyfile(args.eps_tools.resolve(strict=True), bundle / EPS_TOOLS)
hashes[EPS_TOOLS] = digest(bundle / EPS_TOOLS)
write_json(bundle / RECEIPT, {
"schema": 1, "native_commit": args.commit, "web_commit": WEB_COMMIT, "sha256": hashes,
})
@@ -151,12 +159,26 @@ def install(package, home):
shutil.copyfile(package / name, path)
check_file(path, expected)
(bundle / EDITOR).chmod(0o700)
if EPS_TOOLS in files:
root = bundle / "eps-tools"
root.mkdir(mode=0o700)
with tarfile.open(bundle / EPS_TOOLS) as archive:
archive.extractall(root, filter="data")
eps_environment(root)
(bundle / RECEIPT).write_bytes(receipt)
(bundle / "state").symlink_to(home / "state", target_is_directory=True)
bundle.rename(destination)
return destination
def eps_environment(root):
bubblewrap = root / "usr/bin/bwrap"
ghostscript = root / "usr/bin/gs"
require(all(tool.is_file() and os.access(tool, os.X_OK) for tool in (bubblewrap, ghostscript)),
"Desktop EPS converter is missing or incomplete")
return {"TEXRRA_EPS_BWRAP": str(bubblewrap), "TEXRRA_EPS_GS_ROOT": str(root)}
def launch_error(message):
detail = " ".join(str(message).splitlines())
print(f"Texrra desktop error {detail}", flush=True)
@@ -187,8 +209,10 @@ def launch(args):
sys.executable, bundle / "native-beta.py", "web", "--web-dir", bundle / "web",
"--projects-dir", home / "projects", "--port", "0",
]
with subprocess.Popen(command, stdin=subprocess.DEVNULL,
env=dict(os.environ, **{INSTANCE_ENV: args.instance})) as child:
env = dict(os.environ, **{INSTANCE_ENV: args.instance})
if (bundle / EPS_TOOLS).is_file():
env.update(eps_environment(bundle / "eps-tools"))
with subprocess.Popen(command, stdin=subprocess.DEVNULL, env=env) as child:
try:
print(f"Texrra desktop PID {child.pid}", flush=True)
while child.poll() is None:
@@ -238,6 +262,7 @@ def main():
stage.add_argument("output", type=Path)
stage.add_argument("--artifact-dir", type=Path, required=True)
stage.add_argument("--commit", required=True)
stage.add_argument("--eps-tools", type=Path, help="optional Fedora EPS converter tar archive")
stage.add_argument("--reference-bundle", type=Path,
default=repo / "target/p4-a4-child-release/browser-bundle")
stage.add_argument("--web-repo", type=Path, default=repo.parent / "texrra-web")