annotate 0.9.x/scripts/dump_data.py @ 557:3c590f6f5dfa stable tip

Merged revisions 607 via svnmerge from http://svn.edgewall.org/repos/babel/trunk ........ r607 | pjenvey | 2011-04-24 21:41:23 -0700 (Sun, 24 Apr 2011) | 3 lines keywords only support space separated values, not comma separated thanks agronholm ........
author pjenvey
date Mon, 25 Apr 2011 04:44:13 +0000
parents e69a068990f0
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
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
15 from optparse import OptionParser
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
16 from pprint import pprint
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
17 import sys
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
18
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
19 from babel.localedata import load, LocaleDataDict
263
5b7d3f9f7d74 Create branch for 0.9.x maintenance.
cmlenz
parents:
diff changeset
20
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
21
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
22 def main():
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
23 parser = OptionParser(usage='%prog [options] locale [path]')
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
24 parser.add_option('--noinherit', action='store_false', dest='inherit',
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
25 help='do not merge inherited data into locale data')
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
26 parser.add_option('--resolve', action='store_true', dest='resolve',
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
27 help='resolve aliases in locale data')
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
28 parser.set_defaults(inherit=True, resolve=False)
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
29 options, args = parser.parse_args()
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
30 if len(args) not in (1, 2):
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
31 parser.error('incorrect number of arguments')
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
32
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
33 data = load(args[0], merge_inherited=options.inherit)
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
34 if options.resolve:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
35 data = LocaleDataDict(data)
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
36 if len(args) > 1:
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
37 for key in args[1].split('.'):
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
38 data = data[key]
391
e69a068990f0 Ported [424], [425], and [428] back to 0.9.x branch.
cmlenz
parents: 381
diff changeset
39 if isinstance(data, dict):
e69a068990f0 Ported [424], [425], and [428] back to 0.9.x branch.
cmlenz
parents: 381
diff changeset
40 data = dict(data.items())
e69a068990f0 Ported [424], [425], and [428] back to 0.9.x branch.
cmlenz
parents: 381
diff changeset
41 pprint(data)
381
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
42
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
43
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
44 if __name__ == '__main__':
6a0e7205790f Ported [407:415/trunk] back to 0.9.x branch.
cmlenz
parents: 263
diff changeset
45 main()
Copyright (C) 2012-2017 Edgewall Software