# Amiga ADF fixtures (tools/fixtures.py): DD and HD images formatted as OFS, FFS, FFS international and OFS / FFS with # directory cache by amitools' `xdftool` (PyPI amitools through `uvx`), filled with a tree (nested directories, an # empty file, a file large enough for extension blocks, Latin-1 names, protection bits, a set date; amitools 0.8.1's # `comment` command fails, so comments are not covered); each # file read back by `xdftool read` for the reference data, protection / dates from `xdftool list`. # The images are emitted gzip-compressed (mostly empty blocks). # tests/gen/adf.luau { cases = { { name, gz, volume, fs, entries = { { name, size?, crc?, dir?, comment?, mtime? } } } } } import calendar, gzip, importlib.util, os, shutil, time, zlib _s = importlib.util.spec_from_file_location("_arch2", os.path.join(os.path.dirname(os.path.abspath(__file__)), "_arch2.py")) A = importlib.util.module_from_spec(_s) _s.loader.exec_module(A) INPUTS = ["tools/fixtures/_arch2.py"] def xdf(args, cwd): return A.tool(["uv"], ["uvx", "--from", "amitools==0.8.1", "xdftool"] + args, cwd=cwd).decode("latin-1") def generate(ctx): rng = ctx.rng(1985) tmp = A.tmpdir() try: files = [("readme", b"Amiga readme\n" * 20), ("empty", b""), ("s/startup-sequence", b"echo hello\n"), ("deep/a/b/c/leaf.bin", rng.randbytes(1500)), ("big.bin", rng.randbytes(100000)), ("café ü", b"latin-1 name\n")] for i, (_, d) in enumerate(files): open(os.path.join(tmp, "f%d" % i), "wb").write(d) cases = [] for fs, size in (("ofs", "dd"), ("ffs", "dd"), ("ffs+intl", "dd"), ("ofs+dc", "dd"), ("ffs+dc", "dd"), ("ffs", "hd")): img = "t-%s-%s.adf" % (fs.replace("+", "_"), size) cmd = [img, "-f", "create", "size=1760K" if size == "hd" else "size=880K", "+", "format", "Vol " + fs, fs] dirs = set() for i, (name, _) in enumerate(files): parts = name.split("/")[:-1] for k in range(1, len(parts) + 1): d = "/".join(parts[:k]) if d not in dirs: dirs.add(d) cmd += ["+", "makedir", d] cmd += ["+", "write", "f%d" % i, name] cmd += ["+", "protect", "readme", "rw", "+", "time", "readme", "01.02.1993 10:20:30.00"] xdf(cmd, tmp) ents = [{"name": d + "/", "dir": True} for d in sorted(dirs)] for i, (name, d) in enumerate(files): out = os.path.join(tmp, "out%d" % i) xdf([img, "read", name, out], tmp) rd = open(out, "rb").read() assert rd == d, (img, name) e = {"name": name, "size": len(d), "crc": zlib.crc32(d)} if name == "readme": e["mtime"] = calendar.timegm((1993, 2, 1, 10, 20, 30)) ents.append(e) cases.append({"name": img, "gz": gzip.compress(open(os.path.join(tmp, img), "rb").read(), mtime=0), "volume": "Vol " + fs, "fs": "ofs" if fs.startswith("ofs") else "ffs", "entries": ents, "listing": xdf([img, "list"], tmp)}) ctx.emit("adf", {"cases": cases}) finally: shutil.rmtree(tmp)