diff options
Diffstat (limited to 'cros_utils')
-rw-r--r-- | cros_utils/buildbot_utils.py | 53 | ||||
-rw-r--r-- | cros_utils/command_executer.py | 126 | ||||
-rw-r--r-- | cros_utils/manifest_versions.py | 79 | ||||
-rw-r--r-- | cros_utils/misc.py | 78 | ||||
-rw-r--r-- | cros_utils/tabulator.py | 143 |
5 files changed, 294 insertions, 185 deletions
diff --git a/cros_utils/buildbot_utils.py b/cros_utils/buildbot_utils.py index d1403557..f89bb71a 100644 --- a/cros_utils/buildbot_utils.py +++ b/cros_utils/buildbot_utils.py @@ -8,6 +8,7 @@ from __future__ import print_function import base64 import json import os +import re import time import urllib2 @@ -91,8 +92,14 @@ def FindBuildRecordFromLog(description, build_info): point.) """ for build_log in build_info: - if description in build_log['reason']: - return build_log + property_list = build_log['properties'] + for prop in property_list: + if len(prop) < 2: + continue + pname = prop[0] + pvalue = prop[1] + if pname == 'name' and pvalue == description: + return build_log return {} @@ -237,10 +244,9 @@ def GetTrybotImage(chromeos_root, if not patch_arg: command_prefix = 'yes | ' command = ('%s ./cbuildbot --remote --nochromesdk %s' - ' --remote-description=%s %s %s %s' % (command_prefix, - optional_flags, description, - toolchain_flags, patch_arg, - build)) + ' --remote-description=%s %s %s %s' % + (command_prefix, optional_flags, description, toolchain_flags, + patch_arg, build)) _, out, _ = ce.RunCommandWOutput(command) if 'Tryjob submitted!' not in out: logger.GetLogger().LogFatal('Error occurred while launching trybot job: ' @@ -269,8 +275,8 @@ def GetTrybotImage(chromeos_root, build_info = GetBuildInfo(base_dir, build) if not build_info: if pending_time > TIME_OUT: - logger.GetLogger().LogFatal('Unable to get build logs for target %s.' % - build) + logger.GetLogger().LogFatal( + 'Unable to get build logs for target %s.' % build) else: pending_message = 'Unable to find build log; job may be pending.' done = False @@ -317,8 +323,8 @@ def GetTrybotImage(chromeos_root, (pending_time / 60)) pending_time += SLEEP_TIME else: - logger.GetLogger().LogOutput('{0} minutes passed.'.format(running_time / - 60)) + logger.GetLogger().LogOutput( + '{0} minutes passed.'.format(running_time / 60)) logger.GetLogger().LogOutput('Sleeping {0} seconds.'.format(SLEEP_TIME)) running_time += SLEEP_TIME @@ -340,8 +346,8 @@ def GetTrybotImage(chromeos_root, trybot_image = FindArchiveImage(chromeos_root, build, build_id) if not trybot_image: logger.GetLogger().LogError('Trybot job %s failed with status %d;' - ' no trybot image generated.' % - (description, build_status)) + ' no trybot image generated.' % (description, + build_status)) logger.GetLogger().LogOutput("trybot_image is '%s'" % trybot_image) logger.GetLogger().LogOutput('build_status is %d' % build_status) @@ -375,11 +381,30 @@ def WaitForImage(chromeos_root, build): while elapsed_time < TIME_OUT: if DoesImageExist(chromeos_root, build): return - logger.GetLogger().LogOutput('Image %s not ready, waiting for 10 minutes' % - build) + logger.GetLogger().LogOutput( + 'Image %s not ready, waiting for 10 minutes' % build) time.sleep(SLEEP_TIME) elapsed_time += SLEEP_TIME logger.GetLogger().LogOutput('Image %s not found, waited for %d hours' % (build, (TIME_OUT / 3600))) raise BuildbotTimeout('Timeout while waiting for image %s' % build) + + +def GetLatestImage(chromeos_root, path): + """Get latest image""" + + fmt = re.compile(r'R([0-9]+)-([0-9]+).([0-9]+).([0-9]+)') + + ce = command_executer.GetCommandExecuter() + command = ('gsutil ls gs://chromeos-image-archive/%s' % path) + _, out, _ = ce.ChrootRunCommandWOutput( + chromeos_root, command, print_to_console=False) + candidates = [l.split('/')[-2] for l in out.split()] + candidates = map(fmt.match, candidates) + candidates = [[int(r) for r in m.group(1, 2, 3, 4)] for m in candidates if m] + candidates.sort(reverse=True) + for c in candidates: + build = '%s/R%d-%d.%d.%d' % (path, c[0], c[1], c[2], c[3]) + if DoesImageExist(chromeos_root, build): + return build diff --git a/cros_utils/command_executer.py b/cros_utils/command_executer.py index c5614513..ae1b2962 100644 --- a/cros_utils/command_executer.py +++ b/cros_utils/command_executer.py @@ -98,11 +98,13 @@ class CommandExecuter(object): # In this way the child cannot mess the parent's terminal. p = None try: - p = subprocess.Popen(cmd, - stdout=subprocess.PIPE, - stderr=subprocess.PIPE, - shell=True, - preexec_fn=os.setsid) + p = subprocess.Popen( + cmd, + stdout=subprocess.PIPE, + stderr=subprocess.PIPE, + shell=True, + preexec_fn=os.setsid, + executable='/bin/bash') full_stdout = '' full_stderr = '' @@ -156,8 +158,7 @@ class CommandExecuter(object): if self.logger: self.logger.LogWarning('Timeout of %s seconds reached since ' 'process termination.' % - terminated_timeout, - print_to_console) + terminated_timeout, print_to_console) break if (command_timeout is not None and @@ -277,14 +278,15 @@ class CommandExecuter(object): # Write all commands to a file. command_file = self.WriteToTempShFile(cmd) - retval = self.CopyFiles(command_file, - command_file, - dest_machine=machine, - command_terminator=command_terminator, - chromeos_root=chromeos_root, - dest_cros=True, - recursive=False, - print_to_console=print_to_console) + retval = self.CopyFiles( + command_file, + command_file, + dest_machine=machine, + command_terminator=command_terminator, + chromeos_root=chromeos_root, + dest_cros=True, + recursive=False, + print_to_console=print_to_console) if retval: if self.logger: self.logger.LogError('Could not run remote command on machine.' @@ -294,12 +296,13 @@ class CommandExecuter(object): command = self.RemoteAccessInitCommand(chromeos_root, machine) command += '\nremote_sh bash %s' % command_file command += "\nl_retval=$?; echo \"$REMOTE_OUT\"; exit $l_retval" - retval = self.RunCommandGeneric(command, - return_output, - command_terminator=command_terminator, - command_timeout=command_timeout, - terminated_timeout=terminated_timeout, - print_to_console=print_to_console) + retval = self.RunCommandGeneric( + command, + return_output, + command_terminator=command_terminator, + command_timeout=command_timeout, + terminated_timeout=terminated_timeout, + print_to_console=print_to_console) if return_output: connect_signature = ( 'Initiating first contact with remote host\n' + 'Connection OK\n') @@ -368,8 +371,8 @@ class CommandExecuter(object): # the chroot already exists. We want the final returned output to skip # the output from chroot creation steps. if return_output: - ret = self.RunCommand('cd %s; cros_sdk %s -- true' % - (chromeos_root, cros_sdk_options)) + ret = self.RunCommand('cd %s; cros_sdk %s -- true' % (chromeos_root, + cros_sdk_options)) if ret: return (ret, '', '') @@ -378,12 +381,13 @@ class CommandExecuter(object): command = ("cd %s; cros_sdk %s -- bash -c '%s/%s'" % (chromeos_root, cros_sdk_options, misc.CHROMEOS_SCRIPTS_DIR, os.path.basename(command_file))) - ret = self.RunCommandGeneric(command, - return_output, - command_terminator=command_terminator, - command_timeout=command_timeout, - terminated_timeout=terminated_timeout, - print_to_console=print_to_console) + ret = self.RunCommandGeneric( + command, + return_output, + command_terminator=command_terminator, + command_timeout=command_timeout, + terminated_timeout=terminated_timeout, + print_to_console=print_to_console) os.remove(command_file) return ret @@ -419,10 +423,11 @@ class CommandExecuter(object): username=None, command_terminator=None): cmd = ' ;\n'.join(cmdlist) - return self.RunCommand(cmd, - machine=machine, - username=username, - command_terminator=command_terminator) + return self.RunCommand( + cmd, + machine=machine, + username=username, + command_terminator=command_terminator) def CopyFiles(self, src, @@ -464,18 +469,20 @@ class CommandExecuter(object): rsync_prefix = "\nrsync -r -e \"%s\" " % ssh_command if dest_cros == True: command += rsync_prefix + '%s root@%s:%s' % (src, dest_machine, dest) - return self.RunCommand(command, - machine=src_machine, - username=src_user, - command_terminator=command_terminator, - print_to_console=print_to_console) + return self.RunCommand( + command, + machine=src_machine, + username=src_user, + command_terminator=command_terminator, + print_to_console=print_to_console) else: command += rsync_prefix + 'root@%s:%s %s' % (src_machine, src, dest) - return self.RunCommand(command, - machine=dest_machine, - username=dest_user, - command_terminator=command_terminator, - print_to_console=print_to_console) + return self.RunCommand( + command, + machine=dest_machine, + username=dest_user, + command_terminator=command_terminator, + print_to_console=print_to_console) if dest_machine == src_machine: command = 'rsync -a %s %s' % (src, dest) @@ -484,11 +491,12 @@ class CommandExecuter(object): src_machine = os.uname()[1] src_user = getpass.getuser() command = 'rsync -a %s@%s:%s %s' % (src_user, src_machine, src, dest) - return self.RunCommand(command, - machine=dest_machine, - username=dest_user, - command_terminator=command_terminator, - print_to_console=print_to_console) + return self.RunCommand( + command, + machine=dest_machine, + username=dest_user, + command_terminator=command_terminator, + print_to_console=print_to_console) def RunCommand2(self, cmd, @@ -557,9 +565,8 @@ class CommandExecuter(object): def notify_line(self): p = self._buf.find('\n') while p >= 0: - self._line_consumer(line=self._buf[:p + 1], - output=self._name, - pobject=self._pobject) + self._line_consumer( + line=self._buf[:p + 1], output=self._name, pobject=self._pobject) if p < len(self._buf) - 1: self._buf = self._buf[p + 1:] p = self._buf.find('\n') @@ -571,9 +578,8 @@ class CommandExecuter(object): def notify_eos(self): # Notify end of stream. The last line may not end with a '\n'. if self._buf != '': - self._line_consumer(line=self._buf, - output=self._name, - pobject=self._pobject) + self._line_consumer( + line=self._buf, output=self._name, pobject=self._pobject) self._buf = '' if self.log_level == 'verbose': @@ -605,15 +611,13 @@ class CommandExecuter(object): poll = select.poll() outfd = pobject.stdout.fileno() poll.register(outfd, select.POLLIN | select.POLLPRI) - handlermap = {outfd: - StreamHandler(pobject, outfd, 'stdout', line_consumer)} + handlermap = { + outfd: StreamHandler(pobject, outfd, 'stdout', line_consumer) + } if not join_stderr: errfd = pobject.stderr.fileno() - poll.register(errfd, - select.POLLIN | select.POLLPRI) - handlermap[errfd] = StreamHandler(pobject, - errfd, - 'stderr', + poll.register(errfd, select.POLLIN | select.POLLPRI) + handlermap[errfd] = StreamHandler(pobject, errfd, 'stderr', line_consumer) while len(handlermap): readables = poll.poll(300) diff --git a/cros_utils/manifest_versions.py b/cros_utils/manifest_versions.py index 52fd700f..47e2fb20 100644 --- a/cros_utils/manifest_versions.py +++ b/cros_utils/manifest_versions.py @@ -7,6 +7,7 @@ from __future__ import print_function __author__ = 'llozano@google.com (Luis Lozano)' +import copy import os import re import shutil @@ -48,8 +49,10 @@ class ManifestVersions(object): else: versions_git = ( 'https://chromium.googlesource.com/chromiumos/manifest-versions.git') - commands = ['cd {0}'.format(self.clone_location), - 'git clone {0}'.format(versions_git)] + commands = [ + 'cd {0}'.format(self.clone_location), + 'git clone {0}'.format(versions_git) + ] ret = self.ce.RunCommands(commands) if ret: logger.GetLogger().LogFatal('Failed to clone manifest-versions.') @@ -58,26 +61,78 @@ class ManifestVersions(object): if self.clone_location: shutil.rmtree(self.clone_location) + def TimeToVersionChromeOS(self, my_time): + """Convert timestamp to version number, in ChromeOS/Paladin.""" + cur_time = time.mktime(time.gmtime()) + des_time = float(my_time) + if cur_time - des_time > 7000000: + logger.GetLogger().LogFatal('The time you specify is too early.') + commands = [ + 'cd {0}'.format(self.clone_location), 'cd manifest-versions', + 'git checkout -f $(git rev-list' + + ' --max-count=1 --before={0} origin/master)'.format(my_time) + ] + ret = self.ce.RunCommands(commands) + if ret: + logger.GetLogger().LogFatal('Failed to checkout manifest at ' + 'specified time') + path = os.path.realpath( + '{0}/manifest-versions/LKGM/lkgm.xml'.format(self.clone_location)) + pp = path.split('/') + new_list = copy.deepcopy(pp) + for i, e in enumerate(pp): + if e == 'android-LKGM-candidates': + new_list[i] = 'paladin' + chrome_path = '/'.join(new_list) + if not os.path.exists(chrome_path): + logger.GetLogger().LogOutput('LKGM path is %s' % path) + logger.GetLogger().LogOutput('Cannot find path %s' % chrome_path) + pieces = os.path.basename(chrome_path).split('.') + pieces = pieces[:-2] + new_base = '.'.join(pieces) + '*' + wild_path = os.path.join('/', '/'.join(new_list[:-1]), new_base) + command = 'ls %s' % wild_path + ret, out, _ = self.ce.RunCommandWOutput(command) + if ret == 0: + out = out.strip() + files = out.split('\n') + latest = files[-1] + small = os.path.basename(latest).split('.xml')[0] + version = pp[-2] + '.' + small + else: + small = os.path.basename(path).split('.xml')[0] + version = pp[-2] + '.' + small + commands = [ + 'cd {0}'.format(self.clone_location), 'cd manifest-versions', + 'git checkout master' + ] + self.ce.RunCommands(commands) + return version + def TimeToVersion(self, my_time): """Convert timestamp to version number.""" cur_time = time.mktime(time.gmtime()) des_time = float(my_time) if cur_time - des_time > 7000000: logger.GetLogger().LogFatal('The time you specify is too early.') - commands = ['cd {0}'.format(self.clone_location), 'cd manifest-versions', - 'git checkout -f $(git rev-list' + - ' --max-count=1 --before={0} origin/master)'.format(my_time)] + commands = [ + 'cd {0}'.format(self.clone_location), 'cd manifest-versions', + 'git checkout -f $(git rev-list' + + ' --max-count=1 --before={0} origin/master)'.format(my_time) + ] ret = self.ce.RunCommands(commands) if ret: logger.GetLogger().LogFatal('Failed to checkout manifest at ' 'specified time') - path = os.path.realpath('{0}/manifest-versions/LKGM/lkgm.xml'.format( - self.clone_location)) + path = os.path.realpath( + '{0}/manifest-versions/LKGM/lkgm.xml'.format(self.clone_location)) pp = path.split('/') small = os.path.basename(path).split('.xml')[0] version = pp[-2] + '.' + small - commands = ['cd {0}'.format(self.clone_location), 'cd manifest-versions', - 'git checkout master'] + commands = [ + 'cd {0}'.format(self.clone_location), 'cd manifest-versions', + 'git checkout master' + ] self.ce.RunCommands(commands) return version @@ -86,8 +141,10 @@ class ManifestVersions(object): assert not IsRFormatCrosVersion(version) version = version.split('.', 1)[1] os.chdir(self.clone_location) - files = [os.path.join(r, f) - for r, _, fs in os.walk('.') for f in fs if version in f] + files = [ + os.path.join(r, f) for r, _, fs in os.walk('.') for f in fs + if version in f + ] if files: command = 'cp {0} {1}'.format(files[0], to_file) ret = self.ce.RunCommand(command) 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) |