Permalink
Browse files

Use u() in generated geo metadata

  • Loading branch information...
1 parent 9246f92 commit b4cb1e92465cc8a1d52abdcc9bf8ea23f237de3f @daviddrysdale committed Nov 27, 2011
Showing with 12 additions and 11 deletions.
  1. +8 −7 python/buildgeocodingdata.py
  2. +4 −4 python/makefile
@@ -2,7 +2,7 @@
"""Script to read the libphonenumber geocoding metadata and generate Python code.
Invocation:
- buildgeocodingdata.py indir outfile
+ buildgeocodingdata.py indir outfile module_prefix
Processes all of the geocoding data under the given input directory and emit
generated Python code.
@@ -30,7 +30,7 @@
import re
import datetime
-from phonenumbers.util import prnt
+from phonenumbers.util import prnt, rpr
GEODATA_SUFFIX = ".txt"
BLANK_LINE_RE = re.compile(r'^\s*$', re.UNICODE)
@@ -42,6 +42,7 @@
Auto-generated file, do not edit by hand.
"""
+from %(module)s.util import u
'''
# Copyright notice covering the XML metadata; include current year.
@@ -115,15 +116,15 @@ def _stable_dict_repr(strdict):
"""Return a repr() for a dict keyed by a string, in sorted key order"""
lines = []
for key in sorted(strdict.keys()):
- lines.append("%r: %r" % (key, strdict[key]))
+ lines.append("%s: %s" % (rpr(key), rpr(strdict[key])))
return "{%s}" % ", ".join(lines)
-def output_geodata_code(geodata, outfilename):
+def output_geodata_code(geodata, outfilename, module_prefix):
"""Output the geocoding data in Python form to the given file """
with open(outfilename, "w") as outfile:
longest_prefix = 0
- prnt(GEODATA_FILE_PROLOG, file=outfile)
+ prnt(GEODATA_FILE_PROLOG % {'module': module_prefix}, file=outfile)
prnt(COPYRIGHT_NOTICE, file=outfile)
prnt("GEOCODE_DATA = {", file=outfile)
for prefix in sorted(geodata.keys()):
@@ -136,11 +137,11 @@ def output_geodata_code(geodata, outfilename):
def _standalone(argv):
"""Parse the given input directory and emit generated code."""
- if len(argv) != 2:
+ if len(argv) != 3:
print >> sys.stderr, __doc__
sys.exit(1)
geodata = load_geodata(argv[0])
- output_geodata_code(geodata, argv[1])
+ output_geodata_code(geodata, argv[1], argv[2])
if __name__ == "__main__":
View
@@ -12,21 +12,21 @@ phonenumbers/geodata/locale.py: DumpLocale.class
locale: phonenumbers/geodata/locale.py
phonenumbers/geodata/__init__.py: buildgeocodingdata.py ../resources/geocoding
- $(PYTHON) buildgeocodingdata.py ../resources/geocoding $@
+ $(PYTHON) buildgeocodingdata.py ../resources/geocoding $@ .
tests/testgeodata/__init__.py: buildgeocodingdata.py ../resources/test/geocoding
- $(PYTHON) buildgeocodingdata.py ../resources/test/geocoding $@
+ $(PYTHON) buildgeocodingdata.py ../resources/test/geocoding $@ phonenumbers
geodata: phonenumbers/geodata/__init__.py tests/testgeodata/__init__.py
phonenumbers/data/__init__.py: ../resources/PhoneNumberMetaData.xml buildmetadatafromxml.py
$(PYTHON) buildmetadatafromxml.py ../resources/PhoneNumberMetaData.xml phonenumbers/data .
-metadata: phonenumbers/data/__init__.py tests/testdata/__init__.py geodata
-
tests/testdata/__init__.py: ../resources/PhoneNumberMetaDataForTesting.xml buildmetadatafromxml.py
$(PYTHON) buildmetadatafromxml.py ../resources/PhoneNumberMetaDataForTesting.xml tests/testdata phonenumbers
+metadata: phonenumbers/data/__init__.py tests/testdata/__init__.py geodata
+
test: alldata tests/testdata/__init__.py
$(PYTHON) -m phonenumbers.__init__
$(PYTHON) -m phonenumbers.util

0 comments on commit b4cb1e9

Please sign in to comment.