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