Skip to content

Commit

Permalink
tools: use print() function on both Python 2 and 3
Browse files Browse the repository at this point in the history
PR-URL: #24486
Reviewed-By: Anna Henningsen <anna@addaleax.net>
Reviewed-By: James M Snell <jasnell@gmail.com>
Reviewed-By: Refael Ackermann <refack@gmail.com>
Reviewed-By: Sakthipriyan Vairamani <thechargingvolcano@gmail.com>
  • Loading branch information
cclauss authored and rvagg committed Nov 28, 2018
1 parent b2c243f commit 23d8152
Show file tree
Hide file tree
Showing 7 changed files with 120 additions and 113 deletions.
9 changes: 5 additions & 4 deletions tools/genv8constants.py
Expand Up @@ -7,13 +7,14 @@
# ustack helper.
#

from __future__ import print_function
import re
import subprocess
import sys
import errno

if len(sys.argv) != 3:
print "usage: objsym.py outfile libv8_base.a"
print("usage: objsym.py outfile libv8_base.a")
sys.exit(2);

outfile = file(sys.argv[1], 'w');
Expand All @@ -22,13 +23,13 @@
bufsize=-1, stdout=subprocess.PIPE).stdout;
except OSError, e:
if e.errno == errno.ENOENT:
print '''
print('''
Node.js compile error: could not find objdump
Check that GNU binutils are installed and included in PATH
'''
''')
else:
print 'problem running objdump: ', e.strerror
print('problem running objdump: ', e.strerror)

sys.exit()

Expand Down
3 changes: 2 additions & 1 deletion tools/gyp_node.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
import os
import sys

Expand Down Expand Up @@ -52,7 +53,7 @@ def run_gyp(args):

rc = gyp.main(args)
if rc != 0:
print 'Error running GYP'
print('Error running GYP')
sys.exit(rc)


Expand Down
71 changes: 36 additions & 35 deletions tools/icu/icutrim.py
Expand Up @@ -11,6 +11,7 @@
# Usage:
# Use "-h" to get help options.

from __future__ import print_function
import sys
import shutil
# for utf-8
Expand Down Expand Up @@ -79,54 +80,54 @@

for opt in [ "datfile", "filterfile", "tmpdir", "outfile" ]:
if optVars[opt] is None:
print "Missing required option: %s" % opt
print("Missing required option: %s" % opt)
sys.exit(1)

if options.verbose>0:
print "Options: "+str(options)
print("Options: "+str(options))

if (os.path.isdir(options.tmpdir) and options.deltmpdir):
if options.verbose>1:
print "Deleting tmp dir %s.." % (options.tmpdir)
print("Deleting tmp dir %s.." % (options.tmpdir))
shutil.rmtree(options.tmpdir)

if not (os.path.isdir(options.tmpdir)):
os.mkdir(options.tmpdir)
else:
print "Please delete tmpdir %s before beginning." % options.tmpdir
print("Please delete tmpdir %s before beginning." % options.tmpdir)
sys.exit(1)

if options.endian not in ("big","little","host"):
print "Unknown endianness: %s" % options.endian
print("Unknown endianness: %s" % options.endian)
sys.exit(1)

if options.endian is "host":
options.endian = endian

if not os.path.isdir(options.tmpdir):
print "Error, tmpdir not a directory: %s" % (options.tmpdir)
print("Error, tmpdir not a directory: %s" % (options.tmpdir))
sys.exit(1)

if not os.path.isfile(options.filterfile):
print "Filterfile doesn't exist: %s" % (options.filterfile)
print("Filterfile doesn't exist: %s" % (options.filterfile))
sys.exit(1)

if not os.path.isfile(options.datfile):
print "Datfile doesn't exist: %s" % (options.datfile)
print("Datfile doesn't exist: %s" % (options.datfile))
sys.exit(1)

if not options.datfile.endswith(".dat"):
print "Datfile doesn't end with .dat: %s" % (options.datfile)
print("Datfile doesn't end with .dat: %s" % (options.datfile))
sys.exit(1)

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

if os.path.isfile(outfile):
print "Error, output file does exist: %s" % (outfile)
print("Error, output file does exist: %s" % (outfile))
sys.exit(1)

if not options.outfile.endswith(".dat"):
print "Outfile doesn't end with .dat: %s" % (options.outfile)
print("Outfile doesn't end with .dat: %s" % (options.outfile))
sys.exit(1)

dataname=options.outfile[0:-4]
Expand All @@ -140,11 +141,11 @@ def runcmd(tool, cmd, doContinue=False):
cmd = tool + " " + cmd

if(options.verbose>4):
print "# " + cmd
print("# " + cmd)

rc = os.system(cmd)
if rc is not 0 and not doContinue:
print "FAILED: %s" % cmd
print("FAILED: %s" % cmd)
sys.exit(1)
return rc

Expand All @@ -161,10 +162,10 @@ def runcmd(tool, cmd, doContinue=False):
config["variables"]["locales"]["only"] = options.locales.split(',')

if (options.verbose > 6):
print config
print(config)

if(config.has_key("comment")):
print "%s: %s" % (options.filterfile, config["comment"])
print("%s: %s" % (options.filterfile, config["comment"]))

## STEP 1 - copy the data file, swapping endianness
## The first letter of endian_letter will be 'b' or 'l' for big or little
Expand All @@ -184,7 +185,7 @@ def runcmd(tool, cmd, doContinue=False):
itemset = set(items)

if (options.verbose>1):
print "input file: %d items" % (len(items))
print("input file: %d items" % (len(items)))

# list of all trees
trees = {}
Expand All @@ -211,23 +212,23 @@ def queueForRemoval(tree):
return
mytree = trees[tree]
if(options.verbose>0):
print "* %s: %d items" % (tree, len(mytree["locs"]))
print("* %s: %d items" % (tree, len(mytree["locs"])))
# do varible substitution for this tree here
if type(config["trees"][tree]) == str or type(config["trees"][tree]) == unicode:
treeStr = config["trees"][tree]
if(options.verbose>5):
print " Substituting $%s for tree %s" % (treeStr, tree)
print(" Substituting $%s for tree %s" % (treeStr, tree))
if(not config.has_key("variables") or not config["variables"].has_key(treeStr)):
print " ERROR: no variable: variables.%s for tree %s" % (treeStr, tree)
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):
print " Config: %s" % (myconfig)
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)
print(" No processing for %s - skipping" % (tree))
else:
only = None
if myconfig.has_key("only"):
Expand All @@ -236,22 +237,22 @@ def queueForRemoval(tree):
thePool = "%spool.res" % (mytree["treeprefix"])
if (thePool in itemset):
if(options.verbose>0):
print "Removing %s because tree %s is empty." % (thePool, tree)
print("Removing %s because tree %s is empty." % (thePool, tree))
remove.add(thePool)
else:
print "tree %s - no ONLY"
print("tree %s - no ONLY")
for l in range(len(mytree["locs"])):
loc = mytree["locs"][l]
if (only is not None) and not loc in only:
# REMOVE loc
toRemove = "%s%s%s" % (mytree["treeprefix"], loc, mytree["extension"])
if(options.verbose>6):
print "Queueing for removal: %s" % toRemove
print("Queueing for removal: %s" % toRemove)
remove.add(toRemove)

def addTreeByType(tree, mytree):
if(options.verbose>1):
print "(considering %s): %s" % (tree, mytree)
print("(considering %s): %s" % (tree, mytree))
trees[tree] = mytree
mytree["locs"]=[]
for i in range(len(items)):
Expand All @@ -278,7 +279,7 @@ def addTreeByType(tree, mytree):
else:
tree = treeprefix[0:-1]
if(options.verbose>6):
print "procesing %s" % (tree)
print("procesing %s" % (tree))
trees[tree] = { "extension": ".res", "treeprefix": treeprefix, "hasIndex": True }
# read in the resource list for the tree
treelistfile = os.path.join(options.tmpdir,"%s.lst" % tree)
Expand All @@ -288,7 +289,7 @@ def addTreeByType(tree, mytree):
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)):
print " Warning: filter file %s does not mention trees.%s - will be kept as-is" % (options.filterfile, tree)
print(" Warning: filter file %s does not mention trees.%s - will be kept as-is" % (options.filterfile, tree))
else:
queueForRemoval(tree)

Expand All @@ -297,22 +298,22 @@ def removeList(count=0):
global remove
remove = remove - keep
if(count > 10):
print "Giving up - %dth attempt at removal." % count
print("Giving up - %dth attempt at removal." % count)
sys.exit(1)
if(options.verbose>1):
print "%d items to remove - try #%d" % (len(remove),count)
print("%d items to remove - try #%d" % (len(remove),count))
if(len(remove)>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 >>fi, i
print(i, file=fi)
fi.close()
rc = runcmd("icupkg","-r %s %s 2> %s" % (removefile,outfile,hackerrfile),True)
if rc is not 0:
if(options.verbose>5):
print "## Damage control, trying to parse stderr from icupkg.."
print("## Damage control, trying to parse stderr from icupkg..")
fi = open(hackerrfile, 'rb')
erritems = fi.readlines()
fi.close()
Expand All @@ -324,15 +325,15 @@ def removeList(count=0):
if m:
toDelete = m.group(1)
if(options.verbose > 5):
print "<< %s added to delete" % toDelete
print("<< %s added to delete" % toDelete)
remove.add(toDelete)
else:
print "ERROR: could not match errline: %s" % line
print("ERROR: could not match errline: %s" % line)
sys.exit(1)
if(options.verbose > 5):
print " now %d items to remove" % len(remove)
print(" now %d items to remove" % len(remove))
if(oldcount == len(remove)):
print " ERROR: could not add any mor eitems to remove. Fail."
print(" ERROR: could not add any mor eitems to remove. Fail.")
sys.exit(1)
removeList(count+1)

Expand Down
37 changes: 19 additions & 18 deletions tools/icu/shrink-icu-src.py
@@ -1,4 +1,5 @@
#!/usr/bin/env python
from __future__ import print_function
import optparse
import os
import re
Expand Down Expand Up @@ -29,11 +30,11 @@
(options, args) = parser.parse_args()

if os.path.isdir(options.icusmall):
print 'Deleting existing icusmall %s' % (options.icusmall)
print('Deleting existing icusmall %s' % (options.icusmall))
shutil.rmtree(options.icusmall)

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


Expand Down Expand Up @@ -73,7 +74,7 @@ def icu_ignore(dir, files):
def icu_info(icu_full_path):
uvernum_h = os.path.join(icu_full_path, 'source/common/unicode/uvernum.h')
if not os.path.isfile(uvernum_h):
print ' Error: could not load %s - is ICU installed?' % uvernum_h
print(' Error: could not load %s - is ICU installed?' % uvernum_h)
sys.exit(1)
icu_ver_major = None
matchVerExp = r'^\s*#define\s+U_ICU_VERSION_SHORT\s+"([^"]*)".*'
Expand All @@ -83,25 +84,25 @@ def icu_info(icu_full_path):
if m:
icu_ver_major = m.group(1)
if not icu_ver_major:
print ' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h
print(' Could not read U_ICU_VERSION_SHORT version from %s' % uvernum_h)
sys.exit(1)
icu_endianness = sys.byteorder[0]; # TODO(srl295): EBCDIC should be 'e'
return (icu_ver_major, icu_endianness)

(icu_ver_major, icu_endianness) = icu_info(options.icusrc)
print "icudt%s%s" % (icu_ver_major, icu_endianness)
print("icudt%s%s" % (icu_ver_major, icu_endianness))

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

if not os.path.isfile(src_datafile):
print "Could not find source datafile %s - did you build small-icu node?" % src_datafile
print("Could not find source datafile %s - did you build small-icu node?" % src_datafile)
sys.exit(1)
else:
print "will use small datafile %s" % (src_datafile)
print '%s --> %s' % (options.icusrc, options.icusmall)
print("will use small datafile %s" % (src_datafile))
print('%s --> %s' % (options.icusrc, options.icusmall))
shutil.copytree(options.icusrc, options.icusmall, ignore=icu_ignore)
print '%s --> %s' % (src_datafile, dst_datafile)
print('%s --> %s' % (src_datafile, dst_datafile))

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

fi = open(readme_name, 'wb')
print >>fi, "Small ICU sources - auto generated by shrink-icu-src.py"
print >>fi, ""
print >>fi, "This directory contains the ICU subset used by --with-intl=small-icu (the default)"
print >>fi, "It is a strict subset of ICU %s source files with the following exception(s):" % (icu_ver_major)
print >>fi, "* %s : Reduced-size data file" % (dst_datafile)
print >>fi, ""
print >>fi, ""
print >>fi, "To rebuild this directory, see ../../tools/icu/README.md"
print >>fi, ""
print("Small ICU sources - auto generated by shrink-icu-src.py", file=fi)
print("", file=fi)
print("This directory contains the ICU subset used by --with-intl=small-icu (the default)", file=fi)
print("It is a strict subset of ICU %s source files with the following exception(s):" % (icu_ver_major), file=fi)
print("* %s : Reduced-size data file" % (dst_datafile), file=fi)
print("", file=fi)
print("", file=fi)
print("To rebuild this directory, see ../../tools/icu/README.md", file=fi)
print("", file=fi)
fi.close()
5 changes: 3 additions & 2 deletions tools/run-valgrind.py
Expand Up @@ -27,6 +27,7 @@
# (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
# OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.

from __future__ import print_function
from os import path
import subprocess
import sys
Expand All @@ -40,12 +41,12 @@
]

if len(sys.argv) < 2:
print 'Please provide an executable to analyze.'
print('Please provide an executable to analyze.')
sys.exit(1)

executable = path.join(NODE_ROOT, sys.argv[1])
if not path.exists(executable):
print 'Cannot find the file specified: %s' % executable
print('Cannot find the file specified: %s' % executable)
sys.exit(1)

# Compute the command line.
Expand Down
3 changes: 2 additions & 1 deletion tools/specialize_node_d.py
Expand Up @@ -6,11 +6,12 @@
# Specialize node.d for given flavor (`freebsd`) and arch (`x64` or `ia32`)
#

from __future__ import print_function
import re
import sys

if len(sys.argv) != 5:
print "usage: specialize_node_d.py outfile src/node.d flavor arch"
print("usage: specialize_node_d.py outfile src/node.d flavor arch")
sys.exit(2);

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

0 comments on commit 23d8152

Please sign in to comment.