Skip to content

Commit a5bdfed

Browse files
committed
Make internals of buildprefixdata more generic
1 parent 9ca5215 commit a5bdfed

1 file changed

Lines changed: 13 additions & 13 deletions

File tree

tools/python/buildprefixdata.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ def u(s):
5151
PREFIXDATA_SUFFIX = ".txt"
5252
BLANK_LINE_RE = re.compile(r'^\s*$', re.UNICODE)
5353
COMMENT_LINE_RE = re.compile(r'^\s*#.*$', re.UNICODE)
54-
DATA_LINE_RE = re.compile(r'^\+?(?P<prefix>\d+)\|(?P<location>.*)$', re.UNICODE)
54+
DATA_LINE_RE = re.compile(r'^\+?(?P<prefix>\d+)\|(?P<stringdata>.*)$', re.UNICODE)
5555

5656
# Boilerplate header
5757
PREFIXDATA_FILE_PROLOG = '''"""Per-prefix data, mapping each prefix to a dict of locale:name.
@@ -77,13 +77,13 @@ def u(s):
7777
""" % datetime.datetime.now().year
7878

7979

80-
def load_prefixdata_file(prefixdata, filename, locale, overall_prefix):
80+
def load_locale_prefixdata_file(prefixdata, filename, locale, overall_prefix):
8181
"""Load per-prefix data from the given file, for the given locale and prefix.
8282
8383
We assume that this file:
8484
- is encoded in UTF-8
8585
- may have comment lines (starting with #) and blank lines
86-
- has data lines of the form '<prefix>|<location_name>'
86+
- has data lines of the form '<prefix>|<stringdata>'
8787
- contains only data for prefixes that are extensions of the filename.
8888
"""
8989
with open(filename, "rb") as infile:
@@ -94,16 +94,16 @@ def load_prefixdata_file(prefixdata, filename, locale, overall_prefix):
9494
dm = DATA_LINE_RE.match(uline)
9595
if dm:
9696
prefix = dm.group('prefix')
97-
location = dm.group('location')
98-
if location != location.rstrip():
97+
stringdata = dm.group('stringdata')
98+
if stringdata != stringdata.rstrip():
9999
print ("%s:%d: Warning: stripping trailing whitespace" % (filename, lineno))
100-
location = location.rstrip()
100+
stringdata = stringdata.rstrip()
101101
if not prefix.startswith(overall_prefix):
102102
raise Exception("%s:%d: Prefix %s is not within %s" %
103103
(filename, lineno, prefix, overall_prefix))
104104
if prefix not in prefixdata:
105105
prefixdata[prefix] = {}
106-
prefixdata[prefix][locale] = location
106+
prefixdata[prefix][locale] = stringdata
107107
elif BLANK_LINE_RE.match(uline):
108108
pass
109109
elif COMMENT_LINE_RE.match(uline):
@@ -113,20 +113,20 @@ def load_prefixdata_file(prefixdata, filename, locale, overall_prefix):
113113
(filename, lineno, line))
114114

115115

116-
def load_prefixdata(indir):
116+
def load_locale_prefixdata(indir):
117117
"""Load per-prefix data from the given top-level directory.
118118
119119
Prefix data is assumed to be held in files <indir>/<locale>/<prefix>.txt.
120-
The same prefix may occur in multiple files, giving the location's name in
121-
different locales.
120+
The same prefix may occur in multiple files, giving the prefix's description
121+
in different locales.
122122
"""
123-
prefixdata = {} # prefix => dict mapping location to location name
123+
prefixdata = {} # prefix => dict mapping locale to description
124124
for locale in os.listdir(indir):
125125
if not os.path.isdir(os.path.join(indir, locale)):
126126
continue
127127
for filename in glob.glob(os.path.join(indir, locale, "*%s" % PREFIXDATA_SUFFIX)):
128128
overall_prefix, ext = os.path.splitext(os.path.basename(filename))
129-
load_prefixdata_file(prefixdata, filename, locale, overall_prefix)
129+
load_locale_prefixdata_file(prefixdata, filename, locale, overall_prefix)
130130
return prefixdata
131131

132132

@@ -174,7 +174,7 @@ def _standalone(argv):
174174
if len(args) != 2:
175175
prnt(__doc__, file=sys.stderr)
176176
sys.exit(1)
177-
prefixdata = load_prefixdata(args[0])
177+
prefixdata = load_locale_prefixdata(args[0])
178178
output_prefixdata_code(prefixdata, args[1], varprefix)
179179

180180

0 commit comments

Comments
 (0)