diff --git a/data/scripts/cat.py b/data/scripts/cat.py index 2395b2cdeb39..362868630715 100644 --- a/data/scripts/cat.py +++ b/data/scripts/cat.py @@ -16,14 +16,15 @@ # specific language governing permissions and limitations # under the License. # +from __future__ import print_function import sys, re import datetime import os table_name=None -if os.environ.has_key('hive_streaming_tablename'): +if 'hive_streaming_tablename' in os.environ: table_name=os.environ['hive_streaming_tablename'] for line in sys.stdin: - print line - print >> sys.stderr, "dummy" + print(line) + print("dummy", file=sys.stderr) diff --git a/data/scripts/cat_error.py b/data/scripts/cat_error.py index 9642efec8ecb..af47288485be 100644 --- a/data/scripts/cat_error.py +++ b/data/scripts/cat_error.py @@ -19,6 +19,6 @@ import sys for line in sys.stdin: - print line + print(line) sys.exit(1) diff --git a/data/scripts/doubleescapedtab.py b/data/scripts/doubleescapedtab.py index d373067baed2..8a63d1c46b34 100644 --- a/data/scripts/doubleescapedtab.py +++ b/data/scripts/doubleescapedtab.py @@ -19,6 +19,6 @@ import sys for line in sys.stdin: - print "1\\\\\\t2" - print "1\\\\\\\\t2" + print("1\\\\\\t2") + print("1\\\\\\\\t2") diff --git a/data/scripts/dumpdata_script.py b/data/scripts/dumpdata_script.py index c96c9e529bbb..320fa67b58f2 100644 --- a/data/scripts/dumpdata_script.py +++ b/data/scripts/dumpdata_script.py @@ -18,10 +18,15 @@ # import sys -for i in xrange(50): - for j in xrange(5): - for k in xrange(20022): - print 20000 * i + k +try: + range +except NameError: + range=xrange + +for i in range(50): + for j in range(5): + for k in range(20022): + print(20000 * i + k) for line in sys.stdin: pass diff --git a/data/scripts/escapedcarriagereturn.py b/data/scripts/escapedcarriagereturn.py index 475928a2430f..0cc5540e3022 100644 --- a/data/scripts/escapedcarriagereturn.py +++ b/data/scripts/escapedcarriagereturn.py @@ -19,5 +19,5 @@ import sys for line in sys.stdin: - print "1\\\\r2" + print("1\\\\r2") diff --git a/data/scripts/escapednewline.py b/data/scripts/escapednewline.py index 0d5751454bed..d2eeb309ca7c 100644 --- a/data/scripts/escapednewline.py +++ b/data/scripts/escapednewline.py @@ -19,5 +19,5 @@ import sys for line in sys.stdin: - print "1\\\\n2" + print("1\\\\n2") diff --git a/data/scripts/escapedtab.py b/data/scripts/escapedtab.py index 549c91e44463..d7fc64435a34 100644 --- a/data/scripts/escapedtab.py +++ b/data/scripts/escapedtab.py @@ -19,5 +19,5 @@ import sys for line in sys.stdin: - print "1\\\\t2" + print("1\\\\t2") diff --git a/data/scripts/input20_script.py b/data/scripts/input20_script.py index 223fa2be585f..06cb8f771287 100644 --- a/data/scripts/input20_script.py +++ b/data/scripts/input20_script.py @@ -20,11 +20,11 @@ import re dict = {} for line in sys.stdin.readlines(): - if dict.has_key(line): + if line in dict: x = dict[line] dict[line] = x + 1 else: dict[line] = 1 for key in dict: x = dict[key] - print str(x).strip()+'\t'+re.sub('\t','_',key.strip()) \ No newline at end of file + print(str(x).strip()+'\t'+re.sub('\t','_',key.strip())) diff --git a/data/scripts/newline.py b/data/scripts/newline.py index 6500d900dd8a..5ecb129e4292 100644 --- a/data/scripts/newline.py +++ b/data/scripts/newline.py @@ -19,6 +19,6 @@ import sys for line in sys.stdin: - print "1\\n2" - print "1\\r2" - print "1\\t2" + print("1\\n2") + print("1\\r2") + print("1\\t2") diff --git a/hcatalog/bin/hcat.py b/hcatalog/bin/hcat.py index e6ea70c80a00..d3c72f0b27dd 100644 --- a/hcatalog/bin/hcat.py +++ b/hcatalog/bin/hcat.py @@ -140,16 +140,16 @@ if debug == 1: - print "Would run:" - print "exec " + str(cmd) - print " with HADOOP_CLASSPATH set to %s" % (os.environ['HADOOP_CLASSPATH']) + print("Would run:") + print("exec " + str(cmd)) + print(" with HADOOP_CLASSPATH set to %s" % (os.environ['HADOOP_CLASSPATH'])) try: - print " and HADOOP_OPTS set to %s" % (os.environ['HADOOP_OPTS']) + print(" and HADOOP_OPTS set to %s" % (os.environ['HADOOP_OPTS'])) except: pass else: if dumpClasspath == 1: - print os.environ['HADOOP_CLASSPATH'] + print(os.environ['HADOOP_CLASSPATH']) else: if os.name == "posix": retval = subprocess.call(cmd) diff --git a/hcatalog/bin/hcat_server.py b/hcatalog/bin/hcat_server.py index 6afc05e6b510..16364670c99f 100644 --- a/hcatalog/bin/hcat_server.py +++ b/hcatalog/bin/hcat_server.py @@ -26,9 +26,9 @@ sleepTime = 3 def print_usage(): - print "Usage: %s [--config confdir] COMMAND" % (sys.argv[0]) - print " start Start HCatalog Server" - print " stop Stop HCatalog Server" + print("Usage: %s [--config confdir] COMMAND" % (sys.argv[0])) + print(" start Start HCatalog Server") + print(" stop Stop HCatalog Server") def start_hcat(): global sleepTime @@ -97,7 +97,7 @@ def start_hcat(): windowsTmpFile = os.path.join(os.environ['HCAT_LOG_DIR'], "windows.tmp") child = subprocess.Popen([command, "--service", "metastore"], stdout=outfd, stderr=errfd) pid = child.pid - print "Started metastore server init, testing if initialized correctly..." + print("Started metastore server init, testing if initialized correctly...") time.sleep(sleepTime) try: if os.name == "posix": @@ -111,9 +111,9 @@ def start_hcat(): pidFileDesc = open(pidFile, 'w') pidFileDesc.write(str(pid)) pidFileDesc.close() - print "Metastore initialized successfully" + print("Metastore initialized successfully") except Exception as inst: - print inst + print(inst) sys.exit("Metastore startup failed, see %s" % (errFile)) return diff --git a/hcatalog/bin/hcatcfg.py b/hcatalog/bin/hcatcfg.py index f8eb23749f02..1d67c951b661 100644 --- a/hcatalog/bin/hcatcfg.py +++ b/hcatalog/bin/hcatcfg.py @@ -21,6 +21,11 @@ import os.path import sys +try: + from functools import reduce +except: + pass + # Find the config file def findCfgFile(): defaultConfDir = None diff --git a/hcatalog/src/test/e2e/templeton/inpdir/xmlmapper.py b/hcatalog/src/test/e2e/templeton/inpdir/xmlmapper.py index 99f507a41409..cda61826e580 100644 --- a/hcatalog/src/test/e2e/templeton/inpdir/xmlmapper.py +++ b/hcatalog/src/test/e2e/templeton/inpdir/xmlmapper.py @@ -36,4 +36,4 @@ text = ' '.join( list ) text = text[0:10] + "..." + text[-10:] -print '[[%s]]\t[[%s]]' % (title, text) +print('[[%s]]\t[[%s]]' % (title, text)) diff --git a/hcatalog/src/test/e2e/templeton/inpdir/xmlreducer.py b/hcatalog/src/test/e2e/templeton/inpdir/xmlreducer.py index 09ed6467a88a..c3e7b5935af3 100644 --- a/hcatalog/src/test/e2e/templeton/inpdir/xmlreducer.py +++ b/hcatalog/src/test/e2e/templeton/inpdir/xmlreducer.py @@ -21,4 +21,4 @@ line = line.strip() title, page = line.split('\t', 1) - print '%s\t%s' % ( title, page ) + print('%s\t%s' % ( title, page )) diff --git a/service/lib/py/fb303_scripts/fb303_simple_mgmt.py b/service/lib/py/fb303_scripts/fb303_simple_mgmt.py index 4f8ce9933fb9..317bb88d4178 100644 --- a/service/lib/py/fb303_scripts/fb303_simple_mgmt.py +++ b/service/lib/py/fb303_scripts/fb303_simple_mgmt.py @@ -55,24 +55,24 @@ def service_ctrl( msg = fb_status_string(status) if (len(status_details)): msg += " - %s" % status_details - print msg + print(msg) if (status == fb_status.ALIVE): return 2 else: return 3 except: - print "Failed to get status" + print("Failed to get status") return 3 # scalar commands if command in ["version","alive","name"]: try: result = fb303_wrapper(command, port, trans_factory, prot_factory) - print result + print(result) return 0 except: - print "failed to get ",command + print("failed to get " + str(command)) return 3 # counters @@ -80,10 +80,10 @@ def service_ctrl( try: counters = fb303_wrapper('counters', port, trans_factory, prot_factory) for counter in counters: - print "%s: %d" % (counter, counters[counter]) + print("%s: %d" % (counter, counters[counter])) return 0 except: - print "failed to get counters" + print("failed to get counters") return 3 @@ -95,19 +95,19 @@ def service_ctrl( fb303_wrapper(command, port, trans_factory, prot_factory) return 0 except: - print "failed to tell the service to ", command + print("failed to tell the service to " + str(command)) return 3 else: if command in ["stop","reload"]: - print "root privileges are required to stop or reload the service." + print("root privileges are required to stop or reload the service.") return 4 - print "The following commands are available:" + print("The following commands are available:") for command in ["counters","name","version","alive","status"]: - print "\t%s" % command - print "The following commands are available for users with root privileges:" + print("\t%s" % command) + print("The following commands are available for users with root privileges:") for command in ["stop","reload"]: - print "\t%s" % command + print("\t%s" % command) diff --git a/testutils/gen-report.py b/testutils/gen-report.py index 791da5c80036..11ddf90c80e8 100644 --- a/testutils/gen-report.py +++ b/testutils/gen-report.py @@ -86,14 +86,14 @@ def plot_testsuite_time(json_data, top_k=TOP_K, ascii_graph=False, report_file=N for k,v in take(d_descending.iteritems(), top_k): gdata.append((k, v)) - print '\nTop ' + str(top_k) + ' testsuite in terms of execution time (in seconds).. [Total time: ' + str(overall_time) + ' seconds]' + print('\nTop ' + str(top_k) + ' testsuite in terms of execution time (in seconds).. [Total time: ' + str(overall_time) + ' seconds]') if ascii_graph: graph = Pyasciigraph() for line in graph.graph('', gdata): - print line + print(line) else: for line in gdata: - print line[0] + "\t" + str(line[1]) + print(line[0] + "\t" + str(line[1])) if report_file != None: with open(report_file, "w") as f: @@ -119,7 +119,7 @@ def plot_testcase_time(json_data, top_k=TOP_K, ascii_graph=False, report_file=No else: testcase_time[name] = time if int(suite['testsuite']['@tests']) == 0: - print "Empty batch detected for testsuite: " + suite['testsuite']['@name'] + " which took " + suite['testsuite']['@time'] + "s" + print("Empty batch detected for testsuite: " + suite['testsuite']['@name'] + " which took " + suite['testsuite']['@time'] + "s") d_descending = OrderedDict(sorted(testcase_time.items(), key=lambda kv: kv[1], reverse=True)) @@ -129,14 +129,14 @@ def plot_testcase_time(json_data, top_k=TOP_K, ascii_graph=False, report_file=No gdata.append((k, v)) - print '\nTop ' + str(top_k) + ' testcases in terms of execution time (in seconds).. [Total time: ' + str(overall_time) + ' seconds]' + print('\nTop ' + str(top_k) + ' testcases in terms of execution time (in seconds).. [Total time: ' + str(overall_time) + ' seconds]') if ascii_graph: graph = Pyasciigraph() for line in graph.graph('', gdata): - print line + print(line) else: for line in gdata: - print line[0] + "\t" + str(line[1]) + print(line[0] + "\t" + str(line[1])) if report_file != None: with open(report_file, "a") as f: @@ -175,7 +175,7 @@ def print_report(reportUrl, json_dump, top_k, ascii_graph, report_file=None): links = get_links(reportUrl) # Create a queue to communicate with the worker threads q = Queue.Queue() - print "\nProcessing " + str(len(links)) + " test xml reports from " + reportUrl + ".." + print("\nProcessing " + str(len(links)) + " test xml reports from " + reportUrl + "..") # Create 8 worker threads for x in range(8): worker = ReportDownloader(q)