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
46 changes: 19 additions & 27 deletions tools/icu/icutrim.py
Original file line number Diff line number Diff line change
Expand Up @@ -163,17 +163,15 @@ def runcmd(tool, cmd, doContinue=False):
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"] = {}
if options.locales:
config["variables"] = config.get("variables", {})
config["variables"]["locales"] = config["variables"].get("locales", {})
config["variables"]["locales"]["only"] = options.locales.split(',')
Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This file uses 4 space indent so can you use that here too?

(Confusing really since we use 2 space indent everywhere else. Oh well.)

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done.


if (options.verbose > 6):
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
Expand All @@ -186,61 +184,55 @@ def runcmd(tool, cmd, doContinue=False):
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):
if(options.verbose>2):
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"])
Expand Down Expand Up @@ -297,7 +289,7 @@ def addTreeByType(tree, mytree):
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)
Expand Down Expand Up @@ -352,7 +344,7 @@ def removeList(count=0):
# 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"]):
Expand Down