File size: 1,774 Bytes
a023253 b3bd59d a023253 | 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 | #!/usr/bin/env python3
"""Restore the pinned SPC Git checkout when Molab supplies only a source snapshot."""
from pathlib import Path
import hashlib
import subprocess
ROOT = Path('/marimo/SPC')
STAGING = Path('/marimo/SPC_official_restore')
BACKUP = Path('/marimo/SPC_snapshot_backup_20261025')
COMMIT = '96834b22d5e59c852e53d713d434cbabb2f0d165'
def revision(path):
result = subprocess.run(['git', '-C', str(path), 'rev-parse', 'HEAD'], capture_output=True, text=True)
return result.stdout.strip() if result.returncode == 0 else None
if revision(ROOT) == COMMIT:
print('SPC_SOURCE_READY', COMMIT, flush=True)
else:
if (ROOT / '.git').exists():
raise RuntimeError('Existing SPC Git checkout has a different revision; refusing to replace it')
if not STAGING.exists():
subprocess.run(['git', 'clone', '--quiet', 'https://github.com/thanhhai1988/SPC.git', str(STAGING)], check=True)
subprocess.run(['git', '-C', str(STAGING), 'checkout', '--quiet', COMMIT], check=True)
if ROOT.exists():
for relative in ('data_train.py', 'util_data.py'):
existing, canonical = ROOT / relative, STAGING / relative
if not existing.exists() or hashlib.sha256(existing.read_bytes()).digest() != hashlib.sha256(canonical.read_bytes()).digest():
raise RuntimeError(f'Existing SPC snapshot differs at {relative}; refusing automatic replacement')
backup = BACKUP
suffix = 1
while backup.exists():
backup = BACKUP.with_name(f'{BACKUP.name}_{suffix}')
suffix += 1
ROOT.rename(backup)
print('SPC_SNAPSHOT_BACKUP', backup, flush=True)
STAGING.rename(ROOT)
assert revision(ROOT) == COMMIT
print('SPC_SOURCE_READY', COMMIT, flush=True)
|