patman: Rename Color() method to build()

This method has the same name as its class which is confusing. It is also
annoying when searching the code.

It builds a string with a colour, so rename it to build().

Signed-off-by: Simon Glass <sjg@chromium.org>
This commit is contained in:
Simon Glass 2022-01-29 14:14:17 -07:00
parent 82e0e732ee
commit 252ac58996
11 changed files with 71 additions and 71 deletions

View file

@ -174,7 +174,7 @@ class Bintool:
res = self.fetch(meth) res = self.fetch(meth)
except urllib.error.URLError as uerr: except urllib.error.URLError as uerr:
message = uerr.reason message = uerr.reason
print(col.Color(col.RED, f'- {message}')) print(col.build(col.RED, f'- {message}'))
except ValueError as exc: except ValueError as exc:
print(f'Exception: {exc}') print(f'Exception: {exc}')
@ -182,7 +182,7 @@ class Bintool:
if skip_present and self.is_present(): if skip_present and self.is_present():
return PRESENT return PRESENT
print(col.Color(col.YELLOW, 'Fetch: %s' % self.name)) print(col.build(col.YELLOW, 'Fetch: %s' % self.name))
if method == FETCH_ANY: if method == FETCH_ANY:
for try_method in range(1, FETCH_COUNT): for try_method in range(1, FETCH_COUNT):
print(f'- trying method: {FETCH_NAMES[try_method]}') print(f'- trying method: {FETCH_NAMES[try_method]}')
@ -216,7 +216,7 @@ class Bintool:
True on success, False on failure True on success, False on failure
""" """
def show_status(color, prompt, names): def show_status(color, prompt, names):
print(col.Color( print(col.build(
color, f'{prompt}:%s{len(names):2}: %s' % color, f'{prompt}:%s{len(names):2}: %s' %
(' ' * (16 - len(prompt)), ' '.join(names)))) (' ' * (16 - len(prompt)), ' '.join(names))))
@ -227,7 +227,7 @@ class Bintool:
name_list = Bintool.get_tool_list() name_list = Bintool.get_tool_list()
if names_to_fetch[0] == 'missing': if names_to_fetch[0] == 'missing':
skip_present = True skip_present = True
print(col.Color(col.YELLOW, print(col.build(col.YELLOW,
'Fetching tools: %s' % ' '.join(name_list))) 'Fetching tools: %s' % ' '.join(name_list)))
status = collections.defaultdict(list) status = collections.defaultdict(list)
for name in name_list: for name in name_list:

View file

@ -518,14 +518,14 @@ class Builder:
# Display separate counts for ok, warned and fail # Display separate counts for ok, warned and fail
ok = self.upto - self.warned - self.fail ok = self.upto - self.warned - self.fail
line = '\r' + self.col.Color(self.col.GREEN, '%5d' % ok) line = '\r' + self.col.build(self.col.GREEN, '%5d' % ok)
line += self.col.Color(self.col.YELLOW, '%5d' % self.warned) line += self.col.build(self.col.YELLOW, '%5d' % self.warned)
line += self.col.Color(self.col.RED, '%5d' % self.fail) line += self.col.build(self.col.RED, '%5d' % self.fail)
line += ' /%-5d ' % self.count line += ' /%-5d ' % self.count
remaining = self.count - self.upto remaining = self.count - self.upto
if remaining: if remaining:
line += self.col.Color(self.col.MAGENTA, ' -%-5d ' % remaining) line += self.col.build(self.col.MAGENTA, ' -%-5d ' % remaining)
else: else:
line += ' ' * 8 line += ' ' * 8
@ -933,9 +933,9 @@ class Builder:
arch = board_dict[target].arch arch = board_dict[target].arch
else: else:
arch = 'unknown' arch = 'unknown'
str = self.col.Color(color, ' ' + target) str = self.col.build(color, ' ' + target)
if not arch in done_arch: if not arch in done_arch:
str = ' %s %s' % (self.col.Color(color, char), str) str = ' %s %s' % (self.col.build(color, char), str)
done_arch[arch] = True done_arch[arch] = True
if not arch in arch_list: if not arch in arch_list:
arch_list[arch] = str arch_list[arch] = str
@ -947,7 +947,7 @@ class Builder:
color = self.col.RED if num > 0 else self.col.GREEN color = self.col.RED if num > 0 else self.col.GREEN
if num == 0: if num == 0:
return '0' return '0'
return self.col.Color(color, str(num)) return self.col.build(color, str(num))
def ResetResultSummary(self, board_selected): def ResetResultSummary(self, board_selected):
"""Reset the results summary ready for use. """Reset the results summary ready for use.
@ -1010,7 +1010,7 @@ class Builder:
args = [self.ColourNum(x) for x in args] args = [self.ColourNum(x) for x in args]
indent = ' ' * 15 indent = ' ' * 15
Tprint('%s%s: add: %s/%s, grow: %s/%s bytes: %s/%s (%s)' % Tprint('%s%s: add: %s/%s, grow: %s/%s bytes: %s/%s (%s)' %
tuple([indent, self.col.Color(self.col.YELLOW, fname)] + args)) tuple([indent, self.col.build(self.col.YELLOW, fname)] + args))
Tprint('%s %-38s %7s %7s %+7s' % (indent, 'function', 'old', 'new', Tprint('%s %-38s %7s %7s %+7s' % (indent, 'function', 'old', 'new',
'delta')) 'delta'))
for diff, name in delta: for diff, name in delta:
@ -1324,12 +1324,12 @@ class Builder:
names = [board.target for board in line.boards] names = [board.target for board in line.boards]
board_str = ' '.join(names) if names else '' board_str = ' '.join(names) if names else ''
if board_str: if board_str:
out = self.col.Color(colour, line.char + '(') out = self.col.build(colour, line.char + '(')
out += self.col.Color(self.col.MAGENTA, board_str, out += self.col.build(self.col.MAGENTA, board_str,
bright=False) bright=False)
out += self.col.Color(colour, ') %s' % line.errline) out += self.col.build(colour, ') %s' % line.errline)
else: else:
out = self.col.Color(colour, line.char + line.errline) out = self.col.build(colour, line.char + line.errline)
out_list.append(out) out_list.append(out)
Tprint('\n'.join(out_list)) Tprint('\n'.join(out_list))
self._error_lines += 1 self._error_lines += 1

View file

@ -73,7 +73,7 @@ def ShowActions(series, why_selected, boards_selected, builder, options,
if commits: if commits:
for upto in range(0, len(series.commits), options.step): for upto in range(0, len(series.commits), options.step):
commit = series.commits[upto] commit = series.commits[upto]
print(' ', col.Color(col.YELLOW, commit.hash[:8], bright=False), end=' ') print(' ', col.build(col.YELLOW, commit.hash[:8], bright=False), end=' ')
print(commit.subject) print(commit.subject)
print() print()
for arg in why_selected: for arg in why_selected:
@ -85,7 +85,7 @@ def ShowActions(series, why_selected, boards_selected, builder, options,
len(why_selected['all']))) len(why_selected['all'])))
if board_warnings: if board_warnings:
for warning in board_warnings: for warning in board_warnings:
print(col.Color(col.YELLOW, warning)) print(col.build(col.YELLOW, warning))
def ShowToolchainPrefix(boards, toolchains): def ShowToolchainPrefix(boards, toolchains):
"""Show information about a the tool chain used by one or more boards """Show information about a the tool chain used by one or more boards
@ -152,14 +152,14 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None,
if options.fetch_arch: if options.fetch_arch:
if options.fetch_arch == 'list': if options.fetch_arch == 'list':
sorted_list = toolchains.ListArchs() sorted_list = toolchains.ListArchs()
print(col.Color(col.BLUE, 'Available architectures: %s\n' % print(col.build(col.BLUE, 'Available architectures: %s\n' %
' '.join(sorted_list))) ' '.join(sorted_list)))
return 0 return 0
else: else:
fetch_arch = options.fetch_arch fetch_arch = options.fetch_arch
if fetch_arch == 'all': if fetch_arch == 'all':
fetch_arch = ','.join(toolchains.ListArchs()) fetch_arch = ','.join(toolchains.ListArchs())
print(col.Color(col.CYAN, '\nDownloading toolchains: %s' % print(col.build(col.CYAN, '\nDownloading toolchains: %s' %
fetch_arch)) fetch_arch))
for arch in fetch_arch.split(','): for arch in fetch_arch.split(','):
print() print()
@ -177,11 +177,11 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None,
return 0 return 0
if options.incremental: if options.incremental:
print(col.Color(col.RED, print(col.build(col.RED,
'Warning: -I has been removed. See documentation')) 'Warning: -I has been removed. See documentation'))
if not options.output_dir: if not options.output_dir:
if options.work_in_output: if options.work_in_output:
sys.exit(col.Color(col.RED, '-w requires that you specify -o')) sys.exit(col.build(col.RED, '-w requires that you specify -o'))
options.output_dir = '..' options.output_dir = '..'
# Work out what subset of the boards we are building # Work out what subset of the boards we are building
@ -218,12 +218,12 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None,
requested_boards) requested_boards)
selected = boards.GetSelected() selected = boards.GetSelected()
if not len(selected): if not len(selected):
sys.exit(col.Color(col.RED, 'No matching boards found')) sys.exit(col.build(col.RED, 'No matching boards found'))
if options.print_prefix: if options.print_prefix:
err = ShowToolchainPrefix(boards, toolchains) err = ShowToolchainPrefix(boards, toolchains)
if err: if err:
sys.exit(col.Color(col.RED, err)) sys.exit(col.build(col.RED, err))
return 0 return 0
# Work out how many commits to build. We want to build everything on the # Work out how many commits to build. We want to build everything on the
@ -242,24 +242,24 @@ def DoBuildman(options, args, toolchains=None, make_func=None, boards=None,
count, msg = gitutil.count_commits_in_branch(options.git_dir, count, msg = gitutil.count_commits_in_branch(options.git_dir,
options.branch) options.branch)
if count is None: if count is None:
sys.exit(col.Color(col.RED, msg)) sys.exit(col.build(col.RED, msg))
elif count == 0: elif count == 0:
sys.exit(col.Color(col.RED, "Range '%s' has no commits" % sys.exit(col.build(col.RED, "Range '%s' has no commits" %
options.branch)) options.branch))
if msg: if msg:
print(col.Color(col.YELLOW, msg)) print(col.build(col.YELLOW, msg))
count += 1 # Build upstream commit also count += 1 # Build upstream commit also
if not count: if not count:
str = ("No commits found to process in branch '%s': " str = ("No commits found to process in branch '%s': "
"set branch's upstream or use -c flag" % options.branch) "set branch's upstream or use -c flag" % options.branch)
sys.exit(col.Color(col.RED, str)) sys.exit(col.build(col.RED, str))
if options.work_in_output: if options.work_in_output:
if len(selected) != 1: if len(selected) != 1:
sys.exit(col.Color(col.RED, sys.exit(col.build(col.RED,
'-w can only be used with a single board')) '-w can only be used with a single board'))
if count != 1: if count != 1:
sys.exit(col.Color(col.RED, sys.exit(col.build(col.RED,
'-w can only be used with a single commit')) '-w can only be used with a single commit'))
# Read the metadata from the commits. First look at the upstream commit, # Read the metadata from the commits. First look at the upstream commit,

View file

@ -182,10 +182,10 @@ class TestBuild(unittest.TestCase):
col.YELLOW if outcome == OUTCOME_WARN else col.RED) col.YELLOW if outcome == OUTCOME_WARN else col.RED)
expect = '%10s: ' % arch expect = '%10s: ' % arch
# TODO(sjg@chromium.org): If plus is '', we shouldn't need this # TODO(sjg@chromium.org): If plus is '', we shouldn't need this
expect += ' ' + col.Color(expected_colour, plus) expect += ' ' + col.build(expected_colour, plus)
expect += ' ' expect += ' '
for board in boards: for board in boards:
expect += col.Color(expected_colour, ' %s' % board) expect += col.build(expected_colour, ' %s' % board)
self.assertEqual(text, expect) self.assertEqual(text, expect)
def _SetupTest(self, echo_lines=False, threads=1, **kwdisplay_args): def _SetupTest(self, echo_lines=False, threads=1, **kwdisplay_args):
@ -254,12 +254,12 @@ class TestBuild(unittest.TestCase):
new_lines = [] new_lines = []
for line in lines: for line in lines:
if boards: if boards:
expect = self._col.Color(colour, prefix + '(') expect = self._col.build(colour, prefix + '(')
expect += self._col.Color(self._col.MAGENTA, boards, expect += self._col.build(self._col.MAGENTA, boards,
bright=False) bright=False)
expect += self._col.Color(colour, ') %s' % line) expect += self._col.build(colour, ') %s' % line)
else: else:
expect = self._col.Color(colour, prefix + line) expect = self._col.build(colour, prefix + line)
new_lines.append(expect) new_lines.append(expect)
return '\n'.join(new_lines) return '\n'.join(new_lines)
@ -317,12 +317,12 @@ class TestBuild(unittest.TestCase):
self.assertEqual(next(lines).text, '04: %s' % commits[3][1]) self.assertEqual(next(lines).text, '04: %s' % commits[3][1])
if filter_migration_warnings: if filter_migration_warnings:
expect = '%10s: ' % 'powerpc' expect = '%10s: ' % 'powerpc'
expect += ' ' + col.Color(col.GREEN, '') expect += ' ' + col.build(col.GREEN, '')
expect += ' ' expect += ' '
expect += col.Color(col.GREEN, ' %s' % 'board2') expect += col.build(col.GREEN, ' %s' % 'board2')
expect += ' ' + col.Color(col.YELLOW, 'w+') expect += ' ' + col.build(col.YELLOW, 'w+')
expect += ' ' expect += ' '
expect += col.Color(col.YELLOW, ' %s' % 'board3') expect += col.build(col.YELLOW, ' %s' % 'board3')
self.assertEqual(next(lines).text, expect) self.assertEqual(next(lines).text, expect)
else: else:
self.assertSummary(next(lines).text, 'powerpc', 'w+', self.assertSummary(next(lines).text, 'powerpc', 'w+',

View file

@ -381,7 +381,7 @@ class Toolchains:
def List(self): def List(self):
"""List out the selected toolchains for each architecture""" """List out the selected toolchains for each architecture"""
col = terminal.Color() col = terminal.Color()
print(col.Color(col.BLUE, 'List of available toolchains (%d):' % print(col.build(col.BLUE, 'List of available toolchains (%d):' %
len(self.toolchains))) len(self.toolchains)))
if len(self.toolchains): if len(self.toolchains):
for key, value in sorted(self.toolchains.items()): for key, value in sorted(self.toolchains.items()):
@ -559,7 +559,7 @@ class Toolchains:
""" """
# Fist get the URL for this architecture # Fist get the URL for this architecture
col = terminal.Color() col = terminal.Color()
print(col.Color(col.BLUE, "Downloading toolchain for arch '%s'" % arch)) print(col.build(col.BLUE, "Downloading toolchain for arch '%s'" % arch))
url = self.LocateArchUrl(arch) url = self.LocateArchUrl(arch)
if not url: if not url:
print(("Cannot find toolchain for arch '%s' - use 'list' to list" % print(("Cannot find toolchain for arch '%s' - use 'list' to list" %
@ -574,7 +574,7 @@ class Toolchains:
tarfile, tmpdir = tools.download(url, '.buildman') tarfile, tmpdir = tools.download(url, '.buildman')
if not tarfile: if not tarfile:
return 1 return 1
print(col.Color(col.GREEN, 'Unpacking to: %s' % dest), end=' ') print(col.build(col.GREEN, 'Unpacking to: %s' % dest), end=' ')
sys.stdout.flush() sys.stdout.flush()
path = self.Unpack(tarfile, dest) path = self.Unpack(tarfile, dest)
os.remove(tarfile) os.remove(tarfile)
@ -582,14 +582,14 @@ class Toolchains:
print() print()
# Check that the toolchain works # Check that the toolchain works
print(col.Color(col.GREEN, 'Testing')) print(col.build(col.GREEN, 'Testing'))
dirpath = os.path.join(dest, path) dirpath = os.path.join(dest, path)
compiler_fname_list = self.ScanPath(dirpath, True) compiler_fname_list = self.ScanPath(dirpath, True)
if not compiler_fname_list: if not compiler_fname_list:
print('Could not locate C compiler - fetch failed.') print('Could not locate C compiler - fetch failed.')
return 1 return 1
if len(compiler_fname_list) != 1: if len(compiler_fname_list) != 1:
print(col.Color(col.RED, 'Warning, ambiguous toolchains: %s' % print(col.build(col.RED, 'Warning, ambiguous toolchains: %s' %
', '.join(compiler_fname_list))) ', '.join(compiler_fname_list)))
toolchain = Toolchain(compiler_fname_list[0], True, True) toolchain = Toolchain(compiler_fname_list[0], True, True)

View file

@ -228,11 +228,11 @@ def get_warning_msg(col, msg_type, fname, line, msg):
msg: Message to report msg: Message to report
''' '''
if msg_type == 'warning': if msg_type == 'warning':
msg_type = col.Color(col.YELLOW, msg_type) msg_type = col.build(col.YELLOW, msg_type)
elif msg_type == 'error': elif msg_type == 'error':
msg_type = col.Color(col.RED, msg_type) msg_type = col.build(col.RED, msg_type)
elif msg_type == 'check': elif msg_type == 'check':
msg_type = col.Color(col.MAGENTA, msg_type) msg_type = col.build(col.MAGENTA, msg_type)
line_str = '' if line is None else '%d' % line line_str = '' if line is None else '%d' % line
return '%s:%s: %s: %s\n' % (fname, line_str, msg_type, msg) return '%s:%s: %s: %s\n' % (fname, line_str, msg_type, msg)
@ -248,7 +248,7 @@ def check_patches(verbose, args):
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.build(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")
@ -266,6 +266,6 @@ def check_patches(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.build(color, str % (error_count, warning_count, check_count)))
return False return False
return True return True

View file

@ -50,7 +50,7 @@ def prepare_patches(col, branch, count, start, end, ignore_binary, signoff):
if not count: if not count:
str = 'No commits found to process - please use -c flag, or run:\n' \ str = 'No commits found to process - please use -c flag, or run:\n' \
' git branch --set-upstream-to remote/branch' ' git branch --set-upstream-to remote/branch'
sys.exit(col.Color(col.RED, str)) sys.exit(col.build(col.RED, str))
# Read the metadata from the commits # Read the metadata from the commits
to_do = count - end to_do = count - end
@ -143,13 +143,13 @@ def email_patches(col, series, cover_fname, patch_files, process_tags, its_a_go,
cc_file, in_reply_to=in_reply_to, thread=thread, cc_file, in_reply_to=in_reply_to, thread=thread,
smtp_server=smtp_server) smtp_server=smtp_server)
else: else:
print(col.Color(col.RED, "Not sending emails due to errors/warnings")) print(col.build(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 dry_run: if dry_run:
series.ShowActions(patch_files, cmd, process_tags) series.ShowActions(patch_files, cmd, process_tags)
if not its_a_go: if not its_a_go:
print(col.Color(col.RED, "Email would not be sent")) print(col.build(col.RED, "Email would not be sent"))
os.remove(cc_file) os.remove(cc_file)

View file

@ -404,7 +404,7 @@ def check_suppress_cc_config():
if suppresscc == 'all' or suppresscc == 'cccmd': if suppresscc == 'all' or suppresscc == 'cccmd':
col = terminal.Color() col = terminal.Color()
print((col.Color(col.RED, "error") + print((col.build(col.RED, "error") +
": git config sendemail.suppresscc set to %s\n" % (suppresscc)) + ": git config sendemail.suppresscc set to %s\n" % (suppresscc)) +
" patman needs --cc-cmd to be run to set the cc list.\n" + " patman needs --cc-cmd to be run to set the cc list.\n" +
" Please run:\n" + " Please run:\n" +
@ -577,14 +577,14 @@ def lookup_email(lookup_name, alias=None, warn_on_error=True, level=0):
if warn_on_error: if warn_on_error:
raise OSError(msg) raise OSError(msg)
else: else:
print(col.Color(col.RED, msg)) print(col.build(col.RED, msg))
return out_list return out_list
if lookup_name: if lookup_name:
if not lookup_name in alias: if not lookup_name in alias:
msg = "Alias '%s' not found" % lookup_name msg = "Alias '%s' not found" % lookup_name
if warn_on_error: if warn_on_error:
print(col.Color(col.RED, msg)) print(col.build(col.RED, msg))
return out_list return out_list
for item in alias[lookup_name]: for item in alias[lookup_name]:
todo = lookup_email(item, alias, warn_on_error, level + 1) todo = lookup_email(item, alias, warn_on_error, level + 1)

View file

@ -118,11 +118,11 @@ class Series(dict):
# 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.build(col.GREEN, ' %s' % args[upto]))
cc_list = list(self._generated_cc[commit.patch]) cc_list = list(self._generated_cc[commit.patch])
for email in sorted(set(cc_list) - to_set - cc_set): for email in sorted(set(cc_list) - to_set - cc_set):
if email == None: if email == None:
email = col.Color(col.YELLOW, "<alias '%s' not found>" email = col.build(col.YELLOW, "<alias '%s' not found>"
% tag) % tag)
if email: if email:
print(' Cc: ', email) print(' Cc: ', email)
@ -227,13 +227,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.build(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.build(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.build(col.RED, str))
def MakeCcFile(self, process_tags, cover_fname, warn_on_error, def MakeCcFile(self, process_tags, cover_fname, warn_on_error,
add_maintainers, limit): add_maintainers, limit):
@ -271,7 +271,7 @@ class Series(dict):
dir_list = [os.path.join(gitutil.get_top_level(), 'scripts')] dir_list = [os.path.join(gitutil.get_top_level(), 'scripts')]
cc += get_maintainer.get_maintainer(dir_list, commit.patch) cc += get_maintainer.get_maintainer(dir_list, commit.patch)
for x in set(cc) & set(settings.bounces): for x in set(cc) & set(settings.bounces):
print(col.Color(col.YELLOW, 'Skipping "%s"' % x)) print(col.build(col.YELLOW, 'Skipping "%s"' % x))
cc = list(set(cc) - set(settings.bounces)) cc = list(set(cc) - set(settings.bounces))
if limit is not None: if limit is not None:
cc = cc[:limit] cc = cc[:limit]

View file

@ -64,7 +64,7 @@ def CalcAsciiLen(text):
Length of text, after skipping ANSI sequences Length of text, after skipping ANSI sequences
>>> col = Color(COLOR_ALWAYS) >>> col = Color(COLOR_ALWAYS)
>>> text = col.Color(Color.RED, 'abc') >>> text = col.build(Color.RED, 'abc')
>>> len(text) >>> len(text)
14 14
>>> CalcAsciiLen(text) >>> CalcAsciiLen(text)
@ -73,7 +73,7 @@ def CalcAsciiLen(text):
>>> text += 'def' >>> text += 'def'
>>> CalcAsciiLen(text) >>> CalcAsciiLen(text)
6 6
>>> text += col.Color(Color.RED, 'abc') >>> text += col.build(Color.RED, 'abc')
>>> CalcAsciiLen(text) >>> CalcAsciiLen(text)
9 9
""" """
@ -87,7 +87,7 @@ def TrimAsciiLen(text, size):
calculation. calculation.
>>> col = Color(COLOR_ALWAYS) >>> col = Color(COLOR_ALWAYS)
>>> text = col.Color(Color.RED, 'abc') >>> text = col.build(Color.RED, 'abc')
>>> len(text) >>> len(text)
14 14
>>> CalcAsciiLen(TrimAsciiLen(text, 4)) >>> CalcAsciiLen(TrimAsciiLen(text, 4))
@ -97,7 +97,7 @@ def TrimAsciiLen(text, size):
>>> text += 'def' >>> text += 'def'
>>> CalcAsciiLen(TrimAsciiLen(text, 4)) >>> CalcAsciiLen(TrimAsciiLen(text, 4))
4 4
>>> text += col.Color(Color.RED, 'ghi') >>> text += col.build(Color.RED, 'ghi')
>>> CalcAsciiLen(TrimAsciiLen(text, 7)) >>> CalcAsciiLen(TrimAsciiLen(text, 7))
7 7
""" """
@ -148,7 +148,7 @@ def Tprint(text='', newline=True, colour=None, limit_to_line=False, bright=True)
else: else:
if colour: if colour:
col = Color() col = Color()
text = col.Color(colour, text, bright=bright) text = col.build(colour, text, bright=bright)
if newline: if newline:
print(text) print(text)
last_print_len = None last_print_len = None
@ -191,7 +191,7 @@ 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), end='') print(col.build(line.colour, line.text), end='')
else: else:
print(line.text, end='') print(line.text, end='')
if line.newline: if line.newline:
@ -247,7 +247,7 @@ class Color(object):
return self.RESET return self.RESET
return '' return ''
def Color(self, color, text, bright=True): def build(self, color, text, bright=True):
"""Returns text with conditionally added color escape sequences. """Returns text with conditionally added color escape sequences.
Keyword arguments: Keyword arguments:

View file

@ -64,7 +64,7 @@ def progress(msg, warning=False, trailer='...'):
_progress = msg + trailer _progress = msg + trailer
if stdout_is_tty: if stdout_is_tty:
col = _color.YELLOW if warning else _color.GREEN col = _color.YELLOW if warning else _color.GREEN
_stdout.write('\r' + _color.Color(col, _progress)) _stdout.write('\r' + _color.build(col, _progress))
_stdout.flush() _stdout.flush()
in_progress = True in_progress = True
else: else:
@ -82,7 +82,7 @@ def _output(level, msg, color=None):
if verbose >= level: if verbose >= level:
clear_progress() clear_progress()
if color: if color:
msg = _color.Color(color, msg) msg = _color.build(color, msg)
if level < NOTICE: if level < NOTICE:
print(msg, file=sys.stderr) print(msg, file=sys.stderr)
else: else: