annotate 0.9.x/scripts/import_cldr.py @ 381:6a0e7205790f stable

Ported [407:415/trunk] back to 0.9.x branch.
author cmlenz
date Tue, 08 Jul 2008 21:01:28 +0000
parents 05975a0e7021
children e69a068990f0
rev   line source
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
1 #!/usr/bin/env python
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
2 # -*- coding: utf-8 -*-
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
3 #
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
4 # Copyright (C) 2007 Edgewall Software
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
5 # All rights reserved.
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
6 #
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
7 # This software is licensed as described in the file COPYING, which
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
8 # you should have received as part of this distribution. The terms
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
9 # are also available at http://babel.edgewall.org/wiki/License.
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
10 #
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
11 # This software consists of voluntary contributions made by many
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
12 # individuals. For the exact contribution history, see the revision
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
13 # history and logs, available at http://babel.edgewall.org/log/.
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
14
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
15 import copy
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
16 from optparse import OptionParser
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
17 import os
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
18 import pickle
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
19 import re
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
20 import sys
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
21 try:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
22 from xml.etree.ElementTree import parse
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
23 except ImportError:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
24 from elementtree.ElementTree import parse
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
25
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
26 # Make sure we're using Babel source, and not some previously installed version
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
27 sys.path.insert(0, os.path.join(os.path.dirname(sys.argv[0]), '..'))
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
28
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
29 from babel import dates, numbers
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
30 from babel.localedata import Alias
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
31
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
32 weekdays = {'mon': 0, 'tue': 1, 'wed': 2, 'thu': 3, 'fri': 4, 'sat': 5,
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
33 'sun': 6}
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
34
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
35 try:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
36 any
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
37 except NameError:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
38 def any(iterable):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
39 return filter(None, list(iterable))
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
40
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
41
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
42 def _text(elem):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
43 buf = [elem.text or '']
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
44 for child in elem:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
45 buf.append(_text(child))
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
46 buf.append(elem.tail or '')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
47 return u''.join(filter(None, buf)).strip()
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
48
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
49
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
50 NAME_RE = re.compile(r"^\w+$")
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
51 TYPE_ATTR_RE = re.compile(r"^\w+\[@type='(.*?)'\]$")
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
52
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
53 NAME_MAP = {
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
54 'dateFormats': 'date_formats',
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
55 'dateTimeFormats': 'datetime_formats',
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
56 'eraAbbr': 'abbreviated',
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
57 'eraNames': 'wide',
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
58 'eraNarrow': 'narrow',
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
59 'timeFormats': 'time_formats'
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
60 }
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
61
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
62 def _translate_alias(ctxt, path):
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
63 parts = path.split('/')
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
64 keys = ctxt[:]
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
65 for part in parts:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
66 if part == '..':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
67 keys.pop()
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
68 else:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
69 match = TYPE_ATTR_RE.match(part)
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
70 if match:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
71 keys.append(match.group(1))
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
72 else:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
73 assert NAME_RE.match(part)
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
74 keys.append(NAME_MAP.get(part, part))
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
75 return keys
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
76
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
77
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
78 def main():
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
79 parser = OptionParser(usage='%prog path/to/cldr')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
80 options, args = parser.parse_args()
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
81 if len(args) != 1:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
82 parser.error('incorrect number of arguments')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
83
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
84 srcdir = args[0]
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
85 destdir = os.path.join(os.path.dirname(os.path.abspath(sys.argv[0])),
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
86 '..', 'babel')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
87
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
88 sup = parse(os.path.join(srcdir, 'supplemental', 'supplementalData.xml'))
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
89
348
05975a0e7021 Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents: 263
diff changeset
90 # Import global data from the supplemental files
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
91 global_data = {}
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
92
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
93 territory_zones = global_data.setdefault('territory_zones', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
94 zone_aliases = global_data.setdefault('zone_aliases', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
95 zone_territories = global_data.setdefault('zone_territories', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
96 for elem in sup.findall('//timezoneData/zoneFormatting/zoneItem'):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
97 tzid = elem.attrib['type']
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
98 territory_zones.setdefault(elem.attrib['territory'], []).append(tzid)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
99 zone_territories[tzid] = elem.attrib['territory']
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
100 if 'aliases' in elem.attrib:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
101 for alias in elem.attrib['aliases'].split():
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
102 zone_aliases[alias] = tzid
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
103
348
05975a0e7021 Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents: 263
diff changeset
104 # Import Metazone mapping
05975a0e7021 Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents: 263
diff changeset
105 meta_zones = global_data.setdefault('meta_zones', {})
05975a0e7021 Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents: 263
diff changeset
106 tzsup = parse(os.path.join(srcdir, 'supplemental', 'metazoneInfo.xml'))
05975a0e7021 Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents: 263
diff changeset
107 for elem in tzsup.findall('//timezone'):
05975a0e7021 Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents: 263
diff changeset
108 for child in elem.findall('usesMetazone'):
05975a0e7021 Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents: 263
diff changeset
109 if 'to' not in child.attrib: # FIXME: support old mappings
05975a0e7021 Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents: 263
diff changeset
110 meta_zones[elem.attrib['type']] = child.attrib['mzone']
05975a0e7021 Merged revisions [358:360], [364:370], [373:378], [380:382] from [source:trunk].
cmlenz
parents: 263
diff changeset
111
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
112 outfile = open(os.path.join(destdir, 'global.dat'), 'wb')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
113 try:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
114 pickle.dump(global_data, outfile, 2)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
115 finally:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
116 outfile.close()
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
117
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
118 # build a territory containment mapping for inheritance
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
119 regions = {}
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
120 for elem in sup.findall('//territoryContainment/group'):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
121 regions[elem.attrib['type']] = elem.attrib['contains'].split()
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
122
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
123 # Resolve territory containment
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
124 territory_containment = {}
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
125 region_items = regions.items()
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
126 region_items.sort()
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
127 for group, territory_list in region_items:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
128 for territory in territory_list:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
129 containers = territory_containment.setdefault(territory, set([]))
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
130 if group in territory_containment:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
131 containers |= territory_containment[group]
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
132 containers.add(group)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
133
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
134 filenames = os.listdir(os.path.join(srcdir, 'main'))
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
135 filenames.remove('root.xml')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
136 filenames.sort(lambda a,b: len(a)-len(b))
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
137 filenames.insert(0, 'root.xml')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
138
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
139 for filename in filenames:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
140 print>>sys.stderr, 'Processing input file %r' % filename
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
141 stem, ext = os.path.splitext(filename)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
142 if ext != '.xml':
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
143 continue
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
144 #if stem != 'root':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
145 # break
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
146
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
147 tree = parse(os.path.join(srcdir, 'main', filename))
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
148 data = {}
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
149
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
150 language = None
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
151 elem = tree.find('//identity/language')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
152 if elem is not None:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
153 language = elem.attrib['type']
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
154 print>>sys.stderr, ' Language: %r' % language
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
155
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
156 territory = None
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
157 elem = tree.find('//identity/territory')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
158 if elem is not None:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
159 territory = elem.attrib['type']
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
160 else:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
161 territory = '001' # world
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
162 print>>sys.stderr, ' Territory: %r' % territory
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
163 regions = territory_containment.get(territory, [])
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
164 print>>sys.stderr, ' Regions: %r' % regions
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
165
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
166 # <localeDisplayNames>
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
167
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
168 territories = data.setdefault('territories', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
169 for elem in tree.findall('//territories/territory'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
170 if ('draft' in elem.attrib or 'alt' in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
171 and elem.attrib['type'] in territories:
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
172 continue
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
173 territories[elem.attrib['type']] = _text(elem)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
174
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
175 languages = data.setdefault('languages', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
176 for elem in tree.findall('//languages/language'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
177 if ('draft' in elem.attrib or 'alt' in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
178 and elem.attrib['type'] in languages:
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
179 continue
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
180 languages[elem.attrib['type']] = _text(elem)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
181
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
182 variants = data.setdefault('variants', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
183 for elem in tree.findall('//variants/variant'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
184 if ('draft' in elem.attrib or 'alt' in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
185 and elem.attrib['type'] in variants:
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
186 continue
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
187 variants[elem.attrib['type']] = _text(elem)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
188
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
189 scripts = data.setdefault('scripts', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
190 for elem in tree.findall('//scripts/script'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
191 if ('draft' in elem.attrib or 'alt' in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
192 and elem.attrib['type'] in scripts:
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
193 continue
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
194 scripts[elem.attrib['type']] = _text(elem)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
195
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
196 # <dates>
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
197
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
198 week_data = data.setdefault('week_data', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
199 supelem = sup.find('//weekData')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
200
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
201 for elem in supelem.findall('minDays'):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
202 territories = elem.attrib['territories'].split()
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
203 if territory in territories or any([r in territories for r in regions]):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
204 week_data['min_days'] = int(elem.attrib['count'])
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
205
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
206 for elem in supelem.findall('firstDay'):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
207 territories = elem.attrib['territories'].split()
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
208 if territory in territories or any([r in territories for r in regions]):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
209 week_data['first_day'] = weekdays[elem.attrib['day']]
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
210
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
211 for elem in supelem.findall('weekendStart'):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
212 territories = elem.attrib['territories'].split()
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
213 if territory in territories or any([r in territories for r in regions]):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
214 week_data['weekend_start'] = weekdays[elem.attrib['day']]
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
215
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
216 for elem in supelem.findall('weekendEnd'):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
217 territories = elem.attrib['territories'].split()
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
218 if territory in territories or any([r in territories for r in regions]):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
219 week_data['weekend_end'] = weekdays[elem.attrib['day']]
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
220
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
221 zone_formats = data.setdefault('zone_formats', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
222 for elem in tree.findall('//timeZoneNames/gmtFormat'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
223 if 'draft' not in elem.attrib and 'alt' not in elem.attrib:
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
224 zone_formats['gmt'] = unicode(elem.text).replace('{0}', '%s')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
225 break
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
226 for elem in tree.findall('//timeZoneNames/regionFormat'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
227 if 'draft' not in elem.attrib and 'alt' not in elem.attrib:
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
228 zone_formats['region'] = unicode(elem.text).replace('{0}', '%s')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
229 break
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
230 for elem in tree.findall('//timeZoneNames/fallbackFormat'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
231 if 'draft' not in elem.attrib and 'alt' not in elem.attrib:
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
232 zone_formats['fallback'] = unicode(elem.text) \
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
233 .replace('{0}', '%(0)s').replace('{1}', '%(1)s')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
234 break
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
235
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
236 time_zones = data.setdefault('time_zones', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
237 for elem in tree.findall('//timeZoneNames/zone'):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
238 info = {}
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
239 city = elem.findtext('exemplarCity')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
240 if city:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
241 info['city'] = unicode(city)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
242 for child in elem.findall('long/*'):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
243 info.setdefault('long', {})[child.tag] = unicode(child.text)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
244 for child in elem.findall('short/*'):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
245 info.setdefault('short', {})[child.tag] = unicode(child.text)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
246 time_zones[elem.attrib['type']] = info
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
247
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
248 meta_zones = data.setdefault('meta_zones', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
249 for elem in tree.findall('//timeZoneNames/metazone'):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
250 info = {}
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
251 city = elem.findtext('exemplarCity')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
252 if city:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
253 info['city'] = unicode(city)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
254 for child in elem.findall('long/*'):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
255 info.setdefault('long', {})[child.tag] = unicode(child.text)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
256 for child in elem.findall('short/*'):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
257 info.setdefault('short', {})[child.tag] = unicode(child.text)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
258 info['common'] = elem.findtext('commonlyUsed') == 'true'
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
259 meta_zones[elem.attrib['type']] = info
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
260
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
261 for calendar in tree.findall('//calendars/calendar'):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
262 if calendar.attrib['type'] != 'gregorian':
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
263 # TODO: support other calendar types
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
264 continue
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
265
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
266 months = data.setdefault('months', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
267 for ctxt in calendar.findall('months/monthContext'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
268 ctxt_type = ctxt.attrib['type']
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
269 ctxts = months.setdefault(ctxt_type, {})
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
270 for width in ctxt.findall('monthWidth'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
271 width_type = width.attrib['type']
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
272 widths = ctxts.setdefault(width_type, {})
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
273 for elem in width.getiterator():
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
274 if elem.tag == 'month':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
275 if ('draft' in elem.attrib or 'alt' in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
276 and int(elem.attrib['type']) in widths:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
277 continue
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
278 widths[int(elem.attrib.get('type'))] = unicode(elem.text)
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
279 elif elem.tag == 'alias':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
280 ctxts[width_type] = Alias(
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
281 _translate_alias(['months', ctxt_type, width_type],
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
282 elem.attrib['path'])
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
283 )
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
284
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
285 days = data.setdefault('days', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
286 for ctxt in calendar.findall('days/dayContext'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
287 ctxt_type = ctxt.attrib['type']
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
288 ctxts = days.setdefault(ctxt_type, {})
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
289 for width in ctxt.findall('dayWidth'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
290 width_type = width.attrib['type']
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
291 widths = ctxts.setdefault(width_type, {})
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
292 for elem in width.getiterator():
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
293 if elem.tag == 'day':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
294 dtype = weekdays[elem.attrib['type']]
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
295 if ('draft' in elem.attrib or 'alt' not in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
296 and dtype in widths:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
297 continue
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
298 widths[dtype] = unicode(elem.text)
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
299 elif elem.tag == 'alias':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
300 ctxts[width_type] = Alias(
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
301 _translate_alias(['days', ctxt_type, width_type],
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
302 elem.attrib['path'])
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
303 )
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
304
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
305 quarters = data.setdefault('quarters', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
306 for ctxt in calendar.findall('quarters/quarterContext'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
307 ctxt_type = ctxt.attrib['type']
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
308 ctxts = quarters.setdefault(ctxt.attrib['type'], {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
309 for width in ctxt.findall('quarterWidth'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
310 width_type = width.attrib['type']
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
311 widths = ctxts.setdefault(width_type, {})
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
312 for elem in width.getiterator():
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
313 if elem.tag == 'quarter':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
314 if ('draft' in elem.attrib or 'alt' in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
315 and int(elem.attrib['type']) in widths:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
316 continue
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
317 widths[int(elem.attrib['type'])] = unicode(elem.text)
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
318 elif elem.tag == 'alias':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
319 ctxts[width_type] = Alias(
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
320 _translate_alias(['quarters', ctxt_type, width_type],
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
321 elem.attrib['path'])
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
322 )
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
323
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
324 eras = data.setdefault('eras', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
325 for width in calendar.findall('eras/*'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
326 width_type = NAME_MAP[width.tag]
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
327 widths = eras.setdefault(width_type, {})
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
328 for elem in width.getiterator():
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
329 if elem.tag == 'era':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
330 if ('draft' in elem.attrib or 'alt' in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
331 and int(elem.attrib['type']) in widths:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
332 continue
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
333 widths[int(elem.attrib.get('type'))] = unicode(elem.text)
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
334 elif elem.tag == 'alias':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
335 eras[width_type] = Alias(
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
336 _translate_alias(['eras', width_type],
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
337 elem.attrib['path'])
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
338 )
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
339
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
340 # AM/PM
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
341 periods = data.setdefault('periods', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
342 for elem in calendar.findall('am'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
343 if ('draft' in elem.attrib or 'alt' in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
344 and elem.tag in periods:
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
345 continue
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
346 periods[elem.tag] = unicode(elem.text)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
347 for elem in calendar.findall('pm'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
348 if ('draft' in elem.attrib or 'alt' in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
349 and elem.tag in periods:
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
350 continue
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
351 periods[elem.tag] = unicode(elem.text)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
352
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
353 date_formats = data.setdefault('date_formats', {})
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
354 for format in calendar.findall('dateFormats'):
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
355 for elem in format.getiterator():
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
356 if elem.tag == 'dateFormatLength':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
357 if 'draft' in elem.attrib and \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
358 elem.attrib.get('type') in date_formats:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
359 continue
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
360 try:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
361 date_formats[elem.attrib.get('type')] = \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
362 dates.parse_pattern(unicode(elem.findtext('dateFormat/pattern')))
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
363 except ValueError, e:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
364 print>>sys.stderr, 'ERROR: %s' % e
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
365 elif elem.tag == 'alias':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
366 date_formats = Alias(_translate_alias(
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
367 ['date_formats'], elem.attrib['path'])
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
368 )
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
369
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
370 time_formats = data.setdefault('time_formats', {})
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
371 for format in calendar.findall('timeFormats'):
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
372 for elem in format.getiterator():
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
373 if elem.tag == 'timeFormatLength':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
374 if ('draft' in elem.attrib or 'alt' in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
375 and elem.attrib.get('type') in time_formats:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
376 continue
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
377 try:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
378 time_formats[elem.attrib.get('type')] = \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
379 dates.parse_pattern(unicode(elem.findtext('timeFormat/pattern')))
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
380 except ValueError, e:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
381 print>>sys.stderr, 'ERROR: %s' % e
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
382 elif elem.tag == 'alias':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
383 time_formats = Alias(_translate_alias(
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
384 ['time_formats'], elem.attrib['path'])
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
385 )
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
386
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
387 datetime_formats = data.setdefault('datetime_formats', {})
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
388 for format in calendar.findall('dateTimeFormats'):
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
389 for elem in format.getiterator():
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
390 if elem.tag == 'dateTimeFormatLength':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
391 if ('draft' in elem.attrib or 'alt' in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
392 and elem.attrib.get('type') in datetime_formats:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
393 continue
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
394 try:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
395 datetime_formats[elem.attrib.get('type')] = \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
396 unicode(elem.findtext('dateTimeFormat/pattern'))
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
397 except ValueError, e:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
398 print>>sys.stderr, 'ERROR: %s' % e
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
399 elif elem.tag == 'alias':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
400 datetime_formats = Alias(_translate_alias(
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
401 ['datetime_formats'], elem.attrib['path'])
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
402 )
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
403
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
404 # <numbers>
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
405
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
406 number_symbols = data.setdefault('number_symbols', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
407 for elem in tree.findall('//numbers/symbols/*'):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
408 number_symbols[elem.tag] = unicode(elem.text)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
409
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
410 decimal_formats = data.setdefault('decimal_formats', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
411 for elem in tree.findall('//decimalFormats/decimalFormatLength'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
412 if ('draft' in elem.attrib or 'alt' in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
413 and elem.attrib.get('type') in decimal_formats:
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
414 continue
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
415 pattern = unicode(elem.findtext('decimalFormat/pattern'))
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
416 decimal_formats[elem.attrib.get('type')] = numbers.parse_pattern(pattern)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
417
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
418 scientific_formats = data.setdefault('scientific_formats', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
419 for elem in tree.findall('//scientificFormats/scientificFormatLength'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
420 if ('draft' in elem.attrib or 'alt' in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
421 and elem.attrib.get('type') in scientific_formats:
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
422 continue
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
423 pattern = unicode(elem.findtext('scientificFormat/pattern'))
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
424 scientific_formats[elem.attrib.get('type')] = numbers.parse_pattern(pattern)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
425
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
426 currency_formats = data.setdefault('currency_formats', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
427 for elem in tree.findall('//currencyFormats/currencyFormatLength'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
428 if ('draft' in elem.attrib or 'alt' in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
429 and elem.attrib.get('type') in currency_formats:
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
430 continue
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
431 pattern = unicode(elem.findtext('currencyFormat/pattern'))
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
432 currency_formats[elem.attrib.get('type')] = numbers.parse_pattern(pattern)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
433
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
434 percent_formats = data.setdefault('percent_formats', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
435 for elem in tree.findall('//percentFormats/percentFormatLength'):
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
436 if ('draft' in elem.attrib or 'alt' in elem.attrib) \
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
437 and elem.attrib.get('type') in percent_formats:
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
438 continue
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
439 pattern = unicode(elem.findtext('percentFormat/pattern'))
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
440 percent_formats[elem.attrib.get('type')] = numbers.parse_pattern(pattern)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
441
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
442 currency_names = data.setdefault('currency_names', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
443 currency_symbols = data.setdefault('currency_symbols', {})
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
444 for elem in tree.findall('//currencies/currency'):
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
445 name = elem.findtext('displayName')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
446 if name:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
447 currency_names[elem.attrib['type']] = unicode(name)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
448 symbol = elem.findtext('symbol')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
449 if symbol:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
450 currency_symbols[elem.attrib['type']] = unicode(symbol)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
451
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
452 outfile = open(os.path.join(destdir, 'localedata', stem + '.dat'), 'wb')
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
453 try:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
454 pickle.dump(data, outfile, 2)
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
455 finally:
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
456 outfile.close()
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
457
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 348
diff changeset
458
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
459 if __name__ == '__main__':
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
460 main()
Copyright (C) 2012-2017 Edgewall Software