1111# Usage:
1212# Use "-h" to get help options.
1313
14+ from __future__ import print_function
1415import sys
1516import shutil
1617# for utf-8
7980
8081for opt in [ "datfile" , "filterfile" , "tmpdir" , "outfile" ]:
8182 if optVars [opt ] is None :
82- print "Missing required option: %s" % opt
83+ print ( "Missing required option: %s" % opt )
8384 sys .exit (1 )
8485
8586if options .verbose > 0 :
86- print "Options: " + str (options )
87+ print ( "Options: " + str (options ) )
8788
8889if (os .path .isdir (options .tmpdir ) and options .deltmpdir ):
8990 if options .verbose > 1 :
90- print "Deleting tmp dir %s.." % (options .tmpdir )
91+ print ( "Deleting tmp dir %s.." % (options .tmpdir ) )
9192 shutil .rmtree (options .tmpdir )
9293
9394if not (os .path .isdir (options .tmpdir )):
9495 os .mkdir (options .tmpdir )
9596else :
96- print "Please delete tmpdir %s before beginning." % options .tmpdir
97+ print ( "Please delete tmpdir %s before beginning." % options .tmpdir )
9798 sys .exit (1 )
9899
99100if options .endian not in ("big" ,"little" ,"host" ):
100- print "Unknown endianness: %s" % options .endian
101+ print ( "Unknown endianness: %s" % options .endian )
101102 sys .exit (1 )
102103
103104if options .endian is "host" :
104105 options .endian = endian
105106
106107if not os .path .isdir (options .tmpdir ):
107- print "Error, tmpdir not a directory: %s" % (options .tmpdir )
108+ print ( "Error, tmpdir not a directory: %s" % (options .tmpdir ) )
108109 sys .exit (1 )
109110
110111if not os .path .isfile (options .filterfile ):
111- print "Filterfile doesn't exist: %s" % (options .filterfile )
112+ print ( "Filterfile doesn't exist: %s" % (options .filterfile ) )
112113 sys .exit (1 )
113114
114115if not os .path .isfile (options .datfile ):
115- print "Datfile doesn't exist: %s" % (options .datfile )
116+ print ( "Datfile doesn't exist: %s" % (options .datfile ) )
116117 sys .exit (1 )
117118
118119if not options .datfile .endswith (".dat" ):
119- print "Datfile doesn't end with .dat: %s" % (options .datfile )
120+ print ( "Datfile doesn't end with .dat: %s" % (options .datfile ) )
120121 sys .exit (1 )
121122
122123outfile = os .path .join (options .tmpdir , options .outfile )
123124
124125if os .path .isfile (outfile ):
125- print "Error, output file does exist: %s" % (outfile )
126+ print ( "Error, output file does exist: %s" % (outfile ) )
126127 sys .exit (1 )
127128
128129if not options .outfile .endswith (".dat" ):
129- print "Outfile doesn't end with .dat: %s" % (options .outfile )
130+ print ( "Outfile doesn't end with .dat: %s" % (options .outfile ) )
130131 sys .exit (1 )
131132
132133dataname = options .outfile [0 :- 4 ]
@@ -140,11 +141,11 @@ def runcmd(tool, cmd, doContinue=False):
140141 cmd = tool + " " + cmd
141142
142143 if (options .verbose > 4 ):
143- print "# " + cmd
144+ print ( "# " + cmd )
144145
145146 rc = os .system (cmd )
146147 if rc is not 0 and not doContinue :
147- print "FAILED: %s" % cmd
148+ print ( "FAILED: %s" % cmd )
148149 sys .exit (1 )
149150 return rc
150151
@@ -161,10 +162,10 @@ def runcmd(tool, cmd, doContinue=False):
161162 config ["variables" ]["locales" ]["only" ] = options .locales .split (',' )
162163
163164if (options .verbose > 6 ):
164- print config
165+ print ( config )
165166
166167if (config .has_key ("comment" )):
167- print "%s: %s" % (options .filterfile , config ["comment" ])
168+ print ( "%s: %s" % (options .filterfile , config ["comment" ]) )
168169
169170## STEP 1 - copy the data file, swapping endianness
170171## The first letter of endian_letter will be 'b' or 'l' for big or little
@@ -184,7 +185,7 @@ def runcmd(tool, cmd, doContinue=False):
184185itemset = set (items )
185186
186187if (options .verbose > 1 ):
187- print "input file: %d items" % (len (items ))
188+ print ( "input file: %d items" % (len (items ) ))
188189
189190# list of all trees
190191trees = {}
@@ -211,23 +212,23 @@ def queueForRemoval(tree):
211212 return
212213 mytree = trees [tree ]
213214 if (options .verbose > 0 ):
214- print "* %s: %d items" % (tree , len (mytree ["locs" ]))
215+ print ( "* %s: %d items" % (tree , len (mytree ["locs" ]) ))
215216 # do varible substitution for this tree here
216217 if type (config ["trees" ][tree ]) == str or type (config ["trees" ][tree ]) == unicode :
217218 treeStr = config ["trees" ][tree ]
218219 if (options .verbose > 5 ):
219- print " Substituting $%s for tree %s" % (treeStr , tree )
220+ print ( " Substituting $%s for tree %s" % (treeStr , tree ) )
220221 if (not config .has_key ("variables" ) or not config ["variables" ].has_key (treeStr )):
221- print " ERROR: no variable: variables.%s for tree %s" % (treeStr , tree )
222+ print ( " ERROR: no variable: variables.%s for tree %s" % (treeStr , tree ) )
222223 sys .exit (1 )
223224 config ["trees" ][tree ] = config ["variables" ][treeStr ]
224225 myconfig = config ["trees" ][tree ]
225226 if (options .verbose > 4 ):
226- print " Config: %s" % (myconfig )
227+ print ( " Config: %s" % (myconfig ) )
227228 # Process this tree
228229 if (len (myconfig )== 0 or len (mytree ["locs" ])== 0 ):
229230 if (options .verbose > 2 ):
230- print " No processing for %s - skipping" % (tree )
231+ print ( " No processing for %s - skipping" % (tree ) )
231232 else :
232233 only = None
233234 if myconfig .has_key ("only" ):
@@ -236,22 +237,22 @@ def queueForRemoval(tree):
236237 thePool = "%spool.res" % (mytree ["treeprefix" ])
237238 if (thePool in itemset ):
238239 if (options .verbose > 0 ):
239- print "Removing %s because tree %s is empty." % (thePool , tree )
240+ print ( "Removing %s because tree %s is empty." % (thePool , tree ) )
240241 remove .add (thePool )
241242 else :
242- print "tree %s - no ONLY"
243+ print ( "tree %s - no ONLY" )
243244 for l in range (len (mytree ["locs" ])):
244245 loc = mytree ["locs" ][l ]
245246 if (only is not None ) and not loc in only :
246247 # REMOVE loc
247248 toRemove = "%s%s%s" % (mytree ["treeprefix" ], loc , mytree ["extension" ])
248249 if (options .verbose > 6 ):
249- print "Queueing for removal: %s" % toRemove
250+ print ( "Queueing for removal: %s" % toRemove )
250251 remove .add (toRemove )
251252
252253def addTreeByType (tree , mytree ):
253254 if (options .verbose > 1 ):
254- print "(considering %s): %s" % (tree , mytree )
255+ print ( "(considering %s): %s" % (tree , mytree ) )
255256 trees [tree ] = mytree
256257 mytree ["locs" ]= []
257258 for i in range (len (items )):
@@ -278,7 +279,7 @@ def addTreeByType(tree, mytree):
278279 else :
279280 tree = treeprefix [0 :- 1 ]
280281 if (options .verbose > 6 ):
281- print "procesing %s" % (tree )
282+ print ( "procesing %s" % (tree ) )
282283 trees [tree ] = { "extension" : ".res" , "treeprefix" : treeprefix , "hasIndex" : True }
283284 # read in the resource list for the tree
284285 treelistfile = os .path .join (options .tmpdir ,"%s.lst" % tree )
@@ -288,7 +289,7 @@ def addTreeByType(tree, mytree):
288289 trees [tree ]["locs" ] = [treeitems [i ].strip () for i in range (len (treeitems ))]
289290 fi .close ()
290291 if (not config .has_key ("trees" ) or not config ["trees" ].has_key (tree )):
291- print " Warning: filter file %s does not mention trees.%s - will be kept as-is" % (options .filterfile , tree )
292+ print ( " Warning: filter file %s does not mention trees.%s - will be kept as-is" % (options .filterfile , tree ) )
292293 else :
293294 queueForRemoval (tree )
294295
@@ -297,22 +298,22 @@ def removeList(count=0):
297298 global remove
298299 remove = remove - keep
299300 if (count > 10 ):
300- print "Giving up - %dth attempt at removal." % count
301+ print ( "Giving up - %dth attempt at removal." % count )
301302 sys .exit (1 )
302303 if (options .verbose > 1 ):
303- print "%d items to remove - try #%d" % (len (remove ),count )
304+ print ( "%d items to remove - try #%d" % (len (remove ),count ) )
304305 if (len (remove )> 0 ):
305306 oldcount = len (remove )
306307 hackerrfile = os .path .join (options .tmpdir , "REMOVE.err" )
307308 removefile = os .path .join (options .tmpdir , "REMOVE.lst" )
308309 fi = open (removefile , 'wb' )
309310 for i in remove :
310- print >> fi , i
311+ print ( i , file = fi )
311312 fi .close ()
312313 rc = runcmd ("icupkg" ,"-r %s %s 2> %s" % (removefile ,outfile ,hackerrfile ),True )
313314 if rc is not 0 :
314315 if (options .verbose > 5 ):
315- print "## Damage control, trying to parse stderr from icupkg.."
316+ print ( "## Damage control, trying to parse stderr from icupkg.." )
316317 fi = open (hackerrfile , 'rb' )
317318 erritems = fi .readlines ()
318319 fi .close ()
@@ -324,15 +325,15 @@ def removeList(count=0):
324325 if m :
325326 toDelete = m .group (1 )
326327 if (options .verbose > 5 ):
327- print "<< %s added to delete" % toDelete
328+ print ( "<< %s added to delete" % toDelete )
328329 remove .add (toDelete )
329330 else :
330- print "ERROR: could not match errline: %s" % line
331+ print ( "ERROR: could not match errline: %s" % line )
331332 sys .exit (1 )
332333 if (options .verbose > 5 ):
333- print " now %d items to remove" % len (remove )
334+ print ( " now %d items to remove" % len (remove ) )
334335 if (oldcount == len (remove )):
335- print " ERROR: could not add any mor eitems to remove. Fail."
336+ print ( " ERROR: could not add any mor eitems to remove. Fail." )
336337 sys .exit (1 )
337338 removeList (count + 1 )
338339
0 commit comments