Dark theme, scan auto-ingest, packaging prep, and README refresh
This commit is contained in:
@@ -88,6 +88,42 @@ def ingest_dat(conn, path):
|
||||
return dat_name, system, release_count, rom_count
|
||||
|
||||
|
||||
def ensure_catalog(dats_dir=None, conn=None):
|
||||
"""Ingest any DAT files missing from the DB (idempotent, cheap when current).
|
||||
|
||||
Called once at startup so a fresh/reset database still has the catalog and
|
||||
scanning produces matches instead of everything coming back ``unknown``.
|
||||
Returns the number of DATs ingested.
|
||||
"""
|
||||
dats_dir = Path(dats_dir) if dats_dir else config.DATS_DIR
|
||||
if not dats_dir.is_dir():
|
||||
return 0
|
||||
files = sorted(p for p in dats_dir.glob("*.dat") if p.is_file())
|
||||
if not files:
|
||||
return 0
|
||||
|
||||
own = conn is None
|
||||
if own:
|
||||
conn = get_connection(config.DB_PATH)
|
||||
try:
|
||||
known = {r["source_path"] for r in conn.execute("SELECT source_path FROM dats")}
|
||||
count = 0
|
||||
for path in files:
|
||||
if str(path) in known:
|
||||
continue
|
||||
try:
|
||||
ingest_dat(conn, path)
|
||||
except Exception as exc: # noqa: BLE001 - a bad DAT shouldn't block startup
|
||||
print(f"warning: could not ingest {path.name}: {exc}", file=sys.stderr)
|
||||
continue
|
||||
count += 1
|
||||
conn.commit()
|
||||
return count
|
||||
finally:
|
||||
if own:
|
||||
conn.close()
|
||||
|
||||
|
||||
def main(argv=None):
|
||||
parser = argparse.ArgumentParser(description="Ingest clrmamepro DAT files into SQLite")
|
||||
parser.add_argument("--dats", help="directory containing .dat files (default: data/dats)")
|
||||
|
||||
Reference in New Issue
Block a user