update.py 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. #!/usr/bin/env python
  2. # -*- coding: utf-8 -*-
  3. import re
  4. def main():
  5. REGEXP = """^("(.+)",|"",//(.+))$"""
  6. OUTPUT = "../udf_tz.gen"
  7. INPUT = OUTPUT
  8. CONTRIB_ZONES = "../../../../../../../contrib/libs/cctz/tzdata/ya.make.resources"
  9. RES_PREFIX = "/cctz/tzdata/"
  10. print("process %s into %s" % (INPUT, OUTPUT))
  11. with open(INPUT, "r") as inp:
  12. lines = inp.readlines()
  13. zones = []
  14. for line in lines:
  15. m = re.match(REGEXP, line)
  16. if not m:
  17. raise ValueError("invalid line: %s", line)
  18. zones.append(m.group(2) or m.group(3))
  19. szones = set()
  20. print("loaded %s zones" % len(zones))
  21. for zone in zones:
  22. if zone in szones:
  23. raise ValueError("duplicated zone: %s", zone)
  24. szones.add(zone)
  25. scontrib = set()
  26. with open(CONTRIB_ZONES, "r") as contrib:
  27. for line in contrib.readlines():
  28. if RES_PREFIX not in line:
  29. continue
  30. zone = line[line.index(RES_PREFIX) + len(RES_PREFIX):].strip()
  31. if zone in scontrib:
  32. raise ValueError("duplicated zone: %s", zone)
  33. scontrib.add(zone)
  34. if zone in szones:
  35. continue
  36. szones.add(zone)
  37. zones.append(zone)
  38. lines = []
  39. for zone in zones:
  40. if zone in scontrib:
  41. lines.append('"%s",\n' % zone)
  42. else:
  43. lines.append('"",//%s\n' % zone)
  44. with open(OUTPUT, "w") as outp:
  45. outp.writelines(lines)
  46. print("saved %s zones" % len(zones))
  47. if __name__ == "__main__":
  48. main()