Files

26 lines
1.8 KiB
Python

import pathlib,subprocess,datetime,shutil,time,urllib.request,hashlib,json
base=pathlib.Path('/www/dk_project/dk_app/trilium');release=pathlib.Path('/tmp/trilium-korean-phase6')
manifest=json.loads((release/'manifest.json').read_text());digest=lambda b:hashlib.sha256(b).hexdigest()
targets={'main.cjs':'patched/main.cjs','translation.json':'i18n_ko/translation.json'}
assert digest((base/targets['main.cjs']).read_bytes())==manifest['previousMainSha256']
assert digest((base/targets['translation.json']).read_bytes())==manifest['previousTranslationSha256']
for rel,expected in manifest['files'].items():assert digest((release/rel).read_bytes())==expected
backup=base/'backups'/('before-korean-phase6-'+datetime.datetime.now().strftime('%Y%m%d-%H%M%S'));backup.mkdir(parents=True,mode=0o700)
for name,rel in targets.items():shutil.copy2(base/rel,backup/name)
try:
for name,rel in targets.items():(base/rel).write_bytes((release/name).read_bytes())
subprocess.run(['docker','restart','trilium'],check=True)
for attempt in range(40):
try:
with urllib.request.urlopen('http://127.0.0.1:18082/api/health-check',timeout=2) as response:assert response.status==200
with urllib.request.urlopen('http://127.0.0.1:18082/assets/v0.95.0-ko-20260913-r5/translations/ko/translation.json',timeout=3) as response:assert digest(response.read())==manifest['files']['translation.json']
break
except Exception:
if attempt==39:raise
time.sleep(1)
result={'status':'verified','backup':str(backup),'assetVersion':'v0.95.0-ko-20260913-r5','translationSha256':manifest['files']['translation.json']}
(base/'i18n_ko/phase6-result.json').write_text(json.dumps(result,indent=2));print(json.dumps(result))
except Exception:
for name,rel in targets.items():(base/rel).write_bytes((backup/name).read_bytes())
subprocess.run(['docker','restart','trilium'],check=True);raise