apply-patch.py 1.4 KB

1234567891011121314151617181920212223242526
  1. from pathlib import Path
  2. import hashlib
  3. import json
  4. import subprocess
  5. root = Path(__file__).resolve().parent
  6. target = Path('E:/pipe-ner-server').resolve()
  7. assert str(target).lower().replace('\\', '/') == 'e:/pipe-ner-server'
  8. manifest = json.loads((root / 'manifest.json').read_text(encoding='utf-8'))
  9. for entry in manifest:
  10. path = target / entry['path']
  11. digest = hashlib.sha256(path.read_bytes()).hexdigest() if path.exists() else None
  12. if digest != entry['beforeSha256']:
  13. raise SystemExit('Concurrent modification; patch not applied: ' + entry['path'])
  14. staged = root / entry['path']
  15. if hashlib.sha256(staged.read_bytes()).hexdigest() != entry['afterSha256']:
  16. raise SystemExit('Staged file changed; rebuild manifest: ' + entry['path'])
  17. patch = str(root / 'point-status-eight-buckets.patch')
  18. # Inherit stdio; no named-pipe output capture under Windows sandbox.
  19. subprocess.run(['git', 'apply', '--check', '--whitespace=error', patch], cwd=target, check=True)
  20. subprocess.run(['git', 'apply', '--whitespace=error', patch], cwd=target, check=True)
  21. for entry in manifest:
  22. final = (target / entry['path']).read_bytes().replace(b'\r\n', b'\n')
  23. expected = (root / entry['path']).read_bytes().replace(b'\r\n', b'\n')
  24. assert final == expected, entry['path']
  25. print('Applied and verified ' + str(len(manifest)) + ' backend files; no build/debug/test commands executed.')