gen_timezones.py 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. """Regenerate modules/twingate-bootstrap/timezones.txt from the local tz database.
  2. The bootstrap module accepts only names in that file, so a typo such as
  3. Foo/Bar fails at plan time instead of leaving the machine on UTC. The list
  4. comes from `zoneinfo.available_timezones()`, which depends on the tz database
  5. of the machine that runs this script, and zones are added or renamed over
  6. time. Regenerate it now and then and review the diff; tests check the shape of
  7. the file, not equality with whatever database a CI runner has.
  8. Usage: python -I scripts/gen_timezones.py [--root ROOT]
  9. """
  10. from __future__ import annotations
  11. import argparse
  12. import zoneinfo
  13. from pathlib import Path
  14. TARGET = Path("modules/twingate-bootstrap/timezones.txt")
  15. def main() -> int:
  16. parser = argparse.ArgumentParser(description=__doc__.splitlines()[0])
  17. parser.add_argument("--root", default=".")
  18. args = parser.parse_args()
  19. names = sorted(zoneinfo.available_timezones())
  20. if "UTC" not in names or "America/New_York" not in names:
  21. raise SystemExit("gen_timezones: the local tz database looks incomplete")
  22. path = Path(args.root) / TARGET
  23. path.write_text("\n".join(names) + "\n", encoding="utf-8")
  24. print(f"gen_timezones: wrote {len(names)} zones to {path}")
  25. return 0
  26. if __name__ == "__main__":
  27. raise SystemExit(main())