mirror of
https://github.com/Abdess/retroarch_system.git
synced 2026-11-23 10:07:48 -06:00
refactor: share one timestamp key table
This commit is contained in:
1 parent
6df0ec503b
commit
3fa2f77722
4 files changed
+15
-28
No files matched your search
@@ -17,10 +17,13 @@ import re
|
||||
from core.paths import REPO_ROOT
|
||||
|
||||
|
||||
# JSON keys that hold the build clock: database.json (generated_at),
|
||||
# install/*.json manifests (generated), provenance snapshots (imported_at),
|
||||
# games/catalogs/ (fetched).
|
||||
TIMESTAMP_KEYS = frozenset({"generated_at", "generated", "imported_at", "fetched"})
|
||||
|
||||
_TIMESTAMP_PATTERNS = [
|
||||
re.compile(r'"generated_at":\s*"[^"]*"'), # database.json
|
||||
re.compile(r'"imported_at":\s*"[^"]*"'), # provenance snapshots
|
||||
re.compile(r'"fetched":\s*"[^"]*"'), # games/catalogs/
|
||||
*(re.compile(rf'"{key}":\s*"[^"]*"') for key in sorted(TIMESTAMP_KEYS)),
|
||||
re.compile(r"\*Auto-generated on [^*]*\*"), # README.md
|
||||
re.compile(r"\*Generated on [^*]*\*"), # docs site pages
|
||||
# The decorated pages carry the same stamp again as a rendered element,
|
||||
|
||||
@@ -51,7 +51,7 @@ from model.systems import (
|
||||
select_systems,
|
||||
)
|
||||
from core.artifacts import (
|
||||
write_text_atomic,
|
||||
write_if_changed,
|
||||
artifact_lock,
|
||||
repository_output_lock,
|
||||
ArtifactLockBusy,
|
||||
@@ -321,24 +321,6 @@ def _validate_args(args: argparse.Namespace, parser: argparse.ArgumentParser) ->
|
||||
parser.error(message)
|
||||
|
||||
|
||||
def _write_manifest_if_changed(path: str, manifest: dict) -> None:
|
||||
"""Write manifest JSON only if content (excluding timestamp) changed."""
|
||||
new_json = json.dumps(manifest, indent=2)
|
||||
if os.path.exists(path):
|
||||
with open(path) as f:
|
||||
try:
|
||||
old = json.load(f)
|
||||
except (json.JSONDecodeError, OSError):
|
||||
old = None
|
||||
if old is not None:
|
||||
# Compare everything except the generated timestamp
|
||||
old_cmp = {k: v for k, v in old.items() if k != "generated"}
|
||||
new_cmp = {k: v for k, v in manifest.items() if k != "generated"}
|
||||
if old_cmp == new_cmp:
|
||||
return # no content change, keep existing timestamp
|
||||
write_text_atomic(path, new_json)
|
||||
|
||||
|
||||
def _run_manifest_mode(
|
||||
args: argparse.Namespace,
|
||||
groups: list[tuple[list[str], str]],
|
||||
@@ -398,7 +380,7 @@ def _run_manifest_mode(
|
||||
args.output_dir,
|
||||
f"{representative}{narrow_suffix}.json",
|
||||
)
|
||||
_write_manifest_if_changed(out_path, manifest)
|
||||
write_if_changed(out_path, json.dumps(manifest, indent=2))
|
||||
print(
|
||||
f" {out_path}: {manifest['total_files']} files, "
|
||||
f"{manifest['total_size']} bytes, "
|
||||
@@ -437,7 +419,7 @@ def _run_manifest_mode(
|
||||
for name in _platform_cores(alias_cfg, emu_profiles)},
|
||||
manifest["files"],
|
||||
)
|
||||
_write_manifest_if_changed(alias_path, alias_manifest)
|
||||
write_if_changed(alias_path, json.dumps(alias_manifest, indent=2))
|
||||
print(f" {alias_path}: alias of {representative}")
|
||||
except (FileNotFoundError, OSError, yaml.YAMLError) as e:
|
||||
print(f" ERROR: {e}", file=sys.stderr)
|
||||
@@ -1442,9 +1424,9 @@ def _write_standalone_layouts(output_dir: str, platform: str, layouts: dict) ->
|
||||
list. Its [dest, sha1] items take their download from that list."""
|
||||
path = os.path.join(output_dir, STANDALONE_DIR, f"{platform}.json")
|
||||
os.makedirs(os.path.dirname(path), exist_ok=True)
|
||||
_write_manifest_if_changed(path, {
|
||||
write_if_changed(path, json.dumps({
|
||||
"schema": 1, "platform": platform, "standalone_layouts": layouts,
|
||||
})
|
||||
}, indent=2))
|
||||
return path
|
||||
|
||||
|
||||
|
||||
@@ -17,6 +17,7 @@ from collections.abc import Callable, Sequence
|
||||
from dataclasses import dataclass, field
|
||||
from pathlib import Path
|
||||
|
||||
from core.artifacts import TIMESTAMP_KEYS
|
||||
from core.hostguard import LockBusy, free_gb, global_lock, lock_busy
|
||||
from core.statefile import now_iso, save_state
|
||||
from unattended.breaker import may_push, refresh_breaker
|
||||
@@ -40,7 +41,6 @@ ALERT_FREE_GB = 100
|
||||
LOG_DAYS = 30
|
||||
SEGFAULT_CODES = (139, -11)
|
||||
HOST_MISREAD_MARKERS = ("SystemError", "unknown opcode")
|
||||
VOLATILE_KEYS = frozenset({"generated_at", "generated", "imported_at"})
|
||||
|
||||
|
||||
@dataclass
|
||||
@@ -181,7 +181,7 @@ def run_with_retry(
|
||||
|
||||
def strip_volatile(value: object) -> object:
|
||||
if isinstance(value, dict):
|
||||
return {k: strip_volatile(v) for k, v in value.items() if k not in VOLATILE_KEYS}
|
||||
return {k: strip_volatile(v) for k, v in value.items() if k not in TIMESTAMP_KEYS}
|
||||
if isinstance(value, list):
|
||||
return [strip_volatile(v) for v in value]
|
||||
return value
|
||||
|
||||
@@ -2931,6 +2931,8 @@ class FreshnessGuardMechanics(unittest.TestCase):
|
||||
forms = [
|
||||
'{{"generated_at": "{}"}}',
|
||||
'{{"imported_at": "{}"}}',
|
||||
'{{"generated": "{}"}}',
|
||||
'{{"fetched": "{}"}}',
|
||||
"*Auto-generated on {}*",
|
||||
"*Generated on {}*",
|
||||
'<div class="rb-timestamp">Generated on {}.</div>',
|
||||
|
||||
Reference in new issue
Block a user