extract_proxy.py 707 B

123456789101112131415161718192021222324
  1. #!/usr/bin/env python3
  2. """
  3. extract_proxy.py
  4. Run this to write the embedded remote proxy to a standalone file
  5. `tools/must_pv1800_proxy.py`. The main script uploads this proxy over
  6. SFTP and runs it on the remote host.
  7. Usage:
  8. python3 tools/extract_proxy.py
  9. """
  10. import pathlib
  11. import re
  12. src = pathlib.Path(__file__).parent.parent / "must_pv1800_monitor.py"
  13. text = src.read_text()
  14. m = re.search(r"_REMOTE_PROXY_SCRIPT = r'''(.*?)'''", text, re.DOTALL)
  15. if not m:
  16. raise SystemExit("could not find _REMOTE_PROXY_SCRIPT in must_pv1800_monitor.py")
  17. out = pathlib.Path(__file__).parent / "must_pv1800_proxy.py"
  18. out.write_text(m.group(1))
  19. out.chmod(0o755)
  20. print(f"wrote {out} ({out.stat().st_size} bytes)")