From f6ef4395fe1896ba68c80e52cb24763b0fcfe7f8 Mon Sep 17 00:00:00 2001 From: Caroline Tice Date: Thu, 6 Apr 2017 17:16:05 -0700 Subject: [toolchain-utils] Fix remaining lint errors in toolchain-utils. In addition to fixing the lint errors, this also fixes the Python formatting issues (ran tc_pyformat on nearly all the files). BUG=chromium:570450 TEST=Ran all crosperf & bisect tool unit tests. Ran afe_lock_machine.py (check machine status) Ran full crosperf test (octane, speedometer, BootPerf) on alex. Change-Id: Ic86f9192801ac67769f3de30f1c5f0d203ce0831 Reviewed-on: https://chromium-review.googlesource.com/471886 Commit-Ready: Caroline Tice Tested-by: Caroline Tice Reviewed-by: Manoj Gupta --- cros_utils/misc.py | 78 +++++++++++++------------- cros_utils/tabulator.py | 143 ++++++++++++++++++++++++++++-------------------- 2 files changed, 122 insertions(+), 99 deletions(-) (limited to 'cros_utils') diff --git a/cros_utils/misc.py b/cros_utils/misc.py index 6c7d2909..939ed66b 100644 --- a/cros_utils/misc.py +++ b/cros_utils/misc.py @@ -66,7 +66,11 @@ def UnitToNumber(unit_num, base=1000): def GetFilenameFromString(string): - return ApplySubs(string, (r'/', '__'), (r'\s', '_'), (r'[\\$="?^]', ''),) + return ApplySubs( + string, + (r'/', '__'), + (r'\s', '_'), + (r'[\\$="?^]', ''),) def GetRoot(scr_name): @@ -143,16 +147,16 @@ def GetBuildPackagesCommand(board, usepkg=False, debug=False): withdebug_flag = '--nowithdebug' return ('%s/build_packages %s --withdev --withtest --withautotest ' '--skip_toolchain_update %s --board=%s ' - '--accept_licenses=@CHROMEOS' % - (CHROMEOS_SCRIPTS_DIR, usepkg_flag, withdebug_flag, board)) + '--accept_licenses=@CHROMEOS' % (CHROMEOS_SCRIPTS_DIR, usepkg_flag, + withdebug_flag, board)) def GetBuildImageCommand(board, dev=False): dev_args = '' if dev: dev_args = '--noenable_rootfs_verification --disk_layout=2gb-rootfs' - return ('%s/build_image --board=%s %s test' % - (CHROMEOS_SCRIPTS_DIR, board, dev_args)) + return ('%s/build_image --board=%s %s test' % (CHROMEOS_SCRIPTS_DIR, board, + dev_args)) def GetSetupBoardCommand(board, @@ -179,8 +183,8 @@ def GetSetupBoardCommand(board, options.append('--accept_licenses=@CHROMEOS') - return ('%s/setup_board --board=%s %s' % - (CHROMEOS_SCRIPTS_DIR, board, ' '.join(options))) + return ('%s/setup_board --board=%s %s' % (CHROMEOS_SCRIPTS_DIR, board, + ' '.join(options))) def CanonicalizePath(path): @@ -192,8 +196,8 @@ def CanonicalizePath(path): def GetCtargetFromBoard(board, chromeos_root): """Get Ctarget from board.""" base_board = board.split('_')[0] - command = ('source %s; get_ctarget_from_board %s' % - (TOOLCHAIN_UTILS_PATH, base_board)) + command = ('source %s; get_ctarget_from_board %s' % (TOOLCHAIN_UTILS_PATH, + base_board)) ce = command_executer.GetCommandExecuter() ret, out, _ = ce.ChrootRunCommandWOutput(chromeos_root, command) if ret != 0: @@ -206,8 +210,8 @@ def GetCtargetFromBoard(board, chromeos_root): def GetArchFromBoard(board, chromeos_root): """Get Arch from board.""" base_board = board.split('_')[0] - command = ('source %s; get_board_arch %s' % - (TOOLCHAIN_UTILS_PATH, base_board)) + command = ('source %s; get_board_arch %s' % (TOOLCHAIN_UTILS_PATH, + base_board)) ce = command_executer.GetCommandExecuter() ret, out, _ = ce.ChrootRunCommandWOutput(chromeos_root, command) if ret != 0: @@ -318,16 +322,14 @@ def HasGitStagedChanges(git_dir): command = 'cd {0} && git diff --quiet --cached --exit-code HEAD'.format( git_dir) return command_executer.GetCommandExecuter().RunCommand( - command, - print_to_console=False) + command, print_to_console=False) def HasGitUnstagedChanges(git_dir): """Return True if git repository has un-staged changes.""" command = 'cd {0} && git diff --quiet --exit-code HEAD'.format(git_dir) return command_executer.GetCommandExecuter().RunCommand( - command, - print_to_console=False) + command, print_to_console=False) def HasGitUntrackedChanges(git_dir): @@ -335,8 +337,7 @@ def HasGitUntrackedChanges(git_dir): command = ('cd {0} && test -z ' '$(git ls-files --exclude-standard --others)').format(git_dir) return command_executer.GetCommandExecuter().RunCommand( - command, - print_to_console=False) + command, print_to_console=False) def GitGetCommitHash(git_dir, commit_symbolic_name): @@ -357,8 +358,7 @@ def GitGetCommitHash(git_dir, commit_symbolic_name): command = ('cd {0} && git log -n 1 --pretty="format:%H" {1}').format( git_dir, commit_symbolic_name) rv, out, _ = command_executer.GetCommandExecuter().RunCommandWOutput( - command, - print_to_console=False) + command, print_to_console=False) if rv == 0: return out.strip() return None @@ -402,8 +402,7 @@ def GetGitChangesAsList(git_dir, path=None, staged=False): if path: command += ' -- ' + path _, out, _ = command_executer.GetCommandExecuter().RunCommandWOutput( - command, - print_to_console=False) + command, print_to_console=False) rv = [] for line in out.splitlines(): rv.append(line) @@ -411,8 +410,8 @@ def GetGitChangesAsList(git_dir, path=None, staged=False): def IsChromeOsTree(chromeos_root): - return (os.path.isdir(os.path.join(chromeos_root, - 'src/third_party/chromiumos-overlay')) and + return (os.path.isdir( + os.path.join(chromeos_root, 'src/third_party/chromiumos-overlay')) and os.path.isdir(os.path.join(chromeos_root, 'manifest'))) @@ -436,25 +435,22 @@ def DeleteChromeOsTree(chromeos_root, dry_run=False): print(cmd0) else: if command_executer.GetCommandExecuter().RunCommand( - cmd0, - print_to_console=True) != 0: + cmd0, print_to_console=True) != 0: return False cmd1 = ('export CHROMEOSDIRNAME="$(dirname $(cd {0} && pwd))" && ' 'export CHROMEOSBASENAME="$(basename $(cd {0} && pwd))" && ' - 'cd $CHROMEOSDIRNAME && sudo rm -fr $CHROMEOSBASENAME').format( - chromeos_root) + 'cd $CHROMEOSDIRNAME && sudo rm -fr $CHROMEOSBASENAME' + ).format(chromeos_root) if dry_run: print(cmd1) return True return command_executer.GetCommandExecuter().RunCommand( - cmd1, - print_to_console=True) == 0 + cmd1, print_to_console=True) == 0 -def ApplyGerritPatches(chromeos_root, - gerrit_patch_string, +def ApplyGerritPatches(chromeos_root, gerrit_patch_string, branch='cros/master'): """Apply gerrit patches on a chromeos tree. @@ -491,8 +487,8 @@ def ApplyGerritPatches(chromeos_root, pi_str = '{project}:{ref}'.format(project=pi.project, ref=pi.ref) try: project_git_path = project_checkout.GetPath(absolute=True) - logger.GetLogger().LogOutput('Applying patch "{0}" in "{1}" ...'.format( - pi_str, project_git_path)) + logger.GetLogger().LogOutput( + 'Applying patch "{0}" in "{1}" ...'.format(pi_str, project_git_path)) pi.Apply(project_git_path, branch, trivial=False) except Exception: traceback.print_exc(file=sys.stdout) @@ -521,8 +517,8 @@ def BooleanPrompt(prompt='Do you want to continue?', true_value, false_value = true_value.lower(), false_value.lower() true_text, false_text = true_value, false_value if true_value == false_value: - raise ValueError('true_value and false_value must differ: got %r' % - true_value) + raise ValueError( + 'true_value and false_value must differ: got %r' % true_value) if default: true_text = true_text[0].upper() + true_text[1:] @@ -556,14 +552,16 @@ def BooleanPrompt(prompt='Do you want to continue?', elif false_value.startswith(response): return False + +# pylint: disable=unused-argument def rgb2short(r, g, b): - """ Converts RGB values to xterm-256 color. """ + """Converts RGB values to xterm-256 color.""" - redcolor = [255, 124, 160, 196, 9 ] - greencolor = [255, 118, 82, 46, 10 ] + redcolor = [255, 124, 160, 196, 9] + greencolor = [255, 118, 82, 46, 10] if g == 0: - return redcolor[r/52] + return redcolor[r / 52] if r == 0: - return greencolor[g/52] + return greencolor[g / 52] return 4 diff --git a/cros_utils/tabulator.py b/cros_utils/tabulator.py index 98f126bc..6936d35f 100644 --- a/cros_utils/tabulator.py +++ b/cros_utils/tabulator.py @@ -57,7 +57,6 @@ table: cell_table = tf.GetCellTable() tp = TablePrinter(cell_table, out_to) print tp.Print() - """ from __future__ import print_function @@ -464,12 +463,13 @@ class KeyAwareComparisonResult(ComparisonResult): # --texture_upload_count--texture_upload_count--count (high is good) # --total_deferred_image_decode_count--count (low is good) # --total_tiles_analyzed--total_tiles_analyzed--count (high is good) - lower_is_better_keys = ['milliseconds', 'ms_', 'seconds_', 'KB', 'rdbytes', - 'wrbytes', 'dropped_percent', '(ms)', '(seconds)', - '--ms', '--average_num_missing_tiles', - '--experimental_jank', '--experimental_mean_frame', - '--experimental_median_frame_time', - '--total_deferred_image_decode_count', '--seconds'] + lower_is_better_keys = [ + 'milliseconds', 'ms_', 'seconds_', 'KB', 'rdbytes', 'wrbytes', + 'dropped_percent', '(ms)', '(seconds)', '--ms', + '--average_num_missing_tiles', '--experimental_jank', + '--experimental_mean_frame', '--experimental_median_frame_time', + '--total_deferred_image_decode_count', '--seconds' + ] return any([l in key for l in lower_is_better_keys]) @@ -608,12 +608,13 @@ class PValueFormat(Format): def _ComputeFloat(self, cell): cell.string_value = '%0.2f' % float(cell.value) if float(cell.value) < 0.05: - cell.bgcolor = self._GetColor(cell.value, - Color(255, 255, 0, 0), - Color(255, 255, 255, 0), - Color(255, 255, 255, 0), - mid_value=0.05, - power=1) + cell.bgcolor = self._GetColor( + cell.value, + Color(255, 255, 0, 0), + Color(255, 255, 255, 0), + Color(255, 255, 255, 0), + mid_value=0.05, + power=1) class StorageFormat(Format): @@ -647,12 +648,13 @@ class CoeffVarFormat(Format): def _ComputeFloat(self, cell): cell.string_value = '%1.1f%%' % (float(cell.value) * 100) - cell.color = self._GetColor(cell.value, - Color(0, 255, 0, 0), - Color(0, 0, 0, 0), - Color(255, 0, 0, 0), - mid_value=0.02, - power=1) + cell.color = self._GetColor( + cell.value, + Color(0, 255, 0, 0), + Color(0, 0, 0, 0), + Color(255, 0, 0, 0), + mid_value=0.02, + power=1) class PercentFormat(Format): @@ -664,7 +666,8 @@ class PercentFormat(Format): def _ComputeFloat(self, cell): cell.string_value = '%+1.1f%%' % ((float(cell.value) - 1) * 100) - cell.color = self._GetColor(cell.value, Color(255, 0, 0, 0), + cell.color = self._GetColor(cell.value, + Color(255, 0, 0, 0), Color(0, 0, 0, 0), Color(0, 255, 0, 0)) @@ -677,7 +680,8 @@ class RatioFormat(Format): def _ComputeFloat(self, cell): cell.string_value = '%+1.1f%%' % ((cell.value - 1) * 100) - cell.color = self._GetColor(cell.value, Color(255, 0, 0, 0), + cell.color = self._GetColor(cell.value, + Color(255, 0, 0, 0), Color(0, 0, 0, 0), Color(0, 255, 0, 0)) @@ -693,7 +697,8 @@ class ColorBoxFormat(Format): def _ComputeFloat(self, cell): cell.string_value = '--' - bgcolor = self._GetColor(cell.value, Color(255, 0, 0, 0), + bgcolor = self._GetColor(cell.value, + Color(255, 0, 0, 0), Color(255, 255, 255, 0), Color(0, 255, 0, 0)) cell.bgcolor = bgcolor cell.color = bgcolor @@ -889,8 +894,8 @@ class TableFormatter(object): def AddLabelName(self): """Put label on the top of the table.""" top_header = [] - base_colspan = len([c for c in self._columns if not c.result.NeedsBaseline() - ]) + base_colspan = len( + [c for c in self._columns if not c.result.NeedsBaseline()]) compare_colspan = len(self._columns) # Find the row with the key 'retval', if it exists. This # will be used to calculate the number of iterations that passed and @@ -1179,14 +1184,17 @@ def GetComplexTable(runs, labels, out_to=TablePrinter.CONSOLE): """ tg = TableGenerator(runs, labels, TableGenerator.SORT_BY_VALUES_DESC) table = tg.GetTable() - columns = [Column(LiteralResult(), Format(), 'Literal'), - Column(AmeanResult(), Format()), Column(StdResult(), Format()), - Column(CoeffVarResult(), CoeffVarFormat()), - Column(NonEmptyCountResult(), Format()), - Column(AmeanRatioResult(), PercentFormat()), - Column(AmeanRatioResult(), RatioFormat()), - Column(GmeanRatioResult(), RatioFormat()), - Column(PValueResult(), PValueFormat())] + columns = [ + Column(LiteralResult(), Format(), 'Literal'), Column( + AmeanResult(), Format()), Column(StdResult(), Format()), Column( + CoeffVarResult(), CoeffVarFormat()), Column( + NonEmptyCountResult(), Format()), + Column(AmeanRatioResult(), PercentFormat()), Column( + AmeanRatioResult(), RatioFormat()), Column(GmeanRatioResult(), + RatioFormat()), Column( + PValueResult(), + PValueFormat()) + ] tf = TableFormatter(table, columns) cell_table = tf.GetCellTable() tp = TablePrinter(cell_table, out_to) @@ -1195,38 +1203,55 @@ def GetComplexTable(runs, labels, out_to=TablePrinter.CONSOLE): if __name__ == '__main__': # Run a few small tests here. - runs = [[{'k1': '10', - 'k2': '12', - 'k5': '40', - 'k6': '40', - 'ms_1': '20', - 'k7': 'FAIL', - 'k8': 'PASS', - 'k9': 'PASS', - 'k10': '0'}, {'k1': '13', - 'k2': '14', - 'k3': '15', - 'ms_1': '10', - 'k8': 'PASS', - 'k9': 'FAIL', - 'k10': '0'}], [{'k1': '50', - 'k2': '51', - 'k3': '52', - 'k4': '53', - 'k5': '35', - 'k6': '45', - 'ms_1': '200', - 'ms_2': '20', - 'k7': 'FAIL', - 'k8': 'PASS', - 'k9': 'PASS'}]] + runs = [[{ + 'k1': '10', + 'k2': '12', + 'k5': '40', + 'k6': '40', + 'ms_1': '20', + 'k7': 'FAIL', + 'k8': 'PASS', + 'k9': 'PASS', + 'k10': '0' + }, { + 'k1': '13', + 'k2': '14', + 'k3': '15', + 'ms_1': '10', + 'k8': 'PASS', + 'k9': 'FAIL', + 'k10': '0' + }], [{ + 'k1': '50', + 'k2': '51', + 'k3': '52', + 'k4': '53', + 'k5': '35', + 'k6': '45', + 'ms_1': '200', + 'ms_2': '20', + 'k7': 'FAIL', + 'k8': 'PASS', + 'k9': 'PASS' + }]] labels = ['vanilla', 'modified'] t = GetComplexTable(runs, labels, TablePrinter.CONSOLE) print(t) email = GetComplexTable(runs, labels, TablePrinter.EMAIL) - runs = [[{'k1': '1'}, {'k1': '1.1'}, {'k1': '1.2'}], - [{'k1': '5'}, {'k1': '5.1'}, {'k1': '5.2'}]] + runs = [[{ + 'k1': '1' + }, { + 'k1': '1.1' + }, { + 'k1': '1.2' + }], [{ + 'k1': '5' + }, { + 'k1': '5.1' + }, { + 'k1': '5.2' + }]] t = GetComplexTable(runs, labels, TablePrinter.CONSOLE) print(t) -- cgit v1.2.3