Skip to content

Commit 8a5b5e1

Browse files
cclaussBethGriggs
cclauss
authored andcommitted
tools: use print() function on both Python 2 and 3
PR-URL: #24486 Reviewed-By: Anna Henningsen <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Sakthipriyan Vairamani <[email protected]>
1 parent ce2aa80 commit 8a5b5e1

7 files changed

+120
-113
lines changed

tools/genv8constants.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -7,13 +7,14 @@
77
# ustack helper.
88
#
99

10+
from __future__ import print_function
1011
import re
1112
import subprocess
1213
import sys
1314
import errno
1415

1516
if len(sys.argv) != 3:
16-
print "usage: objsym.py outfile libv8_base.a"
17+
print("usage: objsym.py outfile libv8_base.a")
1718
sys.exit(2);
1819

1920
outfile = file(sys.argv[1], 'w');
@@ -22,13 +23,13 @@
2223
bufsize=-1, stdout=subprocess.PIPE).stdout;
2324
except OSError, e:
2425
if e.errno == errno.ENOENT:
25-
print '''
26+
print('''
2627
Node.js compile error: could not find objdump
2728
2829
Check that GNU binutils are installed and included in PATH
29-
'''
30+
''')
3031
else:
31-
print 'problem running objdump: ', e.strerror
32+
print('problem running objdump: ', e.strerror)
3233

3334
sys.exit()
3435

tools/gyp_node.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
from __future__ import print_function
23
import os
34
import sys
45

@@ -52,7 +53,7 @@ def run_gyp(args):
5253

5354
rc = gyp.main(args)
5455
if rc != 0:
55-
print 'Error running GYP'
56+
print('Error running GYP')
5657
sys.exit(rc)
5758

5859

tools/icu/icutrim.py

+36-35
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
# Usage:
1212
# Use "-h" to get help options.
1313

14+
from __future__ import print_function
1415
import sys
1516
import shutil
1617
# for utf-8
@@ -79,54 +80,54 @@
7980

8081
for 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

8586
if options.verbose>0:
86-
print "Options: "+str(options)
87+
print("Options: "+str(options))
8788

8889
if (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

9394
if not (os.path.isdir(options.tmpdir)):
9495
os.mkdir(options.tmpdir)
9596
else:
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

99100
if 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

103104
if options.endian is "host":
104105
options.endian = endian
105106

106107
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))
108109
sys.exit(1)
109110

110111
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))
112113
sys.exit(1)
113114

114115
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))
116117
sys.exit(1)
117118

118119
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))
120121
sys.exit(1)
121122

122123
outfile = os.path.join(options.tmpdir, options.outfile)
123124

124125
if 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

128129
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))
130131
sys.exit(1)
131132

132133
dataname=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

163164
if (options.verbose > 6):
164-
print config
165+
print(config)
165166

166167
if(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):
184185
itemset = set(items)
185186

186187
if (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
190191
trees = {}
@@ -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

252253
def 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

tools/icu/shrink-icu-src.py

+19-18
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
#!/usr/bin/env python
2+
from __future__ import print_function
23
import optparse
34
import os
45
import re
@@ -29,11 +30,11 @@
2930
(options, args) = parser.parse_args()
3031

3132
if os.path.isdir(options.icusmall):
32-
print 'Deleting existing icusmall %s' % (options.icusmall)
33+
print('Deleting existing icusmall %s' % (options.icusmall))
3334
shutil.rmtree(options.icusmall)
3435

3536
if not os.path.isdir(options.icusrc):
36-
print 'Missing source ICU dir --icusrc=%s' % (options.icusrc)
37+
print('Missing source ICU dir --icusrc=%s' % (options.icusrc))
3738
sys.exit(1)
3839

3940

@@ -73,7 +74,7 @@ def icu_ignore(dir, files):
7374
def icu_info(icu_full_path):
7475
uvernum_h = os.path.join(icu_full_path, 'source/common/unicode/uvernum.h')
7576
if not os.path.isfile(uvernum_h):
76-
print ' Error: could not load %s - is ICU installed?' % uvernum_h
77+
print(' Error: could not load %s - is ICU installed?' % uvernum_h)
7778
sys.exit(1)
7879
icu_ver_major = None
7980
matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
@@ -83,25 +84,25 @@ def icu_info(icu_full_path):
8384
if m:
8485
icu_ver_major = m.group(1)
8586
if not icu_ver_major:
86-
print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
87+
print(' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h)
8788
sys.exit(1)
8889
icu_endianness = sys.byteorder[0]; # TODO(srl295): EBCDIC should be 'e'
8990
return (icu_ver_major, icu_endianness)
9091

9192
(icu_ver_major, icu_endianness) = icu_info(options.icusrc)
92-
print "icudt%s%s" % (icu_ver_major, icu_endianness)
93+
print("icudt%s%s" % (icu_ver_major, icu_endianness))
9394

9495
src_datafile = os.path.join(options.icutmp, "icusmdt%s.dat" % (icu_ver_major))
9596
dst_datafile = os.path.join(options.icusmall, "source","data","in", "icudt%s%s.dat" % (icu_ver_major, icu_endianness))
9697

9798
if not os.path.isfile(src_datafile):
98-
print "Could not find source datafile %s - did you build small-icu node?" % src_datafile
99+
print("Could not find source datafile %s - did you build small-icu node?" % src_datafile)
99100
sys.exit(1)
100101
else:
101-
print "will use small datafile %s" % (src_datafile)
102-
print '%s --> %s' % (options.icusrc, options.icusmall)
102+
print("will use small datafile %s" % (src_datafile))
103+
print('%s --> %s' % (options.icusrc, options.icusmall))
103104
shutil.copytree(options.icusrc, options.icusmall, ignore=icu_ignore)
104-
print '%s --> %s' % (src_datafile, dst_datafile)
105+
print('%s --> %s' % (src_datafile, dst_datafile))
105106

106107
# now, make the data dir (since we ignored it)
107108
os.mkdir(os.path.join(os.path.join(options.icusmall, "source", "data")))
@@ -114,13 +115,13 @@ def icu_info(icu_full_path):
114115
readme_name = os.path.join(options.icusmall, "README-SMALL-ICU.txt" )
115116

116117
fi = open(readme_name, 'wb')
117-
print >>fi, "Small ICU sources - auto generated by shrink-icu-src.py"
118-
print >>fi, ""
119-
print >>fi, "This directory contains the ICU subset used by --with-intl=small-icu (the default)"
120-
print >>fi, "It is a strict subset of ICU %s source files with the following exception(s):" % (icu_ver_major)
121-
print >>fi, "* %s : Reduced-size data file" % (dst_datafile)
122-
print >>fi, ""
123-
print >>fi, ""
124-
print >>fi, "To rebuild this directory, see ../../tools/icu/README.md"
125-
print >>fi, ""
118+
print("Small ICU sources - auto generated by shrink-icu-src.py", file=fi)
119+
print("", file=fi)
120+
print("This directory contains the ICU subset used by --with-intl=small-icu (the default)", file=fi)
121+
print("It is a strict subset of ICU %s source files with the following exception(s):" % (icu_ver_major), file=fi)
122+
print("* %s : Reduced-size data file" % (dst_datafile), file=fi)
123+
print("", file=fi)
124+
print("", file=fi)
125+
print("To rebuild this directory, see ../../tools/icu/README.md", file=fi)
126+
print("", file=fi)
126127
fi.close()

tools/run-valgrind.py

+3-2
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
2828
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2929

30+
from __future__ import print_function
3031
from os import path
3132
import subprocess
3233
import sys
@@ -40,12 +41,12 @@
4041
]
4142

4243
if len(sys.argv) < 2:
43-
print 'Please provide an executable to analyze.'
44+
print('Please provide an executable to analyze.')
4445
sys.exit(1)
4546

4647
executable = path.join(NODE_ROOT, sys.argv[1])
4748
if not path.exists(executable):
48-
print 'Cannot find the file specified: %s' % executable
49+
print('Cannot find the file specified: %s' % executable)
4950
sys.exit(1)
5051

5152
# Compute the command line.

tools/specialize_node_d.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66
# Specialize node.d for given flavor (`freebsd`) and arch (`x64` or `ia32`)
77
#
88

9+
from __future__ import print_function
910
import re
1011
import sys
1112

1213
if len(sys.argv) != 5:
13-
print "usage: specialize_node_d.py outfile src/node.d flavor arch"
14+
print("usage: specialize_node_d.py outfile src/node.d flavor arch")
1415
sys.exit(2);
1516

1617
outfile = file(sys.argv[1], 'w');

0 commit comments

Comments
 (0)