patman: Make print statements python 3.x safe
In python 3.x, print must be used as a function call. Convert all print statements to the function call style, importing from __future__ where we print with no trailing newline or print to a file object. Signed-off-by: Paul Burton <paul.burton@imgtec.com> Acked-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
parent
12e5476df3
commit
a920a17b2f
|
@ -83,7 +83,7 @@ def CheckPatch(fname, verbose=False):
|
||||||
|
|
||||||
for line in result.stdout.splitlines():
|
for line in result.stdout.splitlines():
|
||||||
if verbose:
|
if verbose:
|
||||||
print line
|
print(line)
|
||||||
|
|
||||||
# A blank line indicates the end of a message
|
# A blank line indicates the end of a message
|
||||||
if not line and item:
|
if not line and item:
|
||||||
|
@ -151,17 +151,17 @@ def CheckPatches(verbose, args):
|
||||||
error_count += result.errors
|
error_count += result.errors
|
||||||
warning_count += result.warnings
|
warning_count += result.warnings
|
||||||
check_count += result.checks
|
check_count += result.checks
|
||||||
print '%d errors, %d warnings, %d checks for %s:' % (result.errors,
|
print('%d errors, %d warnings, %d checks for %s:' % (result.errors,
|
||||||
result.warnings, result.checks, col.Color(col.BLUE, fname))
|
result.warnings, result.checks, col.Color(col.BLUE, fname)))
|
||||||
if (len(result.problems) != result.errors + result.warnings +
|
if (len(result.problems) != result.errors + result.warnings +
|
||||||
result.checks):
|
result.checks):
|
||||||
print "Internal error: some problems lost"
|
print("Internal error: some problems lost")
|
||||||
for item in result.problems:
|
for item in result.problems:
|
||||||
print GetWarningMsg(col, item.get('type', '<unknown>'),
|
print(GetWarningMsg(col, item.get('type', '<unknown>'),
|
||||||
item.get('file', '<unknown>'),
|
item.get('file', '<unknown>'),
|
||||||
item.get('line', 0), item.get('msg', 'message'))
|
item.get('line', 0), item.get('msg', 'message')))
|
||||||
print
|
print
|
||||||
#print stdout
|
#print(stdout)
|
||||||
if error_count or warning_count or check_count:
|
if error_count or warning_count or check_count:
|
||||||
str = 'checkpatch.pl found %d error(s), %d warning(s), %d checks(s)'
|
str = 'checkpatch.pl found %d error(s), %d warning(s), %d checks(s)'
|
||||||
color = col.GREEN
|
color = col.GREEN
|
||||||
|
@ -169,6 +169,6 @@ def CheckPatches(verbose, args):
|
||||||
color = col.YELLOW
|
color = col.YELLOW
|
||||||
if error_count:
|
if error_count:
|
||||||
color = col.RED
|
color = col.RED
|
||||||
print col.Color(color, str % (error_count, warning_count, check_count))
|
print(col.Color(color, str % (error_count, warning_count, check_count)))
|
||||||
return False
|
return False
|
||||||
return True
|
return True
|
||||||
|
|
|
@ -40,7 +40,7 @@ def GetMaintainer(fname, verbose=False):
|
||||||
get_maintainer = FindGetMaintainer()
|
get_maintainer = FindGetMaintainer()
|
||||||
if not get_maintainer:
|
if not get_maintainer:
|
||||||
if verbose:
|
if verbose:
|
||||||
print "WARNING: Couldn't find get_maintainer.pl"
|
print("WARNING: Couldn't find get_maintainer.pl")
|
||||||
return []
|
return []
|
||||||
|
|
||||||
stdout = command.Output(get_maintainer, '--norolestats', fname)
|
stdout = command.Output(get_maintainer, '--norolestats', fname)
|
||||||
|
|
|
@ -491,7 +491,7 @@ def LookupEmail(lookup_name, alias=None, raise_on_error=True, level=0):
|
||||||
if raise_on_error:
|
if raise_on_error:
|
||||||
raise OSError, msg
|
raise OSError, msg
|
||||||
else:
|
else:
|
||||||
print col.Color(col.RED, msg)
|
print(col.Color(col.RED, msg))
|
||||||
return out_list
|
return out_list
|
||||||
|
|
||||||
if lookup_name:
|
if lookup_name:
|
||||||
|
@ -500,7 +500,7 @@ def LookupEmail(lookup_name, alias=None, raise_on_error=True, level=0):
|
||||||
if raise_on_error:
|
if raise_on_error:
|
||||||
raise ValueError, msg
|
raise ValueError, msg
|
||||||
else:
|
else:
|
||||||
print col.Color(col.RED, msg)
|
print(col.Color(col.RED, msg))
|
||||||
return out_list
|
return out_list
|
||||||
for item in alias[lookup_name]:
|
for item in alias[lookup_name]:
|
||||||
todo = LookupEmail(item, alias, raise_on_error, level + 1)
|
todo = LookupEmail(item, alias, raise_on_error, level + 1)
|
||||||
|
@ -508,7 +508,7 @@ def LookupEmail(lookup_name, alias=None, raise_on_error=True, level=0):
|
||||||
if not new_item in out_list:
|
if not new_item in out_list:
|
||||||
out_list.append(new_item)
|
out_list.append(new_item)
|
||||||
|
|
||||||
#print "No match for alias '%s'" % lookup_name
|
#print("No match for alias '%s'" % lookup_name)
|
||||||
return out_list
|
return out_list
|
||||||
|
|
||||||
def GetTopLevel():
|
def GetTopLevel():
|
||||||
|
|
|
@ -480,12 +480,12 @@ def FixPatches(series, fnames):
|
||||||
commit.patch = fname
|
commit.patch = fname
|
||||||
result = FixPatch(backup_dir, fname, series, commit)
|
result = FixPatch(backup_dir, fname, series, commit)
|
||||||
if result:
|
if result:
|
||||||
print '%d warnings for %s:' % (len(result), fname)
|
print('%d warnings for %s:' % (len(result), fname))
|
||||||
for warn in result:
|
for warn in result:
|
||||||
print '\t', warn
|
print('\t', warn)
|
||||||
print
|
print
|
||||||
count += 1
|
count += 1
|
||||||
print 'Cleaned %d patches' % count
|
print('Cleaned %d patches' % count)
|
||||||
return series
|
return series
|
||||||
|
|
||||||
def InsertCoverLetter(fname, series, count):
|
def InsertCoverLetter(fname, series, count):
|
||||||
|
|
|
@ -93,11 +93,11 @@ elif options.test:
|
||||||
suite.run(result)
|
suite.run(result)
|
||||||
|
|
||||||
# TODO: Surely we can just 'print' result?
|
# TODO: Surely we can just 'print' result?
|
||||||
print result
|
print(result)
|
||||||
for test, err in result.errors:
|
for test, err in result.errors:
|
||||||
print err
|
print(err)
|
||||||
for test, err in result.failures:
|
for test, err in result.failures:
|
||||||
print err
|
print(err)
|
||||||
|
|
||||||
# Called from git with a patch filename as argument
|
# Called from git with a patch filename as argument
|
||||||
# Printout a list of additional CC recipients for this patch
|
# Printout a list of additional CC recipients for this patch
|
||||||
|
@ -110,7 +110,7 @@ elif options.cc_cmd:
|
||||||
for cc in match.group(2).split(', '):
|
for cc in match.group(2).split(', '):
|
||||||
cc = cc.strip()
|
cc = cc.strip()
|
||||||
if cc:
|
if cc:
|
||||||
print cc
|
print(cc)
|
||||||
fd.close()
|
fd.close()
|
||||||
|
|
||||||
elif options.full_help:
|
elif options.full_help:
|
||||||
|
@ -166,12 +166,12 @@ else:
|
||||||
options.dry_run, not options.ignore_bad_tags, cc_file,
|
options.dry_run, not options.ignore_bad_tags, cc_file,
|
||||||
in_reply_to=options.in_reply_to, thread=options.thread)
|
in_reply_to=options.in_reply_to, thread=options.thread)
|
||||||
else:
|
else:
|
||||||
print col.Color(col.RED, "Not sending emails due to errors/warnings")
|
print(col.Color(col.RED, "Not sending emails due to errors/warnings"))
|
||||||
|
|
||||||
# For a dry run, just show our actions as a sanity check
|
# For a dry run, just show our actions as a sanity check
|
||||||
if options.dry_run:
|
if options.dry_run:
|
||||||
series.ShowActions(args, cmd, options.process_tags)
|
series.ShowActions(args, cmd, options.process_tags)
|
||||||
if not its_a_go:
|
if not its_a_go:
|
||||||
print col.Color(col.RED, "Email would not be sent")
|
print(col.Color(col.RED, "Email would not be sent"))
|
||||||
|
|
||||||
os.remove(cc_file)
|
os.remove(cc_file)
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
# SPDX-License-Identifier: GPL-2.0+
|
# SPDX-License-Identifier: GPL-2.0+
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import itertools
|
import itertools
|
||||||
import os
|
import os
|
||||||
|
|
||||||
|
@ -101,38 +103,38 @@ class Series(dict):
|
||||||
cc_set = set(gitutil.BuildEmailList(self.cc));
|
cc_set = set(gitutil.BuildEmailList(self.cc));
|
||||||
|
|
||||||
col = terminal.Color()
|
col = terminal.Color()
|
||||||
print 'Dry run, so not doing much. But I would do this:'
|
print('Dry run, so not doing much. But I would do this:')
|
||||||
print
|
print()
|
||||||
print 'Send a total of %d patch%s with %scover letter.' % (
|
print('Send a total of %d patch%s with %scover letter.' % (
|
||||||
len(args), '' if len(args) == 1 else 'es',
|
len(args), '' if len(args) == 1 else 'es',
|
||||||
self.get('cover') and 'a ' or 'no ')
|
self.get('cover') and 'a ' or 'no '))
|
||||||
|
|
||||||
# TODO: Colour the patches according to whether they passed checks
|
# TODO: Colour the patches according to whether they passed checks
|
||||||
for upto in range(len(args)):
|
for upto in range(len(args)):
|
||||||
commit = self.commits[upto]
|
commit = self.commits[upto]
|
||||||
print col.Color(col.GREEN, ' %s' % args[upto])
|
print(col.Color(col.GREEN, ' %s' % args[upto]))
|
||||||
cc_list = list(self._generated_cc[commit.patch])
|
cc_list = list(self._generated_cc[commit.patch])
|
||||||
for email in set(cc_list) - to_set - cc_set:
|
for email in set(cc_list) - to_set - cc_set:
|
||||||
if email == None:
|
if email == None:
|
||||||
email = col.Color(col.YELLOW, "<alias '%s' not found>"
|
email = col.Color(col.YELLOW, "<alias '%s' not found>"
|
||||||
% tag)
|
% tag)
|
||||||
if email:
|
if email:
|
||||||
print ' Cc: ',email
|
print(' Cc: ', email)
|
||||||
print
|
print
|
||||||
for item in to_set:
|
for item in to_set:
|
||||||
print 'To:\t ', item
|
print('To:\t ', item)
|
||||||
for item in cc_set - to_set:
|
for item in cc_set - to_set:
|
||||||
print 'Cc:\t ', item
|
print('Cc:\t ', item)
|
||||||
print 'Version: ', self.get('version')
|
print('Version: ', self.get('version'))
|
||||||
print 'Prefix:\t ', self.get('prefix')
|
print('Prefix:\t ', self.get('prefix'))
|
||||||
if self.cover:
|
if self.cover:
|
||||||
print 'Cover: %d lines' % len(self.cover)
|
print('Cover: %d lines' % len(self.cover))
|
||||||
cover_cc = gitutil.BuildEmailList(self.get('cover_cc', ''))
|
cover_cc = gitutil.BuildEmailList(self.get('cover_cc', ''))
|
||||||
all_ccs = itertools.chain(cover_cc, *self._generated_cc.values())
|
all_ccs = itertools.chain(cover_cc, *self._generated_cc.values())
|
||||||
for email in set(all_ccs) - to_set - cc_set:
|
for email in set(all_ccs) - to_set - cc_set:
|
||||||
print ' Cc: ',email
|
print(' Cc: ', email)
|
||||||
if cmd:
|
if cmd:
|
||||||
print 'Git command: %s' % cmd
|
print('Git command: %s' % cmd)
|
||||||
|
|
||||||
def MakeChangeLog(self, commit):
|
def MakeChangeLog(self, commit):
|
||||||
"""Create a list of changes for each version.
|
"""Create a list of changes for each version.
|
||||||
|
@ -191,13 +193,13 @@ class Series(dict):
|
||||||
else:
|
else:
|
||||||
if version > 1:
|
if version > 1:
|
||||||
str = 'Change log missing for v%d' % version
|
str = 'Change log missing for v%d' % version
|
||||||
print col.Color(col.RED, str)
|
print(col.Color(col.RED, str))
|
||||||
for version in changes_copy:
|
for version in changes_copy:
|
||||||
str = 'Change log for unknown version v%d' % version
|
str = 'Change log for unknown version v%d' % version
|
||||||
print col.Color(col.RED, str)
|
print(col.Color(col.RED, str))
|
||||||
elif self.changes:
|
elif self.changes:
|
||||||
str = 'Change log exists, but no version is set'
|
str = 'Change log exists, but no version is set'
|
||||||
print col.Color(col.RED, str)
|
print(col.Color(col.RED, str))
|
||||||
|
|
||||||
def MakeCcFile(self, process_tags, cover_fname, raise_on_error,
|
def MakeCcFile(self, process_tags, cover_fname, raise_on_error,
|
||||||
add_maintainers):
|
add_maintainers):
|
||||||
|
@ -228,12 +230,12 @@ class Series(dict):
|
||||||
if add_maintainers:
|
if add_maintainers:
|
||||||
list += get_maintainer.GetMaintainer(commit.patch)
|
list += get_maintainer.GetMaintainer(commit.patch)
|
||||||
all_ccs += list
|
all_ccs += list
|
||||||
print >>fd, commit.patch, ', '.join(set(list))
|
print(commit.patch, ', '.join(set(list)), file=fd)
|
||||||
self._generated_cc[commit.patch] = list
|
self._generated_cc[commit.patch] = list
|
||||||
|
|
||||||
if cover_fname:
|
if cover_fname:
|
||||||
cover_cc = gitutil.BuildEmailList(self.get('cover_cc', ''))
|
cover_cc = gitutil.BuildEmailList(self.get('cover_cc', ''))
|
||||||
print >>fd, cover_fname, ', '.join(set(cover_cc + all_ccs))
|
print(cover_fname, ', '.join(set(cover_cc + all_ccs)), file=fd)
|
||||||
|
|
||||||
fd.close()
|
fd.close()
|
||||||
return fname
|
return fname
|
||||||
|
|
|
@ -3,6 +3,8 @@
|
||||||
# SPDX-License-Identifier: GPL-2.0+
|
# SPDX-License-Identifier: GPL-2.0+
|
||||||
#
|
#
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import ConfigParser
|
import ConfigParser
|
||||||
import os
|
import os
|
||||||
import re
|
import re
|
||||||
|
@ -156,7 +158,7 @@ def ReadGitAliases(fname):
|
||||||
try:
|
try:
|
||||||
fd = open(fname, 'r')
|
fd = open(fname, 'r')
|
||||||
except IOError:
|
except IOError:
|
||||||
print "Warning: Cannot find alias file '%s'" % fname
|
print("Warning: Cannot find alias file '%s'" % fname)
|
||||||
return
|
return
|
||||||
|
|
||||||
re_line = re.compile('alias\s+(\S+)\s+(.*)')
|
re_line = re.compile('alias\s+(\S+)\s+(.*)')
|
||||||
|
@ -167,7 +169,7 @@ def ReadGitAliases(fname):
|
||||||
|
|
||||||
m = re_line.match(line)
|
m = re_line.match(line)
|
||||||
if not m:
|
if not m:
|
||||||
print "Warning: Alias file line '%s' not understood" % line
|
print("Warning: Alias file line '%s' not understood" % line)
|
||||||
continue
|
continue
|
||||||
|
|
||||||
list = alias.get(m.group(1), [])
|
list = alias.get(m.group(1), [])
|
||||||
|
@ -200,10 +202,10 @@ def CreatePatmanConfigFile(config_fname):
|
||||||
try:
|
try:
|
||||||
f = open(config_fname, 'w')
|
f = open(config_fname, 'w')
|
||||||
except IOError:
|
except IOError:
|
||||||
print "Couldn't create patman config file\n"
|
print("Couldn't create patman config file\n")
|
||||||
raise
|
raise
|
||||||
|
|
||||||
print >>f, "[alias]\nme: %s <%s>" % (name, email)
|
print("[alias]\nme: %s <%s>" % (name, email), file=f)
|
||||||
f.close();
|
f.close();
|
||||||
|
|
||||||
def _UpdateDefaults(parser, config):
|
def _UpdateDefaults(parser, config):
|
||||||
|
@ -233,7 +235,7 @@ def _UpdateDefaults(parser, config):
|
||||||
val = config.getint('settings', name)
|
val = config.getint('settings', name)
|
||||||
parser.set_default(name, val)
|
parser.set_default(name, val)
|
||||||
else:
|
else:
|
||||||
print "WARNING: Unknown setting %s" % name
|
print("WARNING: Unknown setting %s" % name)
|
||||||
|
|
||||||
def _ReadAliasFile(fname):
|
def _ReadAliasFile(fname):
|
||||||
"""Read in the U-Boot git alias file if it exists.
|
"""Read in the U-Boot git alias file if it exists.
|
||||||
|
@ -258,7 +260,7 @@ def _ReadAliasFile(fname):
|
||||||
continue
|
continue
|
||||||
alias[words[1]] = [s.strip() for s in words[2].split(',')]
|
alias[words[1]] = [s.strip() for s in words[2].split(',')]
|
||||||
if bad_line:
|
if bad_line:
|
||||||
print bad_line
|
print(bad_line)
|
||||||
|
|
||||||
def Setup(parser, project_name, config_fname=''):
|
def Setup(parser, project_name, config_fname=''):
|
||||||
"""Set up the settings module by reading config files.
|
"""Set up the settings module by reading config files.
|
||||||
|
@ -276,7 +278,7 @@ def Setup(parser, project_name, config_fname=''):
|
||||||
config_fname = '%s/.patman' % os.getenv('HOME')
|
config_fname = '%s/.patman' % os.getenv('HOME')
|
||||||
|
|
||||||
if not os.path.exists(config_fname):
|
if not os.path.exists(config_fname):
|
||||||
print "No config file found ~/.patman\nCreating one...\n"
|
print("No config file found ~/.patman\nCreating one...\n")
|
||||||
CreatePatmanConfigFile(config_fname)
|
CreatePatmanConfigFile(config_fname)
|
||||||
|
|
||||||
config.read(config_fname)
|
config.read(config_fname)
|
||||||
|
|
|
@ -8,6 +8,8 @@
|
||||||
This module handles terminal interaction including ANSI color codes.
|
This module handles terminal interaction including ANSI color codes.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
from __future__ import print_function
|
||||||
|
|
||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
|
|
||||||
|
@ -52,9 +54,9 @@ def Print(text='', newline=True, colour=None):
|
||||||
if colour:
|
if colour:
|
||||||
col = Color()
|
col = Color()
|
||||||
text = col.Color(colour, text)
|
text = col.Color(colour, text)
|
||||||
print text,
|
print(text, end='')
|
||||||
if newline:
|
if newline:
|
||||||
print
|
print()
|
||||||
else:
|
else:
|
||||||
sys.stdout.flush()
|
sys.stdout.flush()
|
||||||
|
|
||||||
|
@ -81,11 +83,11 @@ def EchoPrintTestLines():
|
||||||
for line in print_test_list:
|
for line in print_test_list:
|
||||||
if line.colour:
|
if line.colour:
|
||||||
col = Color()
|
col = Color()
|
||||||
print col.Color(line.colour, line.text),
|
print(col.Color(line.colour, line.text), end='')
|
||||||
else:
|
else:
|
||||||
print line.text,
|
print(line.text, end='')
|
||||||
if line.newline:
|
if line.newline:
|
||||||
print
|
print()
|
||||||
|
|
||||||
|
|
||||||
class Color(object):
|
class Color(object):
|
||||||
|
|
|
@ -181,7 +181,7 @@ index 0000000..2234c87
|
||||||
elif data_type == 'indent':
|
elif data_type == 'indent':
|
||||||
indent = tab
|
indent = tab
|
||||||
else:
|
else:
|
||||||
print 'not implemented'
|
print('not implemented')
|
||||||
return data % (signoff, tab, indent, tab)
|
return data % (signoff, tab, indent, tab)
|
||||||
|
|
||||||
def SetupData(self, data_type):
|
def SetupData(self, data_type):
|
||||||
|
|
Loading…
Reference in New Issue