Files
rosetta/tools/fixtures/docs_arch2.py
T

71 lines
5.2 KiB
Python

# Docs inputs for the archive page's encodings / disk images / LHA-ARJ-Zoo sections and the font page's bitmap and
# Type 1 sections (tools/fixtures.py; tools/docs_check.py explains the inputs): a uuencoded file (sharutils), an
# .lzh (LHa for UNIX), an .arj (arj), a .zoo (built as tools/fixtures/zoo.py does), a D64 (VICE c1541), an ADF
# (amitools xdftool), a FAT floppy (mkfs.fat + mtools), BDF / PSF from Spleen, a PCF by bdftopcf, a .fnt by FontForge,
# Latin Modern's lmr10.pfb, an EOT around DejaVu Sans Mono (built as tools/fixtures/eot.py does) and a JHF text.
# tests/gen/docs_arch2.luau { files = { [name] = bytes }, vars = { uuText = "notes.uu", ... } }
import importlib.util, json, os, shutil, subprocess
HERE = os.path.dirname(os.path.abspath(__file__))
INPUTS = ["tools/docs_check.py", "tools/fixtures/_arch2.py", "tools/fixtures/zoo.py", "tools/fixtures/eot.py", "tools/fixtures/hershey.py"]
def mod(name, path):
spec = importlib.util.spec_from_file_location(name, path)
m = importlib.util.module_from_spec(spec)
spec.loader.exec_module(m)
return m
def store(pkg):
return subprocess.run(["nix", "build", "--no-link", "--print-out-paths", "nixpkgs#" + pkg], capture_output=True, check=True, text=True).stdout.strip().split("\n")[-1]
def generate(ctx):
dc = mod("docs_check", os.path.join(ctx.root, "tools", "docs_check.py"))
A = mod("_arch2", os.path.join(HERE, "_arch2.py"))
zoo = mod("zoo_fx", os.path.join(HERE, "zoo.py"))
eot = mod("eot_fx", os.path.join(HERE, "eot.py"))
hershey = mod("hershey_fx", os.path.join(HERE, "hershey.py"))
os.environ["MTOOLS_SKIP_CHECK"] = "1"
os.environ["TZ"] = "UTC"
files = {}
tmp = A.tmpdir()
try:
tree = [("readme.txt", b"formats-luau retro archives\n"), ("src/main.c", b"int main(void) { return 0; }\n")]
A.tree(tree, tmp)
files["notes.uu"] = A.tool(["sharutils"], ["uuencode", "readme.txt", "readme.txt"], cwd=tmp)
A.tool([], ["env", "NIXPKGS_ALLOW_UNFREE=1", "nix", "shell", "--impure", "nixpkgs#lha", "-c", "lha", "-a2o5q", "tree.lzh", "readme.txt", "src"], cwd=tmp)
files["tree.lzh"] = open(os.path.join(tmp, "tree.lzh"), "rb").read()
A.tool(["arj"], ["arj", "a", "-m1", "-r", "-y", "tree.arj", "readme.txt", "src"], cwd=tmp)
files["tree.arj"] = open(os.path.join(tmp, "tree.arj"), "rb").read()
data = tree[0][1]
files["tree.zoo"] = zoo.archive([("readme.txt", "", 1, zoo.lzw(data), len(data), zoo.crc16(data), 2, 0, None)])
A.tool(["vice"], ["c1541", "-format", "games,gd", "d64", "games.d64", "-write", "readme.txt", "readme"], cwd=tmp)
files["games.d64"] = open(os.path.join(tmp, "games.d64"), "rb").read()
A.tool(["uv"], ["uvx", "--from", "amitools==0.8.1", "xdftool", "work.adf", "-f", "create", "size=880K", "+", "format", "Work", "ffs",
"+", "makedir", "s", "+", "write", "readme.txt", "s/readme"], cwd=tmp)
files["work.adf"] = open(os.path.join(tmp, "work.adf"), "rb").read()
A.tool(["dosfstools"], ["mkfs.fat", "-C", "-F", "12", "-n", "DOCS", "floppy.img", "720"], cwd=tmp)
A.tool(["mtools"], ["mcopy", "-s", "-m", "-i", "floppy.img", "readme.txt", "src", "::/"], cwd=tmp)
files["floppy.img"] = open(os.path.join(tmp, "floppy.img"), "rb").read()
spleen = os.path.join(store("spleen"), "share", "fonts", "misc")
files["spleen-5x8.bdf"] = open(os.path.join(spleen, "spleen-5x8.bdf"), "rb").read()
A.tool(["xorg.bdftopcf"], ["bdftopcf", "-o", os.path.join(tmp, "spleen.pcf"), os.path.join(spleen, "spleen-5x8.bdf")])
files["spleen-5x8.pcf"] = open(os.path.join(tmp, "spleen.pcf"), "rb").read()
files["spleen-8x16.psfu"] = open(os.path.join(store("spleen"), "share", "consolefonts", "spleen-8x16.psfu"), "rb").read()
A.tool(["fontforge"], ["fontforge", "-lang=ff", "-c", 'Open($1); Generate($2, "fnt")', os.path.join(spleen, "spleen-8x16.bdf"), os.path.join(tmp, "spleen.fnt")])
fnt = [f for f in os.listdir(tmp) if f.endswith(".fnt")][0]
files["spleen.fnt"] = open(os.path.join(tmp, fnt), "rb").read()
files["lmr10.pfb"] = open(os.path.join(store("lmodern"), "share", "fonts", "type1", "public", "lm", "lmr10.pfb"), "rb").read()
dejavu = os.path.join(store("dejavu_fonts"), "share", "fonts", "truetype", "DejaVuSansMono.ttf")
facts = json.loads(ctx.python(["fonttools"], eot.CODE, input=json.dumps([dejavu]).encode()))[0]
files["mono.eot"] = eot.eot(open(dejavu, "rb").read(), facts, 0x00020001)
files["roman.jhf"] = (hershey.record(699, -8, 8, []) + "\n" + hershey.record(501, -9, 9, [[(0, -12), (-8, 9)], [(0, -12), (8, 9)], [(-5, 2), (5, 2)]]) + "\n").encode()
finally:
A.rmtree(tmp)
dc.emit_inputs(ctx, files, {"uuText": "notes.uu", "lzhBytes": "tree.lzh", "arjBytes": "tree.arj", "zooBytes": "tree.zoo",
"d64Bytes": "games.d64", "adfBytes": "work.adf", "floppyBytes": "floppy.img",
"bdfText": "spleen-5x8.bdf", "pcfBytes": "spleen-5x8.pcf", "psfBytes": "spleen-8x16.psfu",
"fntBytes": "spleen.fnt", "pfbBytes": "lmr10.pfb", "eotBytes": "mono.eot", "jhfText": "roman.jhf"})