summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorcclauss <cclauss@me.com>2019-08-19 22:03:06 +0200
committerRich Trott <rtrott@gmail.com>2019-08-21 16:30:05 -0700
commitd937b029a99064514965def31ef226dc959e1597 (patch)
tree9e82f519f81e923e1b45c7c51cd7cff06604e0a0 /tools
parent99f80604ad1dc9bfeb2b0b7bb77f51c06cd919db (diff)
downloadandroid-node-v8-d937b029a99064514965def31ef226dc959e1597.tar.gz
android-node-v8-d937b029a99064514965def31ef226dc959e1597.tar.bz2
android-node-v8-d937b029a99064514965def31ef226dc959e1597.zip
tools: fix Python 3 issues in tools/icu/icutrim.py
PR-URL: https://github.com/nodejs/node/pull/29213 Reviewed-By: Steven R Loomis <srloomis@us.ibm.com> Reviewed-By: Jiawen Geng <technicalcute@gmail.com> Reviewed-By: Ben Noordhuis <info@bnoordhuis.nl>
Diffstat (limited to 'tools')
-rwxr-xr-xtools/icu/icutrim.py56
1 files changed, 23 insertions, 33 deletions
diff --git a/tools/icu/icutrim.py b/tools/icu/icutrim.py
index a825b18ac0..25bd99d9cb 100755
--- a/tools/icu/icutrim.py
+++ b/tools/icu/icutrim.py
@@ -163,17 +163,15 @@ fi= open(options.filterfile, "rb")
config=json.load(fi)
fi.close()
-if (options.locales):
- if not config.has_key("variables"):
- config["variables"] = {}
- if not config["variables"].has_key("locales"):
- config["variables"]["locales"] = {}
- config["variables"]["locales"]["only"] = options.locales.split(',')
-
-if (options.verbose > 6):
+if options.locales:
+ config["variables"] = config.get("variables", {})
+ config["variables"]["locales"] = config["variables"].get("locales", {})
+ config["variables"]["locales"]["only"] = options.locales.split(',')
+
+if options.verbose > 6:
print(config)
-if(config.has_key("comment")):
+if "comment" in config:
print("%s: %s" % (options.filterfile, config["comment"]))
## STEP 1 - copy the data file, swapping endianness
@@ -186,53 +184,47 @@ runcmd("icupkg", "-t%s %s %s""" % (endian_letter, options.datfile, outfile))
listfile = os.path.join(options.tmpdir,"icudata.lst")
runcmd("icupkg", "-l %s > %s""" % (outfile, listfile))
-fi = open(listfile, 'rb')
-items = fi.readlines()
-items = [items[i].strip() for i in range(len(items))]
-fi.close()
-
+with open(listfile, 'rb') as fi:
+ items = [line.strip() for line in fi.read().decode("utf-8").splitlines()]
itemset = set(items)
-if (options.verbose>1):
- print("input file: %d items" % (len(items)))
+if options.verbose > 1:
+ print("input file: %d items" % len(items))
# list of all trees
trees = {}
RES_INDX = "res_index.res"
remove = None
# remove - always remove these
-if config.has_key("remove"):
+if "remove" in config:
remove = set(config["remove"])
else:
remove = set()
# keep - always keep these
-if config.has_key("keep"):
+if "keep" in config:
keep = set(config["keep"])
else:
keep = set()
def queueForRemoval(tree):
global remove
- if not config.has_key("trees"):
- # no config
- return
- if not config["trees"].has_key(tree):
+ if tree not in config.get("trees", {}):
return
mytree = trees[tree]
- if(options.verbose>0):
+ if options.verbose > 0:
print("* %s: %d items" % (tree, len(mytree["locs"])))
# do varible substitution for this tree here
if isinstance(config["trees"][tree], basestring):
treeStr = config["trees"][tree]
- if(options.verbose>5):
+ if options.verbose > 5:
print(" Substituting $%s for tree %s" % (treeStr, tree))
- if(not config.has_key("variables") or not config["variables"].has_key(treeStr)):
+ if treeStr not in config.get("variables", {}):
print(" ERROR: no variable: variables.%s for tree %s" % (treeStr, tree))
sys.exit(1)
config["trees"][tree] = config["variables"][treeStr]
myconfig = config["trees"][tree]
- if(options.verbose>4):
+ if options.verbose > 4:
print(" Config: %s" % (myconfig))
# Process this tree
if(len(myconfig)==0 or len(mytree["locs"])==0):
@@ -240,7 +232,7 @@ def queueForRemoval(tree):
print(" No processing for %s - skipping" % (tree))
else:
only = None
- if myconfig.has_key("only"):
+ if "only" in myconfig:
only = set(myconfig["only"])
if (len(only)==0) and (mytree["treeprefix"] != ""):
thePool = "%spool.res" % (mytree["treeprefix"])
@@ -297,7 +289,7 @@ for i in range(len(items)):
treeitems = fi.readlines()
trees[tree]["locs"] = [treeitems[i].strip() for i in range(len(treeitems))]
fi.close()
- if(not config.has_key("trees") or not config["trees"].has_key(tree)):
+ 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)
@@ -315,10 +307,8 @@ def removeList(count=0):
oldcount = len(remove)
hackerrfile=os.path.join(options.tmpdir, "REMOVE.err")
removefile = os.path.join(options.tmpdir, "REMOVE.lst")
- fi = open(removefile, 'wb')
- for i in remove:
- print(i, file=fi)
- fi.close()
+ with open(removefile, 'wb') as fi:
+ fi.write('\n'.join(remove).encode("utf-8") + b'\n')
rc = runcmd("icupkg","-r %s %s 2> %s" % (removefile,outfile,hackerrfile),True)
if rc != 0:
if(options.verbose>5):
@@ -352,7 +342,7 @@ removeList(1)
# now, fixup res_index, one at a time
for tree in trees:
# skip trees that don't have res_index
- if not trees[tree].has_key("hasIndex"):
+ if "hasIndex" not in trees[tree]:
continue
treebunddir = options.tmpdir
if(trees[tree]["treeprefix"]):