11
11
# Usage:
12
12
# Use "-h" to get help options.
13
13
14
+ from __future__ import print_function
14
15
import sys
15
16
import shutil
16
17
# for utf-8
79
80
80
81
for opt in [ "datfile" , "filterfile" , "tmpdir" , "outfile" ]:
81
82
if optVars [opt ] is None :
82
- print "Missing required option: %s" % opt
83
+ print ( "Missing required option: %s" % opt )
83
84
sys .exit (1 )
84
85
85
86
if options .verbose > 0 :
86
- print "Options: " + str (options )
87
+ print ( "Options: " + str (options ) )
87
88
88
89
if (os .path .isdir (options .tmpdir ) and options .deltmpdir ):
89
90
if options .verbose > 1 :
90
- print "Deleting tmp dir %s.." % (options .tmpdir )
91
+ print ( "Deleting tmp dir %s.." % (options .tmpdir ) )
91
92
shutil .rmtree (options .tmpdir )
92
93
93
94
if not (os .path .isdir (options .tmpdir )):
94
95
os .mkdir (options .tmpdir )
95
96
else :
96
- print "Please delete tmpdir %s before beginning." % options .tmpdir
97
+ print ( "Please delete tmpdir %s before beginning." % options .tmpdir )
97
98
sys .exit (1 )
98
99
99
100
if options .endian not in ("big" ,"little" ,"host" ):
100
- print "Unknown endianness: %s" % options .endian
101
+ print ( "Unknown endianness: %s" % options .endian )
101
102
sys .exit (1 )
102
103
103
104
if options .endian is "host" :
104
105
options .endian = endian
105
106
106
107
if 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 ) )
108
109
sys .exit (1 )
109
110
110
111
if not os .path .isfile (options .filterfile ):
111
- print "Filterfile doesn't exist: %s" % (options .filterfile )
112
+ print ( "Filterfile doesn't exist: %s" % (options .filterfile ) )
112
113
sys .exit (1 )
113
114
114
115
if not os .path .isfile (options .datfile ):
115
- print "Datfile doesn't exist: %s" % (options .datfile )
116
+ print ( "Datfile doesn't exist: %s" % (options .datfile ) )
116
117
sys .exit (1 )
117
118
118
119
if 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 ) )
120
121
sys .exit (1 )
121
122
122
123
outfile = os .path .join (options .tmpdir , options .outfile )
123
124
124
125
if os .path .isfile (outfile ):
125
- print "Error, output file does exist: %s" % (outfile )
126
+ print ( "Error, output file does exist: %s" % (outfile ) )
126
127
sys .exit (1 )
127
128
128
129
if 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 ) )
130
131
sys .exit (1 )
131
132
132
133
dataname = options .outfile [0 :- 4 ]
@@ -140,11 +141,11 @@ def runcmd(tool, cmd, doContinue=False):
140
141
cmd = tool + " " + cmd
141
142
142
143
if (options .verbose > 4 ):
143
- print "# " + cmd
144
+ print ( "# " + cmd )
144
145
145
146
rc = os .system (cmd )
146
147
if rc is not 0 and not doContinue :
147
- print "FAILED: %s" % cmd
148
+ print ( "FAILED: %s" % cmd )
148
149
sys .exit (1 )
149
150
return rc
150
151
@@ -161,10 +162,10 @@ def runcmd(tool, cmd, doContinue=False):
161
162
config ["variables" ]["locales" ]["only" ] = options .locales .split (',' )
162
163
163
164
if (options .verbose > 6 ):
164
- print config
165
+ print ( config )
165
166
166
167
if (config .has_key ("comment" )):
167
- print "%s: %s" % (options .filterfile , config ["comment" ])
168
+ print ( "%s: %s" % (options .filterfile , config ["comment" ]) )
168
169
169
170
## STEP 1 - copy the data file, swapping endianness
170
171
## 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):
184
185
itemset = set (items )
185
186
186
187
if (options .verbose > 1 ):
187
- print "input file: %d items" % (len (items ))
188
+ print ( "input file: %d items" % (len (items ) ))
188
189
189
190
# list of all trees
190
191
trees = {}
@@ -211,23 +212,23 @@ def queueForRemoval(tree):
211
212
return
212
213
mytree = trees [tree ]
213
214
if (options .verbose > 0 ):
214
- print "* %s: %d items" % (tree , len (mytree ["locs" ]))
215
+ print ( "* %s: %d items" % (tree , len (mytree ["locs" ]) ))
215
216
# do varible substitution for this tree here
216
217
if type (config ["trees" ][tree ]) == str or type (config ["trees" ][tree ]) == unicode :
217
218
treeStr = config ["trees" ][tree ]
218
219
if (options .verbose > 5 ):
219
- print " Substituting $%s for tree %s" % (treeStr , tree )
220
+ print ( " Substituting $%s for tree %s" % (treeStr , tree ) )
220
221
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 ) )
222
223
sys .exit (1 )
223
224
config ["trees" ][tree ] = config ["variables" ][treeStr ]
224
225
myconfig = config ["trees" ][tree ]
225
226
if (options .verbose > 4 ):
226
- print " Config: %s" % (myconfig )
227
+ print ( " Config: %s" % (myconfig ) )
227
228
# Process this tree
228
229
if (len (myconfig )== 0 or len (mytree ["locs" ])== 0 ):
229
230
if (options .verbose > 2 ):
230
- print " No processing for %s - skipping" % (tree )
231
+ print ( " No processing for %s - skipping" % (tree ) )
231
232
else :
232
233
only = None
233
234
if myconfig .has_key ("only" ):
@@ -236,22 +237,22 @@ def queueForRemoval(tree):
236
237
thePool = "%spool.res" % (mytree ["treeprefix" ])
237
238
if (thePool in itemset ):
238
239
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 ) )
240
241
remove .add (thePool )
241
242
else :
242
- print "tree %s - no ONLY"
243
+ print ( "tree %s - no ONLY" )
243
244
for l in range (len (mytree ["locs" ])):
244
245
loc = mytree ["locs" ][l ]
245
246
if (only is not None ) and not loc in only :
246
247
# REMOVE loc
247
248
toRemove = "%s%s%s" % (mytree ["treeprefix" ], loc , mytree ["extension" ])
248
249
if (options .verbose > 6 ):
249
- print "Queueing for removal: %s" % toRemove
250
+ print ( "Queueing for removal: %s" % toRemove )
250
251
remove .add (toRemove )
251
252
252
253
def addTreeByType (tree , mytree ):
253
254
if (options .verbose > 1 ):
254
- print "(considering %s): %s" % (tree , mytree )
255
+ print ( "(considering %s): %s" % (tree , mytree ) )
255
256
trees [tree ] = mytree
256
257
mytree ["locs" ]= []
257
258
for i in range (len (items )):
@@ -278,7 +279,7 @@ def addTreeByType(tree, mytree):
278
279
else :
279
280
tree = treeprefix [0 :- 1 ]
280
281
if (options .verbose > 6 ):
281
- print "procesing %s" % (tree )
282
+ print ( "procesing %s" % (tree ) )
282
283
trees [tree ] = { "extension" : ".res" , "treeprefix" : treeprefix , "hasIndex" : True }
283
284
# read in the resource list for the tree
284
285
treelistfile = os .path .join (options .tmpdir ,"%s.lst" % tree )
@@ -288,7 +289,7 @@ def addTreeByType(tree, mytree):
288
289
trees [tree ]["locs" ] = [treeitems [i ].strip () for i in range (len (treeitems ))]
289
290
fi .close ()
290
291
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 ) )
292
293
else :
293
294
queueForRemoval (tree )
294
295
@@ -297,22 +298,22 @@ def removeList(count=0):
297
298
global remove
298
299
remove = remove - keep
299
300
if (count > 10 ):
300
- print "Giving up - %dth attempt at removal." % count
301
+ print ( "Giving up - %dth attempt at removal." % count )
301
302
sys .exit (1 )
302
303
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 ) )
304
305
if (len (remove )> 0 ):
305
306
oldcount = len (remove )
306
307
hackerrfile = os .path .join (options .tmpdir , "REMOVE.err" )
307
308
removefile = os .path .join (options .tmpdir , "REMOVE.lst" )
308
309
fi = open (removefile , 'wb' )
309
310
for i in remove :
310
- print >> fi , i
311
+ print ( i , file = fi )
311
312
fi .close ()
312
313
rc = runcmd ("icupkg" ,"-r %s %s 2> %s" % (removefile ,outfile ,hackerrfile ),True )
313
314
if rc is not 0 :
314
315
if (options .verbose > 5 ):
315
- print "## Damage control, trying to parse stderr from icupkg.."
316
+ print ( "## Damage control, trying to parse stderr from icupkg.." )
316
317
fi = open (hackerrfile , 'rb' )
317
318
erritems = fi .readlines ()
318
319
fi .close ()
@@ -324,15 +325,15 @@ def removeList(count=0):
324
325
if m :
325
326
toDelete = m .group (1 )
326
327
if (options .verbose > 5 ):
327
- print "<< %s added to delete" % toDelete
328
+ print ( "<< %s added to delete" % toDelete )
328
329
remove .add (toDelete )
329
330
else :
330
- print "ERROR: could not match errline: %s" % line
331
+ print ( "ERROR: could not match errline: %s" % line )
331
332
sys .exit (1 )
332
333
if (options .verbose > 5 ):
333
- print " now %d items to remove" % len (remove )
334
+ print ( " now %d items to remove" % len (remove ) )
334
335
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." )
336
337
sys .exit (1 )
337
338
removeList (count + 1 )
338
339
0 commit comments