diff --git a/tools/genv8constants.py b/tools/genv8constants.py index 2b6ed8499253ec..0f56857700c403 100755 --- a/tools/genv8constants.py +++ b/tools/genv8constants.py @@ -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'); @@ -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() diff --git a/tools/gyp_node.py b/tools/gyp_node.py index 043053c3daa9d9..831d2ef1550cdb 100755 --- a/tools/gyp_node.py +++ b/tools/gyp_node.py @@ -1,4 +1,5 @@ #!/usr/bin/env python +from __future__ import print_function import os import sys @@ -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) diff --git a/tools/icu/icutrim.py b/tools/icu/icutrim.py index 517bf39bad323d..2b771cb641ec37 100755 --- a/tools/icu/icutrim.py +++ b/tools/icu/icutrim.py @@ -11,6 +11,7 @@ # Usage: # Use "-h" to get help options. +from __future__ import print_function import sys import shutil # for utf-8 @@ -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] @@ -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 @@ -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 @@ -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 = {} @@ -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"): @@ -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)): @@ -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) @@ -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) @@ -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() @@ -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) diff --git a/tools/icu/shrink-icu-src.py b/tools/icu/shrink-icu-src.py index e18243542408a5..b6e456279b32c2 100644 --- a/tools/icu/shrink-icu-src.py +++ b/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 @@ -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) @@ -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+"([^"]*)".*' @@ -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"))) @@ -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() diff --git a/tools/run-valgrind.py b/tools/run-valgrind.py index cad3e7ec6954d2..67fa424584e63a 100755 --- a/tools/run-valgrind.py +++ b/tools/run-valgrind.py @@ -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 @@ -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. diff --git a/tools/specialize_node_d.py b/tools/specialize_node_d.py index bb5ef5a57ce916..d9e8c1fd13ea51 100755 --- a/tools/specialize_node_d.py +++ b/tools/specialize_node_d.py @@ -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'); diff --git a/tools/test.py b/tools/test.py index 67b8cb917e0db6..640206f95cb420 100755 --- a/tools/test.py +++ b/tools/test.py @@ -28,6 +28,7 @@ # OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. +from __future__ import print_function import imp import logging import optparse @@ -87,11 +88,11 @@ def PrintFailureHeader(self, test): negative_marker = '[negative] ' else: negative_marker = '' - print "=== %(label)s %(negative)s===" % { + print("=== %(label)s %(negative)s===" % { 'label': test.GetLabel(), 'negative': negative_marker - } - print "Path: %s" % "/".join(test.path) + }) + print("Path: %s" % "/".join(test.path)) def Run(self, tasks): self.Starting() @@ -182,40 +183,40 @@ def EscapeCommand(command): class SimpleProgressIndicator(ProgressIndicator): def Starting(self): - print 'Running %i tests' % len(self.cases) + print('Running %i tests' % len(self.cases)) def Done(self): - print + print() for failed in self.failed: self.PrintFailureHeader(failed.test) if failed.output.stderr: - print "--- stderr ---" - print failed.output.stderr.strip() + print("--- stderr ---") + print(failed.output.stderr.strip()) if failed.output.stdout: - print "--- stdout ---" - print failed.output.stdout.strip() - print "Command: %s" % EscapeCommand(failed.command) + print("--- stdout ---") + print(failed.output.stdout.strip()) + print("Command: %s" % EscapeCommand(failed.command)) if failed.HasCrashed(): - print "--- %s ---" % PrintCrashed(failed.output.exit_code) + print("--- %s ---" % PrintCrashed(failed.output.exit_code)) if failed.HasTimedOut(): - print "--- TIMEOUT ---" + print("--- TIMEOUT ---") if len(self.failed) == 0: - print "===" - print "=== All tests succeeded" - print "===" + print("===") + print("=== All tests succeeded") + print("===") else: - print - print "===" - print "=== %i tests failed" % len(self.failed) + print() + print("===") + print("=== %i tests failed" % len(self.failed)) if self.crashed > 0: - print "=== %i tests CRASHED" % self.crashed - print "===" + print("=== %i tests CRASHED" % self.crashed) + print("===") class VerboseProgressIndicator(SimpleProgressIndicator): def AboutToRun(self, case): - print 'Starting %s...' % case.GetLabel() + print('Starting %s...' % case.GetLabel()) sys.stdout.flush() def HasRun(self, output): @@ -226,7 +227,7 @@ def HasRun(self, output): outcome = 'FAIL' else: outcome = 'pass' - print 'Done running %s: %s' % (output.test.GetLabel(), outcome) + print('Done running %s: %s' % (output.test.GetLabel(), outcome)) class DotsProgressIndicator(SimpleProgressIndicator): @@ -362,9 +363,9 @@ def HasRun(self, output): ("because:" in line or "reason:" in line): if not printed_file: printed_file = True - print '==== %s ====' % command + print('==== %s ====' % command) self.failed.append(output) - print ' %s' % line + print(' %s' % line) def Done(self): pass @@ -393,15 +394,15 @@ def HasRun(self, output): self.PrintFailureHeader(output.test) stdout = output.output.stdout.strip() if len(stdout): - print self.templates['stdout'] % stdout + print(self.templates['stdout'] % stdout) stderr = output.output.stderr.strip() if len(stderr): - print self.templates['stderr'] % stderr - print "Command: %s" % EscapeCommand(output.command) + print(self.templates['stderr'] % stderr) + print("Command: %s" % EscapeCommand(output.command)) if output.HasCrashed(): - print "--- %s ---" % PrintCrashed(output.output.exit_code) + print("--- %s ---" % PrintCrashed(output.output.exit_code)) if output.HasTimedOut(): - print "--- TIMEOUT ---" + print("--- TIMEOUT ---") def Truncate(self, str, length): if length and (len(str) > (length - 3)): @@ -422,7 +423,7 @@ def PrintProgress(self, name): } status = self.Truncate(status, 78) self.last_status_length = len(status) - print status, + print(status, end=' ') sys.stdout.flush() @@ -437,7 +438,7 @@ def __init__(self, cases, flaky_tests_mode): super(ColorProgressIndicator, self).__init__(cases, flaky_tests_mode, templates) def ClearLine(self, last_line_length): - print "\033[1K\r", + print("\033[1K\r", end=' ') class MonochromeProgressIndicator(CompactProgressIndicator): @@ -453,7 +454,7 @@ def __init__(self, cases, flaky_tests_mode): super(MonochromeProgressIndicator, self).__init__(cases, flaky_tests_mode, templates) def ClearLine(self, last_line_length): - print ("\r" + (" " * last_line_length) + "\r"), + print(("\r" + (" " * last_line_length) + "\r"), end=' ') PROGRESS_INDICATORS = { @@ -616,7 +617,7 @@ def KillTimedOutProcess(context, pid): def RunProcess(context, timeout, args, **rest): - if context.verbose: print "#", " ".join(args) + if context.verbose: print("#", " ".join(args)) popen_args = args prev_error_mode = SEM_INVALID_VALUE; if utils.IsWindows(): @@ -1181,15 +1182,15 @@ def ParseCondition(expr): """Parses a logical expression into an Expression object""" tokens = Tokenizer(expr).Tokenize() if not tokens: - print "Malformed expression: '%s'" % expr + print("Malformed expression: '%s'" % expr) return None scan = Scanner(tokens) ast = ParseLogicalExpression(scan) if not ast: - print "Malformed expression: '%s'" % expr + print("Malformed expression: '%s'" % expr) return None if scan.HasMore(): - print "Malformed expression: '%s'" % expr + print("Malformed expression: '%s'" % expr) return None return ast @@ -1387,19 +1388,19 @@ def ProcessOptions(options): if options.run == [""]: options.run = None elif len(options.run) != 2: - print "The run argument must be two comma-separated integers." + print("The run argument must be two comma-separated integers.") return False else: try: options.run = map(int, options.run) except ValueError: - print "Could not parse the integers from the run argument." + print("Could not parse the integers from the run argument.") return False if options.run[0] < 0 or options.run[1] < 0: - print "The run argument cannot have negative integers." + print("The run argument cannot have negative integers.") return False if options.run[0] >= options.run[1]: - print "The test group to run (n) must be smaller than number of groups (m)." + print("The test group to run (n) must be smaller than number of groups (m).") return False if options.J: # inherit JOBS from environment if provided. some virtualised systems @@ -1407,7 +1408,7 @@ def ProcessOptions(options): cores = os.environ.get('JOBS') options.j = int(cores) if cores is not None else multiprocessing.cpu_count() if options.flaky_tests not in [RUN, SKIP, DONTCARE]: - print "Unknown flaky-tests mode %s" % options.flaky_tests + print("Unknown flaky-tests mode %s" % options.flaky_tests) return False return True @@ -1606,13 +1607,13 @@ def Main(): for mode in options.mode: vm = context.GetVm(arch, mode) if not exists(vm): - print "Can't find shell executable: '%s'" % vm + print("Can't find shell executable: '%s'" % vm) continue archEngineContext = Execute([vm, "-p", "process.arch"], context) vmArch = archEngineContext.stdout.rstrip() if archEngineContext.exit_code is not 0 or vmArch == "undefined": - print "Can't determine the arch of: '%s'" % vm - print archEngineContext.stderr.rstrip() + print("Can't determine the arch of: '%s'" % vm) + print(archEngineContext.stderr.rstrip()) continue env = { 'mode': mode, @@ -1649,15 +1650,15 @@ def Main(): if key in visited: continue visited.add(key) - print "--- begin source: %s ---" % test.GetLabel() + print("--- begin source: %s ---" % test.GetLabel()) source = test.GetSource().strip() - print source - print "--- end source: %s ---" % test.GetLabel() + print(source) + print("--- end source: %s ---" % test.GetLabel()) return 0 if options.warn_unused: for rule in globally_unused_rules: - print "Rule for '%s' was not used." % '/'.join([str(s) for s in rule.path]) + print("Rule for '%s' was not used." % '/'.join([str(s) for s in rule.path])) tempdir = os.environ.get('NODE_TEST_DIR') or options.temp_dir if tempdir: @@ -1666,7 +1667,7 @@ def Main(): os.makedirs(tempdir) except OSError as exception: if exception.errno != errno.EEXIST: - print "Could not create the temporary directory", options.temp_dir + print("Could not create the temporary directory", options.temp_dir) sys.exit(1) def should_keep(case): @@ -1700,7 +1701,7 @@ def should_keep(case): len(cases_to_run), options.run[1]) ] if len(cases_to_run) == 0: - print "No tests to run." + print("No tests to run.") return 1 else: try: @@ -1711,13 +1712,13 @@ def should_keep(case): result = 1 duration = time.time() - start except KeyboardInterrupt: - print "Interrupted" + print("Interrupted") return 1 if options.time: # Write the times to stderr to make it easy to separate from the # test output. - print + print() sys.stderr.write("--- Total time: %s ---\n" % FormatTime(duration)) timed_tests = [ t for t in cases_to_run if not t.duration is None ] timed_tests.sort(lambda a, b: a.CompareTime(b))