annotate 0.9.x/scripts/import_cldr.py @ 512:f29b2dadd9fc stable

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