Merge "Use print function rather than print statement"

This commit is contained in:
Jenkins 2013-10-15 01:49:50 +00:00 committed by Gerrit Code Review
commit 767bf3b536
9 changed files with 54 additions and 40 deletions

View File

@ -102,6 +102,7 @@ class CoverageController(object):
def _start_coverage_telnet(self, tn, service): def _start_coverage_telnet(self, tn, service):
data_file = os.path.join(self.data_path, data_file = os.path.join(self.data_path,
'.nova-coverage.%s' % str(service)) '.nova-coverage.%s' % str(service))
tn.write('from __future__ import print_function\n')
tn.write('import sys\n') tn.write('import sys\n')
tn.write('from coverage import coverage\n') tn.write('from coverage import coverage\n')
tn.write("coverInst = coverage(data_file='%s') " tn.write("coverInst = coverage(data_file='%s') "
@ -109,7 +110,7 @@ class CoverageController(object):
"else coverInst\n" % data_file) "else coverInst\n" % data_file)
tn.write('coverInst.skipModules = sys.modules.keys()\n') tn.write('coverInst.skipModules = sys.modules.keys()\n')
tn.write("coverInst.start()\n") tn.write("coverInst.start()\n")
tn.write("print 'finished'\n") tn.write("print('finished')\n")
tn.expect([re.compile('finished')]) tn.expect([re.compile('finished')])
def _start_coverage(self, req, body): def _start_coverage(self, req, body):
@ -147,7 +148,7 @@ class CoverageController(object):
def _stop_coverage_telnet(self, tn): def _stop_coverage_telnet(self, tn):
tn.write("coverInst.stop()\n") tn.write("coverInst.stop()\n")
tn.write("coverInst.save()\n") tn.write("coverInst.save()\n")
tn.write("print 'finished'\n") tn.write("print('finished')\n")
tn.expect([re.compile('finished')]) tn.expect([re.compile('finished')])
def _check_coverage(self): def _check_coverage(self):
@ -170,14 +171,14 @@ class CoverageController(object):
if xml: if xml:
execute = str("coverInst.xml_report(outfile='%s')\n" % path) execute = str("coverInst.xml_report(outfile='%s')\n" % path)
tn.write(execute) tn.write(execute)
tn.write("print 'finished'\n") tn.write("print('finished')\n")
tn.expect([re.compile('finished')]) tn.expect([re.compile('finished')])
else: else:
execute = str("output = open('%s', 'w')\n" % path) execute = str("output = open('%s', 'w')\n" % path)
tn.write(execute) tn.write(execute)
tn.write("coverInst.report(file=output)\n") tn.write("coverInst.report(file=output)\n")
tn.write("output.close()\n") tn.write("output.close()\n")
tn.write("print 'finished'\n") tn.write("print('finished')\n")
tn.expect([re.compile('finished')]) tn.expect([re.compile('finished')])
tn.close() tn.close()
@ -244,7 +245,7 @@ class CoverageController(object):
def _reset_coverage_telnet(self, tn): def _reset_coverage_telnet(self, tn):
tn.write("coverInst.erase()\n") tn.write("coverInst.erase()\n")
tn.write("print 'finished'\n") tn.write("print('finished')\n")
tn.expect([re.compile('finished')]) tn.expect([re.compile('finished')])
def _reset_coverage(self, req): def _reset_coverage(self, req):

View File

@ -117,6 +117,7 @@ class CoverageController(wsgi.Controller):
def _start_coverage_telnet(self, tn, service): def _start_coverage_telnet(self, tn, service):
data_file = os.path.join(self.data_path, data_file = os.path.join(self.data_path,
'.nova-coverage.%s' % str(service)) '.nova-coverage.%s' % str(service))
tn.write('from __future__ import print_function\n')
tn.write('import sys\n') tn.write('import sys\n')
tn.write('from coverage import coverage\n') tn.write('from coverage import coverage\n')
tn.write("coverInst = coverage(data_file='%s') " tn.write("coverInst = coverage(data_file='%s') "
@ -124,7 +125,7 @@ class CoverageController(wsgi.Controller):
"else coverInst\n" % data_file) "else coverInst\n" % data_file)
tn.write('coverInst.skipModules = sys.modules.keys()\n') tn.write('coverInst.skipModules = sys.modules.keys()\n')
tn.write("coverInst.start()\n") tn.write("coverInst.start()\n")
tn.write("print 'finished'\n") tn.write("print('finished')\n")
tn.expect([re.compile('finished')]) tn.expect([re.compile('finished')])
def _check_coverage_module_loaded(self): def _check_coverage_module_loaded(self):
@ -172,7 +173,7 @@ class CoverageController(wsgi.Controller):
def _stop_coverage_telnet(self, tn): def _stop_coverage_telnet(self, tn):
tn.write("coverInst.stop()\n") tn.write("coverInst.stop()\n")
tn.write("coverInst.save()\n") tn.write("coverInst.save()\n")
tn.write("print 'finished'\n") tn.write("print('finished')\n")
tn.expect([re.compile('finished')]) tn.expect([re.compile('finished')])
def _check_coverage(self): def _check_coverage(self):
@ -199,14 +200,14 @@ class CoverageController(wsgi.Controller):
if xml: if xml:
execute = str("coverInst.xml_report(outfile='%s')\n" % path) execute = str("coverInst.xml_report(outfile='%s')\n" % path)
tn.write(execute) tn.write(execute)
tn.write("print 'finished'\n") tn.write("print('finished')\n")
tn.expect([re.compile('finished')]) tn.expect([re.compile('finished')])
else: else:
execute = str("output = open('%s', 'w')\n" % path) execute = str("output = open('%s', 'w')\n" % path)
tn.write(execute) tn.write(execute)
tn.write("coverInst.report(file=output)\n") tn.write("coverInst.report(file=output)\n")
tn.write("output.close()\n") tn.write("output.close()\n")
tn.write("print 'finished'\n") tn.write("print('finished')\n")
tn.expect([re.compile('finished')]) tn.expect([re.compile('finished')])
tn.close() tn.close()
@ -277,7 +278,7 @@ class CoverageController(wsgi.Controller):
def _reset_coverage_telnet(self, tn): def _reset_coverage_telnet(self, tn):
tn.write("coverInst.erase()\n") tn.write("coverInst.erase()\n")
tn.write("print 'finished'\n") tn.write("print('finished')\n")
tn.expect([re.compile('finished')]) tn.expect([re.compile('finished')])
@extensions.expected_errors(503) @extensions.expected_errors(503)

View File

@ -1097,7 +1097,7 @@ class AgentBuildCommands(object):
agent_build.version, agent_build.md5hash)) agent_build.version, agent_build.md5hash))
print(' %s' % agent_build.url) print(' %s' % agent_build.url)
print print()
@args('--os', metavar='<os>', help='os') @args('--os', metavar='<os>', help='os')
@args('--architecture', dest='architecture', @args('--architecture', dest='architecture',

View File

@ -379,7 +379,7 @@ class Debug(Middleware):
print(('*' * 40) + ' RESPONSE HEADERS') print(('*' * 40) + ' RESPONSE HEADERS')
for (key, value) in resp.headers.iteritems(): for (key, value) in resp.headers.iteritems():
print(key, '=', value) print(key, '=', value)
print print()
resp.app_iter = self.print_generator(resp.app_iter) resp.app_iter = self.print_generator(resp.app_iter)

View File

@ -21,6 +21,9 @@ find_unused_options.py
Compare the nova.conf file with the nova.conf.sample file to find any unused Compare the nova.conf file with the nova.conf.sample file to find any unused
options or default values in nova.conf options or default values in nova.conf
''' '''
from __future__ import print_function
import argparse import argparse
import os import os
import sys import sys
@ -74,7 +77,7 @@ if __name__ == '__main__':
for k, v in sorted(conf_file_options.items()): for k, v in sorted(conf_file_options.items()):
if k not in sample_conf_file_options: if k not in sample_conf_file_options:
print "Unused:", k print("Unused:", k)
for k, v in sorted(conf_file_options.items()): for k, v in sorted(conf_file_options.items()):
if k in sample_conf_file_options and v == sample_conf_file_options[k]: if k in sample_conf_file_options and v == sample_conf_file_options[k]:
print "Default valued:", k print("Default valued:", k)

View File

@ -31,6 +31,9 @@ Run like:
./tools/db/schema_diff.py mysql master:latest my_branch:82 ./tools/db/schema_diff.py mysql master:latest my_branch:82
""" """
from __future__ import print_function
import datetime import datetime
import glob import glob
import os import os
@ -191,19 +194,19 @@ def git_has_uncommited_changes():
def die(msg): def die(msg):
print >> sys.stderr, "ERROR: %s" % msg print("ERROR: %s" % msg, file=sys.stderr)
sys.exit(1) sys.exit(1)
def usage(msg=None): def usage(msg=None):
if msg: if msg:
print >> sys.stderr, "ERROR: %s" % msg print("ERROR: %s" % msg, file=sys.stderr)
prog = "schema_diff.py" prog = "schema_diff.py"
args = ["<mysql|postgres>", "<orig-branch:orig-version>", args = ["<mysql|postgres>", "<orig-branch:orig-version>",
"<new-branch:new-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) sys.exit(1)

View File

@ -19,6 +19,8 @@
# License for the specific language governing permissions and limitations # License for the specific language governing permissions and limitations
# under the License. # under the License.
from __future__ import print_function
import os import os
import sys import sys
@ -44,7 +46,7 @@ def print_help(venv, root):
Also, make test will automatically use the virtualenv. Also, make test will automatically use the virtualenv.
""" """
print help % (venv, root) print(help % (venv, root))
def main(argv): def main(argv):

View File

@ -18,6 +18,8 @@
"""pylint error checking.""" """pylint error checking."""
from __future__ import print_function
import cStringIO as StringIO import cStringIO as StringIO
import json import json
import re import re
@ -114,9 +116,9 @@ class ErrorKeys(object):
@classmethod @classmethod
def print_json(cls, errors, output=sys.stdout): 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()): for i in sorted(errors.keys()):
print >>output, json.dumps(i) print(json.dumps(i), file=output)
@classmethod @classmethod
def from_file(cls, filename): def from_file(cls, filename):
@ -139,7 +141,7 @@ def run_pylint():
def generate_error_keys(msg=None): def generate_error_keys(msg=None):
print "Generating", KNOWN_PYLINT_EXCEPTIONS_FILE print("Generating", KNOWN_PYLINT_EXCEPTIONS_FILE)
if msg is None: if msg is None:
msg = run_pylint() msg = run_pylint()
errors = LintOutput.from_msg_to_dict(msg) errors = LintOutput.from_msg_to_dict(msg)
@ -148,30 +150,30 @@ def generate_error_keys(msg=None):
def validate(newmsg=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) known = ErrorKeys.from_file(KNOWN_PYLINT_EXCEPTIONS_FILE)
if newmsg is None: if newmsg is None:
print "Running pylint. Be patient..." print("Running pylint. Be patient...")
newmsg = run_pylint() newmsg = run_pylint()
errors = LintOutput.from_msg_to_dict(newmsg) errors = LintOutput.from_msg_to_dict(newmsg)
print "Unique errors reported by pylint: was %d, now %d." \ print("Unique errors reported by pylint: was %d, now %d."
% (len(known), len(errors)) % (len(known), len(errors)))
passed = True passed = True
for err_key, err_list in errors.items(): for err_key, err_list in errors.items():
for err in err_list: for err in err_list:
if err_key not in known: if err_key not in known:
print err.lintoutput print(err.lintoutput)
print print()
passed = False passed = False
if passed: if passed:
print "Congrats! pylint check passed." print("Congrats! pylint check passed.")
redundant = known - set(errors.keys()) redundant = known - set(errors.keys())
if redundant: if redundant:
print "Extra credit: some known pylint exceptions disappeared." print("Extra credit: some known pylint exceptions disappeared.")
for i in sorted(redundant): for i in sorted(redundant):
print json.dumps(i) print(json.dumps(i))
print "Consider regenerating the exception file if you will." print("Consider regenerating the exception file if you will.")
else: else:
print ("Please fix the errors above. If you believe they are false" print ("Please fix the errors above. If you believe they are false"
" positives, run 'tools/lintstack.py generate' to overwrite.") " positives, run 'tools/lintstack.py generate' to overwrite.")
@ -179,10 +181,10 @@ def validate(newmsg=None):
def usage(): 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 generate pylint_exceptions file: tools/lintstack.py generate
To validate the current commit: tools/lintstack.py To validate the current commit: tools/lintstack.py
""" """)
def main(): def main():

View File

@ -32,6 +32,8 @@ Due to the risk of false positives, the results from this need some human
interpretation. interpretation.
""" """
from __future__ import print_function
import optparse import optparse
import string import string
import subprocess import subprocess
@ -39,12 +41,12 @@ import sys
def run(cmd, fail_ok=False): def run(cmd, fail_ok=False):
print "running: %s" % cmd print("running: %s" % cmd)
obj = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE, obj = subprocess.Popen(cmd, stdout=subprocess.PIPE, stderr=subprocess.PIPE,
shell=True) shell=True)
obj.wait() obj.wait()
if obj.returncode != 0 and not fail_ok: 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) sys.exit(obj.returncode)
return obj.stdout.read() return obj.stdout.read()
@ -95,13 +97,13 @@ def main():
run("git checkout %s" % original_branch) run("git checkout %s" % original_branch)
run("git branch -D %s" % new_branch) run("git branch -D %s" % new_branch)
print expect_failure print(expect_failure)
print "" print("")
print "*******************************" print("*******************************")
if test_works: if test_works:
print "FOUND a regression test" print("FOUND a regression test")
else: else:
print "NO regression test" print("NO regression test")
sys.exit(1) sys.exit(1)