|
13 | 13 |
|
14 | 14 | from __future__ import print_function |
15 | 15 |
|
| 16 | +import io |
16 | 17 | import json |
17 | 18 | import optparse |
18 | 19 | import os |
@@ -159,9 +160,8 @@ def runcmd(tool, cmd, doContinue=False): |
159 | 160 | return rc |
160 | 161 |
|
161 | 162 | ## STEP 0 - read in json config |
162 | | -fi= open(options.filterfile, "rb") |
163 | | -config=json.load(fi) |
164 | | -fi.close() |
| 163 | +with io.open(options.filterfile, encoding='utf-8') as fi: |
| 164 | + config = json.load(fi) |
165 | 165 |
|
166 | 166 | if options.locales: |
167 | 167 | config["variables"] = config.get("variables", {}) |
@@ -285,10 +285,9 @@ def addTreeByType(tree, mytree): |
285 | 285 | # read in the resource list for the tree |
286 | 286 | treelistfile = os.path.join(options.tmpdir,"%s.lst" % tree) |
287 | 287 | runcmd("iculslocs", "-i %s -N %s -T %s -l > %s" % (outfile, dataname, tree, treelistfile)) |
288 | | - fi = open(treelistfile, 'rb') |
289 | | - treeitems = fi.readlines() |
290 | | - trees[tree]["locs"] = [treeitems[i].strip() for i in range(len(treeitems))] |
291 | | - fi.close() |
| 288 | + with io.open(treelistfile, 'r', encoding='utf-8') as fi: |
| 289 | + treeitems = fi.readlines() |
| 290 | + trees[tree]["locs"] = [line.strip() for line in treeitems] |
292 | 291 | if tree not in config.get("trees", {}): |
293 | 292 | print(" Warning: filter file %s does not mention trees.%s - will be kept as-is" % (options.filterfile, tree)) |
294 | 293 | else: |
@@ -317,12 +316,12 @@ def removeList(count=0): |
317 | 316 | erritems = fi.readlines() |
318 | 317 | fi.close() |
319 | 318 | #Item zone/zh_Hant_TW.res depends on missing item zone/zh_Hant.res |
320 | | - pat = re.compile("""^Item ([^ ]+) depends on missing item ([^ ]+).*""") |
| 319 | + pat = re.compile(bytes(r"^Item ([^ ]+) depends on missing item ([^ ]+).*", 'utf-8')) |
321 | 320 | for i in range(len(erritems)): |
322 | 321 | line = erritems[i].strip() |
323 | 322 | m = pat.match(line) |
324 | 323 | if m: |
325 | | - toDelete = m.group(1) |
| 324 | + toDelete = m.group(1).decode("utf-8") |
326 | 325 | if(options.verbose > 5): |
327 | 326 | print("<< %s added to delete" % toDelete) |
328 | 327 | remove.add(toDelete) |
|
0 commit comments