1.0.2: converter searches no subfolders, safer filters, forms, links and watermark
A document at the root of a checkout of 68377 folders needed 56 minutes, because the converter named the suite, the document folder and the build folder with `//` in TEXINPUTS; it now names them without recursion and the same document converts in 11.5 seconds. A file below the document no longer replaces a package of TeX Live. The security review of the pending changes found four defects, each fixed with a test proven red against the old files and green against the new ones twice: an HTML table read in an empty sandbox, so an iframe opens no address; form labels written through the LaTeX writer, so they are set as text; the form pattern scans a line once instead of quadratically; a kept build folder no longer lays the links of an earlier drawing over a new one. The form tests remove the PDF of an earlier run before each conversion. Also carried: forms out of Markdown, link colours from the company, clickable links in prose, HTML tables and SVG drawings, the watermark, and the further changes of 1.0.1 and 1.0.2 in the CHANGELOG. npm test: 1232 of 1232 checks. Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
This commit is contained in:
1 parent
adc58e19d7
commit
d7aac52ac7
28 files changed
+3918
-137
No files matched your search
Executable
+97
@@ -0,0 +1,97 @@
|
||||
#!/usr/bin/env python3
|
||||
# Copyright (c) 2026 Marc Wäckerlin. SPDX-License-Identifier: MIT
|
||||
"""Convert the SVG drawings of a company to the PDF form LaTeX includes.
|
||||
|
||||
No TeX engine reads an SVG, so a company that has its logo as an SVG gets a PDF
|
||||
of the same name beside it, and the identity names the logo without a format:
|
||||
`logo = company-logo` finds `company-logo.pdf`. The SVG stays the source.
|
||||
|
||||
logo.py <directory> [<directory> …] convert every drawing
|
||||
logo.py --check <directory> [<directory> …] name every PDF that is
|
||||
missing or older than its SVG
|
||||
|
||||
Only the directories named are read, not their folders: a company keeps its
|
||||
drawings beside its identity, and a tree further down is somebody else's.
|
||||
"""
|
||||
import argparse
|
||||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
|
||||
|
||||
# A shell opened by a snap-packaged editor can point a system Inkscape at the
|
||||
# editor's GTK modules and settings schemas. The resulting process aborts before
|
||||
# reading the SVG. These paths belong to the parent application, not to the
|
||||
# converter subprocess.
|
||||
SNAP_LEAKS = ("GSETTINGS_SCHEMA_DIR", "GTK_PATH", "GIO_MODULE_DIR",
|
||||
"GTK_IM_MODULE_FILE", "XDG_DATA_DIRS")
|
||||
|
||||
|
||||
def inkscape_environment():
|
||||
"""The caller's environment without GTK paths owned by an editor snap."""
|
||||
environment = os.environ.copy()
|
||||
for name in SNAP_LEAKS:
|
||||
environment.pop(name, None)
|
||||
return environment
|
||||
|
||||
|
||||
def drawings(directory):
|
||||
"""Every SVG of one directory, as pairs of source and target."""
|
||||
return [(os.path.join(directory, name),
|
||||
os.path.join(directory, os.path.splitext(name)[0] + ".pdf"))
|
||||
for name in sorted(os.listdir(directory))
|
||||
if name.lower().endswith(".svg")]
|
||||
|
||||
|
||||
def stale(source, target):
|
||||
"""True where the PDF has to be made again."""
|
||||
return not os.path.exists(target) \
|
||||
or os.path.getmtime(target) < os.path.getmtime(source)
|
||||
|
||||
|
||||
def convert(source, target):
|
||||
"""inkscape, the converter the drawing filter of the suite uses as well."""
|
||||
result = subprocess.run(
|
||||
["inkscape", "--export-type=pdf", "--export-filename=" + target,
|
||||
source],
|
||||
env=inkscape_environment(),
|
||||
stdout=subprocess.PIPE, stderr=subprocess.STDOUT,
|
||||
encoding="utf-8", errors="replace")
|
||||
if result.returncode != 0 or not os.path.exists(target):
|
||||
return f"{source}: inkscape could not convert the drawing:\n" \
|
||||
f"{result.stdout.strip()}"
|
||||
print(target)
|
||||
return None
|
||||
|
||||
|
||||
def main(arguments=None):
|
||||
parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
|
||||
parser.add_argument("directories", nargs="+", metavar="directory")
|
||||
parser.add_argument("--check", action="store_true")
|
||||
options = parser.parse_args(arguments)
|
||||
missing = [directory for directory in options.directories
|
||||
if not os.path.isdir(directory)]
|
||||
for directory in missing:
|
||||
print(f"{directory}: there is no such directory", file=sys.stderr)
|
||||
if missing:
|
||||
return 1
|
||||
pairs = [pair for directory in options.directories
|
||||
for pair in drawings(directory)]
|
||||
if options.check:
|
||||
outdated = [(source, target) for source, target in pairs
|
||||
if stale(source, target)]
|
||||
for source, target in outdated:
|
||||
print(f"{target} is missing or older than {source}",
|
||||
file=sys.stderr)
|
||||
return 1 if outdated else 0
|
||||
failures = [failure for failure in
|
||||
(convert(source, target) for source, target in pairs
|
||||
if stale(source, target))
|
||||
if failure]
|
||||
for failure in failures:
|
||||
print(failure, file=sys.stderr)
|
||||
return 1 if failures else 0
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
sys.exit(main())
|
||||
Reference in new issue
Block a user