summaryrefslogtreecommitdiff
path: root/tools
diff options
context:
space:
mode:
authorDavid Ripton <dripton@redhat.com>2013-10-08 11:13:45 -0400
committerDavid Ripton <dripton@redhat.com>2013-10-08 11:13:45 -0400
commita52db496a5a8ac3ffd8598bf8bbe7e120b63d36b (patch)
tree401fc4fb2cde2dfa15d5b400a08382ed381915b2 /tools
parenta0546fd3f42c37e8cd6e4e9b70d59ae1e689b4b7 (diff)
downloadnova-a52db496a5a8ac3ffd8598bf8bbe7e120b63d36b.tar.gz
Use print function rather than print statement
This is for Python 3 compatibility, since Python 3 does not support the print statement, only the print function. (Python 2.6 and 2.7 support both, depending on whether a __future__ import is used.) Paths containing "xen" were left alone, because of comments in a couple of the files indicating that the XenServer code needed to be compatible with Python 2.4. Fixes bug 1226943 Change-Id: I23b804a4d99500b4acf81dd19645ab06dfcc9f1c
Diffstat (limited to 'tools')
-rwxr-xr-xtools/config/analyze_opts.py7
-rwxr-xr-xtools/db/schema_diff.py9
-rw-r--r--tools/install_venv.py4
-rwxr-xr-xtools/lintstack.py32
-rwxr-xr-xtools/regression_tester.py16
5 files changed, 40 insertions, 28 deletions
diff --git a/tools/config/analyze_opts.py b/tools/config/analyze_opts.py
index 84294c9d31..c91f4dedaf 100755
--- a/tools/config/analyze_opts.py
+++ b/tools/config/analyze_opts.py
@@ -21,6 +21,9 @@ find_unused_options.py
Compare the nova.conf file with the nova.conf.sample file to find any unused
options or default values in nova.conf
'''
+
+from __future__ import print_function
+
import argparse
import os
import sys
@@ -74,7 +77,7 @@ if __name__ == '__main__':
for k, v in sorted(conf_file_options.items()):
if k not in sample_conf_file_options:
- print "Unused:", k
+ print("Unused:", k)
for k, v in sorted(conf_file_options.items()):
if k in sample_conf_file_options and v == sample_conf_file_options[k]:
- print "Default valued:", k
+ print("Default valued:", k)
diff --git a/tools/db/schema_diff.py b/tools/db/schema_diff.py
index d2fd493914..8fd9aad829 100755
--- a/tools/db/schema_diff.py
+++ b/tools/db/schema_diff.py
@@ -31,6 +31,9 @@ Run like:
./tools/db/schema_diff.py mysql master:latest my_branch:82
"""
+
+from __future__ import print_function
+
import datetime
import glob
import os
@@ -191,19 +194,19 @@ def git_has_uncommited_changes():
def die(msg):
- print >> sys.stderr, "ERROR: %s" % msg
+ print("ERROR: %s" % msg, file=sys.stderr)
sys.exit(1)
def usage(msg=None):
if msg:
- print >> sys.stderr, "ERROR: %s" % msg
+ print("ERROR: %s" % msg, file=sys.stderr)
prog = "schema_diff.py"
args = ["<mysql|postgres>", "<orig-branch:orig-version>",
"<new-branch:new-version>"]
- print >> sys.stderr, "usage: %s %s" % (prog, ' '.join(args))
+ print("usage: %s %s" % (prog, ' '.join(args)), file=sys.stderr)
sys.exit(1)
diff --git a/tools/install_venv.py b/tools/install_venv.py
index 8d30676df5..85d0c2794a 100644
--- a/tools/install_venv.py
+++ b/tools/install_venv.py
@@ -19,6 +19,8 @@
# License for the specific language governing permissions and limitations
# under the License.
+from __future__ import print_function
+
import os
import sys
@@ -44,7 +46,7 @@ def print_help(venv, root):
Also, make test will automatically use the virtualenv.
"""
- print help % (venv, root)
+ print(help % (venv, root))
def main(argv):
diff --git a/tools/lintstack.py b/tools/lintstack.py
index cda5f0b3d3..0240a43dc0 100755
--- a/tools/lintstack.py
+++ b/tools/lintstack.py
@@ -18,6 +18,8 @@
"""pylint error checking."""
+from __future__ import print_function
+
import cStringIO as StringIO
import json
import re
@@ -114,9 +116,9 @@ class ErrorKeys(object):
@classmethod
def print_json(cls, errors, output=sys.stdout):
- print >>output, "# automatically generated by tools/lintstack.py"
+ print("# automatically generated by tools/lintstack.py", file=output)
for i in sorted(errors.keys()):
- print >>output, json.dumps(i)
+ print(json.dumps(i), file=output)
@classmethod
def from_file(cls, filename):
@@ -139,7 +141,7 @@ def run_pylint():
def generate_error_keys(msg=None):
- print "Generating", KNOWN_PYLINT_EXCEPTIONS_FILE
+ print("Generating", KNOWN_PYLINT_EXCEPTIONS_FILE)
if msg is None:
msg = run_pylint()
errors = LintOutput.from_msg_to_dict(msg)
@@ -148,30 +150,30 @@ def generate_error_keys(msg=None):
def validate(newmsg=None):
- print "Loading", KNOWN_PYLINT_EXCEPTIONS_FILE
+ print("Loading", KNOWN_PYLINT_EXCEPTIONS_FILE)
known = ErrorKeys.from_file(KNOWN_PYLINT_EXCEPTIONS_FILE)
if newmsg is None:
- print "Running pylint. Be patient..."
+ print("Running pylint. Be patient...")
newmsg = run_pylint()
errors = LintOutput.from_msg_to_dict(newmsg)
- print "Unique errors reported by pylint: was %d, now %d." \
- % (len(known), len(errors))
+ print("Unique errors reported by pylint: was %d, now %d."
+ % (len(known), len(errors)))
passed = True
for err_key, err_list in errors.items():
for err in err_list:
if err_key not in known:
- print err.lintoutput
- print
+ print(err.lintoutput)
+ print()
passed = False
if passed:
- print "Congrats! pylint check passed."
+ print("Congrats! pylint check passed.")
redundant = known - set(errors.keys())
if redundant:
- print "Extra credit: some known pylint exceptions disappeared."
+ print("Extra credit: some known pylint exceptions disappeared.")
for i in sorted(redundant):
- print json.dumps(i)
- print "Consider regenerating the exception file if you will."
+ print(json.dumps(i))
+ print("Consider regenerating the exception file if you will.")
else:
print ("Please fix the errors above. If you believe they are false"
" positives, run 'tools/lintstack.py generate' to overwrite.")
@@ -179,10 +181,10 @@ def validate(newmsg=None):
def usage():
- print """Usage: tools/lintstack.py [generate|validate]
+ print("""Usage: tools/lintstack.py [generate|validate]
To generate pylint_exceptions file: tools/lintstack.py generate
To validate the current commit: tools/lintstack.py
- """
+ """)
def main():
diff --git a/tools/regression_tester.py b/tools/regression_tester.py
index aabd0d7940..89a5a4dd29 100755
--- a/tools/regression_tester.py
+++ b/tools/regression_tester.py
@@ -32,6 +32,8 @@ Due to the risk of false positives, the results from this need some human
interpretation.
"""
+from __future__ import print_function
+
import optparse
import string
import subprocess
@@ -39,12 +41,12 @@ import sys
def run(cmd, fail_ok=False):
- print "running: %s" % cmd
+ print("running: %s" % cmd)
obj = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=True)
obj.wait()
if obj.returncode != 0 and not fail_ok:
- print "The above command terminated with an error."
+ print("The above command terminated with an error.")
sys.exit(obj.returncode)
return obj.stdout.read()
@@ -95,13 +97,13 @@ def main():
run("git checkout %s" % original_branch)
run("git branch -D %s" % new_branch)
- print expect_failure
- print ""
- print "*******************************"
+ print(expect_failure)
+ print("")
+ print("*******************************")
if test_works:
- print "FOUND a regression test"
+ print("FOUND a regression test")
else:
- print "NO regression test"
+ print("NO regression test")
sys.exit(1)