Skip to content
Closed
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Prev Previous commit
Next Next commit
use of io.open function
  • Loading branch information
jmercier-lbi committed Feb 26, 2020
commit 4c49c5040341002c63d89b5d4da61470373ff157
24 changes: 12 additions & 12 deletions tools/icu/icutrim.py
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@

from __future__ import print_function

import io
import json
import optparse
import os
Expand Down Expand Up @@ -159,9 +160,8 @@ def runcmd(tool, cmd, doContinue=False):
return rc

## STEP 0 - read in json config
fi= open(options.filterfile, "rb")
config=json.load(fi)
fi.close()
with io.open(options.filterfile, encoding='utf-8') as fi:
config=json.load(fi)
Comment thread
bioinfornatics marked this conversation as resolved.
Resolved

if options.locales:
config["variables"] = config.get("variables", {})
Expand Down Expand Up @@ -285,14 +285,14 @@ def addTreeByType(tree, mytree):
# read in the resource list for the tree
treelistfile = os.path.join(options.tmpdir,"%s.lst" % tree)
runcmd("iculslocs", "-i %s -N %s -T %s -l > %s" % (outfile, dataname, tree, treelistfile))
fi = open(treelistfile, 'r')
treeitems = fi.readlines()
trees[tree]["locs"] = [treeitems[i].strip() for i in range(len(treeitems))]
fi.close()
if tree not in config.get("trees", {}):
print(" Warning: filter file %s does not mention trees.%s - will be kept as-is" % (options.filterfile, tree))
else:
queueForRemoval(tree)
with io.open(treelistfile, 'r', encoding='utf-8') as fi:
treeitems = fi.readlines()
trees[tree]["locs"] = [treeitems[i].strip() for i in range(len(treeitems))]
Comment thread
aqrln marked this conversation as resolved.
Resolved
fi.close()
Comment thread
aqrln marked this conversation as resolved.
Resolved
if tree not in config.get("trees", {}):
print(" Warning: filter file %s does not mention trees.%s - will be kept as-is" % (options.filterfile, tree))
else:
queueForRemoval(tree)

def removeList(count=0):
# don't allow "keep" items to creep in here.
Expand All @@ -317,7 +317,7 @@ def removeList(count=0):
erritems = fi.readlines()
fi.close()
#Item zone/zh_Hant_TW.res depends on missing item zone/zh_Hant.res
pat = re.compile(rb"^Item ([^ ]+) depends on missing item ([^ ]+).*")
pat = re.compile(bytes(r"^Item ([^ ]+) depends on missing item ([^ ]+).*", 'utf-8'))
for i in range(len(erritems)):
line = erritems[i].strip()
m = pat.match(line)
Expand Down