#!/usr/bin/env python3
# SPDX-License-Identifier: MIT
"""Census the PC software collections on the mirror: counts by year, image format and size.
Only file names are read (and one directory listing per folder); no archive is opened and
nothing is copied. The collections are found by environment variable, never by a path in
this repository:
- ``EXODOS_DIR``: eXoDOS's game folder (the one holding ``
().zip``).
- ``EXODEMOSCENE_DIR``: eXoDemoScene's production folder (`` ().zip``).
- ``TDC_DIR``: the Total DOS Collection's ``Games`` folder (``Files//``,
``Images/{Floppy,CD,Cartridge}/...``).
Unset variables are reported and skipped.
EXODOS_DIR=... TDC_DIR=... python3 -I scripts/census_software.py
"""
from __future__ import annotations
import collections
import os
import re
import sys
from pathlib import Path
YEAR = re.compile(r"\((\d{4})\)")
TAG = re.compile(r"\[([^\]]+)\]")
EARLY = 1987 # the 5150/5160 era for this census: titles up to and including this year
def by_year(names: list[str]) -> collections.Counter[str]:
years: collections.Counter[str] = collections.Counter()
for name in names:
match = YEAR.search(name)
years[match.group(1) if match else "unknown"] += 1
return years
def early(years: collections.Counter[str]) -> int:
return sum(n for y, n in years.items() if y.isdigit() and int(y) <= EARLY)
def zips(folder: Path) -> list[str]:
return sorted(p.name for p in folder.rglob("*.zip"))
def main() -> int:
for var, label in (("EXODOS_DIR", "eXoDOS games"), ("EXODEMOSCENE_DIR", "eXoDemoScene productions")):
value = os.environ.get(var)
if not value:
print(f"{label}: {var} not set, skipped")
continue
names = [p.name for p in Path(value).glob("*.zip")]
years = by_year(names)
print(f"{label}: {len(names)} archives, {early(years)} dated {EARLY} or earlier")
print(" by year: " + " ".join(f"{y}:{n}" for y, n in sorted(years.items())))
tdc = os.environ.get("TDC_DIR")
if not tdc:
print("Total DOS Collection: TDC_DIR not set, skipped")
return 0
root = Path(tdc)
files = zips(root / "Files")
years = by_year(files)
print(f"TDC Files (installed games): {len(files)} archives, {early(years)} dated {EARLY} or earlier")
for kind in ("Floppy", "CD", "Cartridge"):
folder = root / "Images" / kind
if not folder.exists():
continue
names = zips(folder)
years = by_year(names)
tags: collections.Counter[str] = collections.Counter(t for n in names for t in TAG.findall(n))
print(f"TDC Images/{kind}: {len(names)} archives, {early(years)} dated {EARLY} or earlier")
print(" tags: " + ", ".join(f"[{t}] {n}" for t, n in tags.most_common(16)))
return 0
if __name__ == "__main__":
sys.exit(main())