changelog
[platform/upstream/freerdp.git] / scripts / update-windows-zones.py
1 #!/usr/bin/env python3
2
3 import os
4 import urllib.request
5 import xml.etree.ElementTree as ET
6
7 name = os.path.realpath(__file__)
8 base = os.path.normpath(os.path.join(os.path.dirname(name), '..'))
9 rname = os.path.relpath(name, base)
10 zfile = os.path.join(base, 'winpr/libwinpr/timezone/WindowsZones.c')
11 url = 'https://raw.githubusercontent.com/unicode-org/cldr/latest/common/supplemental/windowsZones.xml'
12
13 try:
14     with urllib.request.urlopen(url) as response:
15         xml = response.read()
16         root = ET.fromstring(xml)
17         entries = []
18         for child in root.iter('mapZone'):
19             tzid = child.get('type')
20             windows = child.get('other')
21             entries += ['\t{ "' + windows + '", "' + tzid + '" },\n']
22         entries.sort()
23
24         with open(zfile, 'w') as f:
25             f.write('/*\n')
26             f.write(' * Automatically generated with ' + str(rname) + '\n')
27             f.write(' */\n')
28             f.write('\n')
29             f.write('#include "WindowsZones.h"\n')
30             f.write('\n')
31             f.write('const WINDOWS_TZID_ENTRY WindowsTimeZoneIdTable[] =\n')
32             f.write('{\n')
33             for entry in entries:
34                 f.write(entry)
35             f.write('};\n')
36             f.write('\n');
37             f.write('const size_t WindowsTimeZoneIdTableNrElements = ARRAYSIZE(WindowsTimeZoneIdTable);\n')
38 except Exception as e:
39     print('----------------------------------------------------')
40     print(str(e))
41     print('----------------------------------------------------')