diff options
Diffstat (limited to 'tools')
-rw-r--r-- | tools/buildman/README | 9 | ||||
-rw-r--r-- | tools/buildman/builder.py | 33 | ||||
-rw-r--r-- | tools/buildman/builderthread.py | 16 | ||||
-rwxr-xr-x | tools/buildman/buildman.py | 2 | ||||
-rw-r--r-- | tools/buildman/test.py | 4 | ||||
-rw-r--r-- | tools/buildman/toolchain.py | 18 | ||||
-rwxr-xr-x | tools/dtoc/dtoc.py | 10 | ||||
-rw-r--r-- | tools/dtoc/fdt_fallback.py | 4 | ||||
-rw-r--r-- | tools/dtoc/fdt_normal.py | 9 | ||||
-rw-r--r-- | tools/dtoc/fdt_select.py | 16 | ||||
-rw-r--r-- | tools/dtoc/fdt_util.py | 3 | ||||
-rw-r--r-- | tools/patman/checkpatch.py | 16 | ||||
-rw-r--r-- | tools/patman/command.py | 2 | ||||
-rw-r--r-- | tools/patman/cros_subprocess.py | 2 | ||||
-rw-r--r-- | tools/patman/get_maintainer.py | 2 | ||||
-rw-r--r-- | tools/patman/gitutil.py | 18 | ||||
-rw-r--r-- | tools/patman/patchstream.py | 6 | ||||
-rwxr-xr-x | tools/patman/patman.py | 12 | ||||
-rw-r--r-- | tools/patman/series.py | 42 | ||||
-rw-r--r-- | tools/patman/settings.py | 37 | ||||
-rw-r--r-- | tools/patman/terminal.py | 14 | ||||
-rw-r--r-- | tools/patman/test.py | 2 |
22 files changed, 162 insertions, 115 deletions
diff --git a/tools/buildman/README b/tools/buildman/README index 8c5f8610d0..514bebc9f8 100644 --- a/tools/buildman/README +++ b/tools/buildman/README @@ -211,6 +211,15 @@ arm: arm-none-eabi- and buildman will find arm-none-eabi-gcc in /usr/bin if you have it installed. +[toolchain-wrapper] +wrapper: ccache + +This tells buildman to use a compiler wrapper in front of CROSS_COMPILE. In +this example, ccache. It doesn't affect the toolchain scan. The wrapper is +added when CROSS_COMPILE environtal variable is set. The name in this +section is ignored. If more than one line is provided, only the last one +is taken. + 3. Make sure you have the require Python pre-requisites Buildman uses multiprocessing, Queue, shutil, StringIO, ConfigParser and diff --git a/tools/buildman/builder.py b/tools/buildman/builder.py index 8ec3551729..e27a28577c 100644 --- a/tools/buildman/builder.py +++ b/tools/buildman/builder.py @@ -12,8 +12,10 @@ import os import re import Queue import shutil +import signal import string import sys +import threading import time import builderthread @@ -126,7 +128,6 @@ class Builder: """Class for building U-Boot for a particular commit. Public members: (many should ->private) - active: True if the builder is active and has not been stopped already_done: Number of builds already completed base_dir: Base directory to use for builder checkout: True to check out source, False to skip that step. @@ -234,7 +235,6 @@ class Builder: self.base_dir = base_dir self._working_dir = os.path.join(base_dir, '.bm-work') self.threads = [] - self.active = True self.do_make = self.Make self.gnu_make = gnu_make self.checkout = checkout @@ -283,11 +283,17 @@ class Builder: ignore_lines = ['(make.*Waiting for unfinished)', '(Segmentation fault)'] self.re_make_err = re.compile('|'.join(ignore_lines)) + # Handle existing graceful with SIGINT / Ctrl-C + signal.signal(signal.SIGINT, self.signal_handler) + def __del__(self): """Get rid of all threads created by the builder""" for t in self.threads: del t + def signal_handler(self, signal, frame): + sys.exit(1) + def SetDisplayOptions(self, show_errors=False, show_sizes=False, show_detail=False, show_bloat=False, list_error_boards=False, show_config=False): @@ -389,11 +395,6 @@ class Builder: if result: target = result.brd.target - if result.return_code < 0: - self.active = False - command.StopAll() - return - self.upto += 1 if result.return_code != 0: self.fail += 1 @@ -1366,8 +1367,10 @@ class Builder: if os.path.exists(git_dir): gitutil.Fetch(git_dir, thread_dir) else: - Print('Cloning repo for thread %d' % thread_num) + Print('\rCloning repo for thread %d' % thread_num, + newline=False) gitutil.Clone(src_dir, thread_dir) + Print('\r%s\r' % (' ' * 30), newline=False) def _PrepareWorkingSpace(self, max_threads, setup_git): """Prepare the working directory for use. @@ -1395,8 +1398,14 @@ class Builder: for commit_upto in range(self.commit_count): dir_list.append(self._GetOutputDir(commit_upto)) + to_remove = [] for dirname in glob.glob(os.path.join(self.base_dir, '*')): if dirname not in dir_list: + to_remove.append(dirname) + if to_remove: + Print('Removing %d old build directories' % len(to_remove), + newline=False) + for dirname in to_remove: shutil.rmtree(dirname) def BuildBoards(self, commits, board_selected, keep_outputs, verbose): @@ -1422,6 +1431,7 @@ class Builder: self._PrepareWorkingSpace(min(self.num_threads, len(board_selected)), commits is not None) self._PrepareOutputSpace() + Print('\rStarting build...', newline=False) self.SetupBuild(board_selected, commits) self.ProcessResult(None) @@ -1434,8 +1444,11 @@ class Builder: job.step = self._step self.queue.put(job) - # Wait until all jobs are started - self.queue.join() + term = threading.Thread(target=self.queue.join) + term.setDaemon(True) + term.start() + while term.isAlive(): + term.join(100) # Wait until we have processed all output self.out_queue.join() diff --git a/tools/buildman/builderthread.py b/tools/buildman/builderthread.py index c512d3b521..8974351225 100644 --- a/tools/buildman/builderthread.py +++ b/tools/buildman/builderthread.py @@ -304,10 +304,6 @@ class BuilderThread(threading.Thread): print >>fd, 'arch', result.toolchain.arch fd.write('%s' % result.return_code) - with open(os.path.join(build_dir, 'toolchain'), 'w') as fd: - print >>fd, 'gcc', result.toolchain.gcc - print >>fd, 'path', result.toolchain.path - # Write out the image and function size information and an objdump env = result.toolchain.MakeEnvironment(self.builder.full_path) lines = [] @@ -470,17 +466,7 @@ class BuilderThread(threading.Thread): This thread picks a job from the queue, runs it, and then goes to the next job. """ - alive = True while True: job = self.builder.queue.get() - if self.builder.active and alive: - self.RunJob(job) - ''' - try: - if self.builder.active and alive: - self.RunJob(job) - except Exception as err: - alive = False - print err - ''' + self.RunJob(job) self.builder.queue.task_done() diff --git a/tools/buildman/buildman.py b/tools/buildman/buildman.py index d0afeda6c0..607429df7b 100755 --- a/tools/buildman/buildman.py +++ b/tools/buildman/buildman.py @@ -15,7 +15,7 @@ import unittest # Bring in the patman libraries our_path = os.path.dirname(os.path.realpath(__file__)) -sys.path.append(os.path.join(our_path, '../patman')) +sys.path.insert(1, os.path.join(our_path, '../patman')) # Our modules import board diff --git a/tools/buildman/test.py b/tools/buildman/test.py index d8f3c81fad..ed2a3a8929 100644 --- a/tools/buildman/test.py +++ b/tools/buildman/test.py @@ -198,9 +198,9 @@ class TestBuild(unittest.TestCase): if line.text.strip(): count += 1 - # We should get one starting message, then an update for every commit + # We should get two starting messages, then an update for every commit # built. - self.assertEqual(count, len(commits) * len(boards) + 1) + self.assertEqual(count, len(commits) * len(boards) + 2) build.SetDisplayOptions(show_errors=True); build.ShowSummary(self.commits, board_selected) #terminal.EchoPrintTestLines() diff --git a/tools/buildman/toolchain.py b/tools/buildman/toolchain.py index 41e4e4c535..4778876201 100644 --- a/tools/buildman/toolchain.py +++ b/tools/buildman/toolchain.py @@ -127,6 +127,18 @@ class Toolchain: return PRIORITY_CALC + prio return PRIORITY_CALC + prio + def GetWrapper(self, show_warning=True): + """Get toolchain wrapper from the setting file. + """ + value = '' + for name, value in bsettings.GetItems('toolchain-wrapper'): + if not value: + print "Warning: Wrapper not found" + if value: + value = value + ' ' + + return value + def MakeEnvironment(self, full_path): """Returns an environment for using the toolchain. @@ -138,10 +150,12 @@ class Toolchain: PATH """ env = dict(os.environ) + wrapper = self.GetWrapper() + if full_path: - env['CROSS_COMPILE'] = os.path.join(self.path, self.cross) + env['CROSS_COMPILE'] = wrapper + os.path.join(self.path, self.cross) else: - env['CROSS_COMPILE'] = self.cross + env['CROSS_COMPILE'] = wrapper + self.cross env['PATH'] = self.path + ':' + env['PATH'] return env diff --git a/tools/dtoc/dtoc.py b/tools/dtoc/dtoc.py index 518aa51216..11050b66f7 100755 --- a/tools/dtoc/dtoc.py +++ b/tools/dtoc/dtoc.py @@ -60,7 +60,7 @@ def Conv_name_to_c(name): def TabTo(num_tabs, str): if len(str) >= num_tabs * 8: return str + ' ' - return str + '\t' * (num_tabs - len(str) / 8) + return str + '\t' * (num_tabs - len(str) // 8) class DtbPlatdata: """Provide a means to convert device tree binary data to platform data @@ -224,14 +224,14 @@ class DtbPlatdata: fields = {} # Get a list of all the valid properties in this node. - for name, prop in node.props.iteritems(): + for name, prop in node.props.items(): if name not in PROP_IGNORE_LIST and name[0] != '#': fields[name] = copy.deepcopy(prop) # If we've seen this node_name before, update the existing struct. if node_name in structs: struct = structs[node_name] - for name, prop in fields.iteritems(): + for name, prop in fields.items(): oldprop = struct.get(name) if oldprop: oldprop.Widen(prop) @@ -246,7 +246,7 @@ class DtbPlatdata: for node in self._valid_nodes: node_name = self.GetCompatName(node) struct = structs[node_name] - for name, prop in node.props.iteritems(): + for name, prop in node.props.items(): if name not in PROP_IGNORE_LIST and name[0] != '#': prop.Widen(struct[name]) upto += 1 @@ -298,7 +298,7 @@ class DtbPlatdata: var_name = Conv_name_to_c(node.name) self.Buf('static struct %s%s %s%s = {\n' % (STRUCT_PREFIX, struct_name, VAL_PREFIX, var_name)) - for pname, prop in node.props.iteritems(): + for pname, prop in node.props.items(): if pname in PROP_IGNORE_LIST or pname[0] == '#': continue ptype = TYPE_NAMES[prop.type] diff --git a/tools/dtoc/fdt_fallback.py b/tools/dtoc/fdt_fallback.py index 0c0ebbcf47..23e26796c8 100644 --- a/tools/dtoc/fdt_fallback.py +++ b/tools/dtoc/fdt_fallback.py @@ -58,7 +58,7 @@ class Node(NodeBase): This fills in the props and subnodes properties, recursively searching into subnodes so that the entire tree is built. """ - for name, byte_list_str in self._fdt.GetProps(self.path).iteritems(): + for name, byte_list_str in self._fdt.GetProps(self.path).items(): prop = Prop(self, name, byte_list_str) self.props[name] = prop @@ -160,7 +160,7 @@ class FdtFallback(Fdt): if default is not None: args += ['-d', str(default)] if typespec is not None: - args += ['-t%s' % typespec] + args += ['-t', typespec] out = command.Output('fdtget', *args) return out.strip() diff --git a/tools/dtoc/fdt_normal.py b/tools/dtoc/fdt_normal.py index aae258e412..cce5c06d8c 100644 --- a/tools/dtoc/fdt_normal.py +++ b/tools/dtoc/fdt_normal.py @@ -81,7 +81,7 @@ class Node(NodeBase): This fills in the props and subnodes properties, recursively searching into subnodes so that the entire tree is built. """ - self.props = self._fdt.GetProps(self, self.path) + self.props = self._fdt.GetProps(self) offset = libfdt.fdt_first_subnode(self._fdt.GetFdt(), self.Offset()) while offset >= 0: @@ -159,7 +159,7 @@ class FdtNormal(Fdt): fdt_len = libfdt.fdt_totalsize(self._fdt) del self._fdt[fdt_len:] - def GetProps(self, node, path): + def GetProps(self, node): """Get all properties from a node. Args: @@ -172,11 +172,8 @@ class FdtNormal(Fdt): Raises: ValueError: if the node does not exist. """ - offset = libfdt.fdt_path_offset(self._fdt, path) - if offset < 0: - libfdt.Raise(offset) props_dict = {} - poffset = libfdt.fdt_first_property_offset(self._fdt, offset) + poffset = libfdt.fdt_first_property_offset(self._fdt, node._offset) while poffset >= 0: dprop, plen = libfdt.fdt_get_property_by_offset(self._fdt, poffset) prop = Prop(node, poffset, libfdt.String(self._fdt, dprop.nameoff), diff --git a/tools/dtoc/fdt_select.py b/tools/dtoc/fdt_select.py index 18a36d88a0..ea78c527fc 100644 --- a/tools/dtoc/fdt_select.py +++ b/tools/dtoc/fdt_select.py @@ -6,6 +6,8 @@ # SPDX-License-Identifier: GPL-2.0+ # +import fdt_fallback + # Bring in either the normal fdt library (which relies on libfdt) or the # fallback one (which uses fdtget and is slower). Both provide the same # interface for this file to use. @@ -14,13 +16,21 @@ try: have_libfdt = True except ImportError: have_libfdt = False - import fdt_fallback -def FdtScan(fname): +force_fallback = False + +def FdtScan(fname, _force_fallback=False): """Returns a new Fdt object from the implementation we are using""" - if have_libfdt: + if have_libfdt and not force_fallback and not _force_fallback: dtb = fdt_normal.FdtNormal(fname) else: dtb = fdt_fallback.FdtFallback(fname) dtb.Scan() return dtb + +def UseFallback(fallback): + global force_fallback + + old_val = force_fallback + force_fallback = fallback + return old_val diff --git a/tools/dtoc/fdt_util.py b/tools/dtoc/fdt_util.py index 3a10838109..e6d523b9de 100644 --- a/tools/dtoc/fdt_util.py +++ b/tools/dtoc/fdt_util.py @@ -8,6 +8,7 @@ import os import struct +import sys import tempfile import command @@ -22,6 +23,8 @@ def fdt32_to_cpu(val): Return: A native-endian integer value """ + if sys.version_info > (3, 0): + val = val.encode('raw_unicode_escape') return struct.unpack('>I', val)[0] def EnsureCompiled(fname): diff --git a/tools/patman/checkpatch.py b/tools/patman/checkpatch.py index 3eef6de221..be78fc510b 100644 --- a/tools/patman/checkpatch.py +++ b/tools/patman/checkpatch.py @@ -83,7 +83,7 @@ def CheckPatch(fname, verbose=False): for line in result.stdout.splitlines(): if verbose: - print line + print(line) # A blank line indicates the end of a message if not line and item: @@ -151,17 +151,17 @@ def CheckPatches(verbose, args): error_count += result.errors warning_count += result.warnings check_count += result.checks - print '%d errors, %d warnings, %d checks for %s:' % (result.errors, - result.warnings, result.checks, col.Color(col.BLUE, fname)) + print('%d errors, %d warnings, %d checks for %s:' % (result.errors, + result.warnings, result.checks, col.Color(col.BLUE, fname))) if (len(result.problems) != result.errors + result.warnings + result.checks): - print "Internal error: some problems lost" + print("Internal error: some problems lost") 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('line', 0), item.get('msg', 'message')) + item.get('line', 0), item.get('msg', 'message'))) print - #print stdout + #print(stdout) if error_count or warning_count or check_count: str = 'checkpatch.pl found %d error(s), %d warning(s), %d checks(s)' color = col.GREEN @@ -169,6 +169,6 @@ def CheckPatches(verbose, args): color = col.YELLOW if error_count: 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 True diff --git a/tools/patman/command.py b/tools/patman/command.py index d1f0ca505c..bebc495b59 100644 --- a/tools/patman/command.py +++ b/tools/patman/command.py @@ -85,7 +85,7 @@ def RunPipe(pipe_list, infile=None, outfile=None, try: last_pipe = cros_subprocess.Popen(cmd, cwd=cwd, **kwargs) - except Exception, err: + except Exception as err: result.exception = err if raise_on_error: raise Exception("Error running '%s': %s" % (user_pipestr, str)) diff --git a/tools/patman/cros_subprocess.py b/tools/patman/cros_subprocess.py index 0fc4a06b50..ebd4300dfd 100644 --- a/tools/patman/cros_subprocess.py +++ b/tools/patman/cros_subprocess.py @@ -166,7 +166,7 @@ class Popen(subprocess.Popen): while read_set or write_set: try: rlist, wlist, _ = select.select(read_set, write_set, [], 0.2) - except select.error, e: + except select.error as e: if e.args[0] == errno.EINTR: continue raise diff --git a/tools/patman/get_maintainer.py b/tools/patman/get_maintainer.py index 00b49394bc..2deb5db6ec 100644 --- a/tools/patman/get_maintainer.py +++ b/tools/patman/get_maintainer.py @@ -40,7 +40,7 @@ def GetMaintainer(fname, verbose=False): get_maintainer = FindGetMaintainer() if not get_maintainer: if verbose: - print "WARNING: Couldn't find get_maintainer.pl" + print("WARNING: Couldn't find get_maintainer.pl") return [] stdout = command.Output(get_maintainer, '--norolestats', fname) diff --git a/tools/patman/gitutil.py b/tools/patman/gitutil.py index bb7c9e08bc..0d23079a3a 100644 --- a/tools/patman/gitutil.py +++ b/tools/patman/gitutil.py @@ -139,7 +139,7 @@ def GetUpstream(git_dir, branch): leaf = merge.split('/')[-1] return '%s/%s' % (remote, leaf), None else: - raise ValueError, ("Cannot determine upstream branch for branch " + raise ValueError("Cannot determine upstream branch for branch " "'%s' remote='%s', merge='%s'" % (branch, remote, merge)) @@ -224,7 +224,7 @@ def Checkout(commit_hash, git_dir=None, work_tree=None, force=False): result = command.RunPipe([pipe], capture=True, raise_on_error=False, capture_stderr=True) if result.return_code != 0: - raise OSError, 'git checkout (%s): %s' % (pipe, result.stderr) + raise OSError('git checkout (%s): %s' % (pipe, result.stderr)) def Clone(git_dir, output_dir): """Checkout the selected commit for this build @@ -236,7 +236,7 @@ def Clone(git_dir, output_dir): result = command.RunPipe([pipe], capture=True, cwd=output_dir, capture_stderr=True) if result.return_code != 0: - raise OSError, 'git clone: %s' % result.stderr + raise OSError('git clone: %s' % result.stderr) def Fetch(git_dir=None, work_tree=None): """Fetch from the origin repo @@ -252,7 +252,7 @@ def Fetch(git_dir=None, work_tree=None): pipe.append('fetch') result = command.RunPipe([pipe], capture=True, capture_stderr=True) if result.return_code != 0: - raise OSError, 'git fetch: %s' % result.stderr + raise OSError('git fetch: %s' % result.stderr) def CreatePatches(start, count, series): """Create a series of patches from the top of the current branch. @@ -489,18 +489,18 @@ def LookupEmail(lookup_name, alias=None, raise_on_error=True, level=0): if level > 10: msg = "Recursive email alias at '%s'" % lookup_name if raise_on_error: - raise OSError, msg + raise OSError(msg) else: - print col.Color(col.RED, msg) + print(col.Color(col.RED, msg)) return out_list if lookup_name: if not lookup_name in alias: msg = "Alias '%s' not found" % lookup_name if raise_on_error: - raise ValueError, msg + raise ValueError(msg) else: - print col.Color(col.RED, msg) + print(col.Color(col.RED, msg)) return out_list for item in alias[lookup_name]: 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: out_list.append(new_item) - #print "No match for alias '%s'" % lookup_name + #print("No match for alias '%s'" % lookup_name) return out_list def GetTopLevel(): diff --git a/tools/patman/patchstream.py b/tools/patman/patchstream.py index 69d5cfb7a8..cd4667f61c 100644 --- a/tools/patman/patchstream.py +++ b/tools/patman/patchstream.py @@ -480,12 +480,12 @@ def FixPatches(series, fnames): commit.patch = fname result = FixPatch(backup_dir, fname, series, commit) if result: - print '%d warnings for %s:' % (len(result), fname) + print('%d warnings for %s:' % (len(result), fname)) for warn in result: - print '\t', warn + print('\t', warn) print count += 1 - print 'Cleaned %d patches' % count + print('Cleaned %d patches' % count) return series def InsertCoverLetter(fname, series, count): diff --git a/tools/patman/patman.py b/tools/patman/patman.py index fe50eb4d5c..fdbee67f55 100755 --- a/tools/patman/patman.py +++ b/tools/patman/patman.py @@ -93,11 +93,11 @@ elif options.test: suite.run(result) # TODO: Surely we can just 'print' result? - print result + print(result) for test, err in result.errors: - print err + print(err) for test, err in result.failures: - print err + print(err) # Called from git with a patch filename as argument # 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(', '): cc = cc.strip() if cc: - print cc + print(cc) fd.close() elif options.full_help: @@ -166,12 +166,12 @@ else: options.dry_run, not options.ignore_bad_tags, cc_file, in_reply_to=options.in_reply_to, thread=options.thread) 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 if options.dry_run: series.ShowActions(args, cmd, options.process_tags) 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) diff --git a/tools/patman/series.py b/tools/patman/series.py index cc6f80b2fd..38a452edad 100644 --- a/tools/patman/series.py +++ b/tools/patman/series.py @@ -3,6 +3,8 @@ # SPDX-License-Identifier: GPL-2.0+ # +from __future__ import print_function + import itertools import os @@ -101,38 +103,38 @@ class Series(dict): cc_set = set(gitutil.BuildEmailList(self.cc)); col = terminal.Color() - print 'Dry run, so not doing much. But I would do this:' - print - print 'Send a total of %d patch%s with %scover letter.' % ( + print('Dry run, so not doing much. But I would do this:') + print() + print('Send a total of %d patch%s with %scover letter.' % ( 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 for upto in range(len(args)): 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]) for email in set(cc_list) - to_set - cc_set: if email == None: email = col.Color(col.YELLOW, "<alias '%s' not found>" % tag) if email: - print ' Cc: ',email + print(' Cc: ', email) print for item in to_set: - print 'To:\t ', item + print('To:\t ', item) for item in cc_set - to_set: - print 'Cc:\t ', item - print 'Version: ', self.get('version') - print 'Prefix:\t ', self.get('prefix') + print('Cc:\t ', item) + print('Version: ', self.get('version')) + print('Prefix:\t ', self.get('prefix')) 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', '')) all_ccs = itertools.chain(cover_cc, *self._generated_cc.values()) for email in set(all_ccs) - to_set - cc_set: - print ' Cc: ',email + print(' Cc: ', email) if cmd: - print 'Git command: %s' % cmd + print('Git command: %s' % cmd) def MakeChangeLog(self, commit): """Create a list of changes for each version. @@ -191,13 +193,13 @@ class Series(dict): else: if version > 1: 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: str = 'Change log for unknown version v%d' % version - print col.Color(col.RED, str) + print(col.Color(col.RED, str)) elif self.changes: 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, add_maintainers): @@ -225,15 +227,15 @@ class Series(dict): raise_on_error=raise_on_error) list += gitutil.BuildEmailList(commit.cc_list, raise_on_error=raise_on_error) - if add_maintainers: + if add_maintainers: list += get_maintainer.GetMaintainer(commit.patch) all_ccs += list - print >>fd, commit.patch, ', '.join(set(list)) + print(commit.patch, ', '.join(set(list)), file=fd) self._generated_cc[commit.patch] = list if cover_fname: 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() return fname @@ -259,7 +261,7 @@ class Series(dict): """ git_prefix = gitutil.GetDefaultSubjectPrefix() if git_prefix: - git_prefix = '%s][' % git_prefix + git_prefix = '%s][' % git_prefix else: git_prefix = '' diff --git a/tools/patman/settings.py b/tools/patman/settings.py index ba2a68ff63..5f207f5ef1 100644 --- a/tools/patman/settings.py +++ b/tools/patman/settings.py @@ -3,7 +3,13 @@ # SPDX-License-Identifier: GPL-2.0+ # -import ConfigParser +from __future__ import print_function + +try: + import configparser as ConfigParser +except: + import ConfigParser + import os import re @@ -30,7 +36,10 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser): - Merge general default settings/aliases with project-specific ones. # Sample config used for tests below... - >>> import StringIO + >>> try: + ... from StringIO import StringIO + ... except ImportError: + ... from io import StringIO >>> sample_config = ''' ... [alias] ... me: Peter P. <likesspiders@example.com> @@ -48,25 +57,25 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser): # Check to make sure that bogus project gets general alias. >>> config = _ProjectConfigParser("zzz") - >>> config.readfp(StringIO.StringIO(sample_config)) + >>> config.readfp(StringIO(sample_config)) >>> config.get("alias", "enemies") 'Evil <evil@example.com>' # Check to make sure that alias gets overridden by project. >>> config = _ProjectConfigParser("sm") - >>> config.readfp(StringIO.StringIO(sample_config)) + >>> config.readfp(StringIO(sample_config)) >>> config.get("alias", "enemies") 'Green G. <ugly@example.com>' # Check to make sure that settings get merged with project. >>> config = _ProjectConfigParser("linux") - >>> config.readfp(StringIO.StringIO(sample_config)) + >>> config.readfp(StringIO(sample_config)) >>> sorted(config.items("settings")) [('am_hero', 'True'), ('process_tags', 'False')] # Check to make sure that settings works with unknown project. >>> config = _ProjectConfigParser("unknown") - >>> config.readfp(StringIO.StringIO(sample_config)) + >>> config.readfp(StringIO(sample_config)) >>> sorted(config.items("settings")) [('am_hero', 'True')] """ @@ -88,7 +97,7 @@ class _ProjectConfigParser(ConfigParser.SafeConfigParser): if not self.has_section(project_settings): self.add_section(project_settings) project_defaults = _default_settings.get(project_name, {}) - for setting_name, setting_value in project_defaults.iteritems(): + for setting_name, setting_value in project_defaults.items(): self.set(project_settings, setting_name, setting_value) def get(self, section, option, *args, **kwargs): @@ -156,7 +165,7 @@ def ReadGitAliases(fname): try: fd = open(fname, 'r') except IOError: - print "Warning: Cannot find alias file '%s'" % fname + print("Warning: Cannot find alias file '%s'" % fname) return re_line = re.compile('alias\s+(\S+)\s+(.*)') @@ -167,7 +176,7 @@ def ReadGitAliases(fname): m = re_line.match(line) if not m: - print "Warning: Alias file line '%s' not understood" % line + print("Warning: Alias file line '%s' not understood" % line) continue list = alias.get(m.group(1), []) @@ -200,10 +209,10 @@ def CreatePatmanConfigFile(config_fname): try: f = open(config_fname, 'w') except IOError: - print "Couldn't create patman config file\n" + print("Couldn't create patman config file\n") raise - print >>f, "[alias]\nme: %s <%s>" % (name, email) + print("[alias]\nme: %s <%s>" % (name, email), file=f) f.close(); def _UpdateDefaults(parser, config): @@ -233,7 +242,7 @@ def _UpdateDefaults(parser, config): val = config.getint('settings', name) parser.set_default(name, val) else: - print "WARNING: Unknown setting %s" % name + print("WARNING: Unknown setting %s" % name) def _ReadAliasFile(fname): """Read in the U-Boot git alias file if it exists. @@ -258,7 +267,7 @@ def _ReadAliasFile(fname): continue alias[words[1]] = [s.strip() for s in words[2].split(',')] if bad_line: - print bad_line + print(bad_line) def Setup(parser, project_name, config_fname=''): """Set up the settings module by reading config files. @@ -276,7 +285,7 @@ def Setup(parser, project_name, config_fname=''): config_fname = '%s/.patman' % os.getenv('HOME') 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) config.read(config_fname) diff --git a/tools/patman/terminal.py b/tools/patman/terminal.py index e78a7c14f5..137265fc81 100644 --- a/tools/patman/terminal.py +++ b/tools/patman/terminal.py @@ -8,6 +8,8 @@ This module handles terminal interaction including ANSI color codes. """ +from __future__ import print_function + import os import sys @@ -52,9 +54,11 @@ def Print(text='', newline=True, colour=None): if colour: col = Color() text = col.Color(colour, text) - print text, + print(text, end='') if newline: - print + print() + else: + sys.stdout.flush() def SetPrintTestMode(): """Go into test mode, where all printing is recorded""" @@ -79,11 +83,11 @@ def EchoPrintTestLines(): for line in print_test_list: if line.colour: col = Color() - print col.Color(line.colour, line.text), + print(col.Color(line.colour, line.text), end='') else: - print line.text, + print(line.text, end='') if line.newline: - print + print() class Color(object): diff --git a/tools/patman/test.py b/tools/patman/test.py index e8f7472785..8c39f66e73 100644 --- a/tools/patman/test.py +++ b/tools/patman/test.py @@ -181,7 +181,7 @@ index 0000000..2234c87 elif data_type == 'indent': indent = tab else: - print 'not implemented' + print('not implemented') return data % (signoff, tab, indent, tab) def SetupData(self, data_type): |