diff options
author | Zhizhou Yang <zhizhouy@google.com> | 2020-02-10 16:51:20 -0800 |
---|---|---|
committer | Zhizhou Yang <zhizhouy@google.com> | 2020-02-12 01:34:49 +0000 |
commit | 81d651f89ac91819a77b8bd2ca720646326bf89a (patch) | |
tree | ec2f44c02809b95d036a8c619834ec4db8dba2e4 | |
parent | 4b68aee96e6c6b7593b8d91973168c817852b2b2 (diff) | |
download | toolchain-utils-81d651f89ac91819a77b8bd2ca720646326bf89a.tar.gz |
toolchain-utils: Partially port scripts to python 3
This patch ports some still-in-use python scripts under root directory
of toolchain-utils to python 3.
BUG=chromium:1011676
TEST=Passed unittests and tested with manually launching.
Change-Id: Id6066944780a7204fe4746cd271f41ac20f2274d
Reviewed-on: https://chromium-review.googlesource.com/c/chromiumos/third_party/toolchain-utils/+/2049103
Commit-Queue: Zhizhou Yang <zhizhouy@google.com>
Tested-by: Zhizhou Yang <zhizhouy@google.com>
Auto-Submit: Zhizhou Yang <zhizhouy@google.com>
Reviewed-by: George Burgess <gbiv@chromium.org>
-rwxr-xr-x | auto_delete_nightly_test_data.py | 2 | ||||
-rwxr-xr-x | build_chromeos.py | 68 | ||||
-rwxr-xr-x | build_tc.py | 16 | ||||
-rwxr-xr-x | buildbot_test_llvm.py | 8 | ||||
-rwxr-xr-x | buildbot_test_toolchains.py | 13 | ||||
-rwxr-xr-x | chromiumos_image_diff.py | 14 | ||||
-rwxr-xr-x | cros_utils/command_executer_timeout_test.py (renamed from command_executer_timeout_test.py) | 8 | ||||
-rwxr-xr-x | remote_kill_test.py | 44 | ||||
-rwxr-xr-x | remote_test.py | 8 | ||||
-rwxr-xr-x | run_tests_for.py | 9 | ||||
-rwxr-xr-x | setup_chromeos.py | 28 | ||||
-rwxr-xr-x | tc_enter_chroot.py | 30 | ||||
-rwxr-xr-x | update_telemetry_defaults.py | 38 |
13 files changed, 129 insertions, 157 deletions
diff --git a/auto_delete_nightly_test_data.py b/auto_delete_nightly_test_data.py index 59280e1f..429d0b4a 100755 --- a/auto_delete_nightly_test_data.py +++ b/auto_delete_nightly_test_data.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Copyright 2019 The Chromium OS Authors. All rights reserved. diff --git a/build_chromeos.py b/build_chromeos.py index 0b0676d1..e275da1f 100755 --- a/build_chromeos.py +++ b/build_chromeos.py @@ -1,6 +1,10 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- # -# Copyright 2010 Google Inc. All Rights Reserved. +# Copyright 2020 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + """Script to checkout the ChromeOS source. This script sets up the ChromeOS source in the given directory, matching a @@ -92,8 +96,8 @@ def Main(argv): dest='debug', default=False, action='store_true', - help=("Optional. Build chrome browser with \"-g -O0\". " - "Notice, this also turns on \'--dev\'. " + help=('Optional. Build chrome browser with "-g -O0". ' + "Notice, this also turns on '--dev'. " 'Defaults to False.')) parser.add_argument( '--env', dest='env', default='', help='Env to pass to build_packages.') @@ -133,7 +137,7 @@ def Main(argv): 'This flags is used internally by this script. ' 'Contact the author for more detail.')) - if options.rebuild == True: + if options.rebuild: build_packages_env += ' EXTRA_BOARD_FLAGS=-e' # EXTRA_BOARD_FLAGS=-e should clean up the object files for the chrome # browser but it doesn't. So do it here. @@ -166,10 +170,9 @@ def Main(argv): if not os.path.isdir(options.chromeos_root + '/chroot/build/' + options.board) or options.clobber_board: # Run build_tc.py from binary package - ret = cmd_executer.ChrootRunCommand(options.chromeos_root, - misc.GetSetupBoardCommand( - options.board, - force=options.clobber_board)) + ret = cmd_executer.ChrootRunCommand( + options.chromeos_root, + misc.GetSetupBoardCommand(options.board, force=options.clobber_board)) logger.GetLogger().LogFatalIf(ret, 'setup_board failed') else: logger.GetLogger().LogOutput('Did not setup_board ' @@ -179,23 +182,23 @@ def Main(argv): # Perform 2-step build_packages to build a debug chrome browser. # Firstly, build everything that chromeos-chrome depends on normally. - if options.rebuild == True: + if options.rebuild: # Give warning about "--rebuild" and "--debug". Under this combination, # only dependencies of "chromeos-chrome" get rebuilt. logger.GetLogger().LogWarning( - "\"--rebuild\" does not correctly re-build every package when " - "\"--debug\" is enabled. ") + '--rebuild" does not correctly re-build every package when ' + '"--debug" is enabled. ') # Replace EXTRA_BOARD_FLAGS=-e with "-e --onlydeps" build_packages_env = build_packages_env.replace( - 'EXTRA_BOARD_FLAGS=-e', 'EXTRA_BOARD_FLAGS=\"-e --onlydeps\"') + 'EXTRA_BOARD_FLAGS=-e', 'EXTRA_BOARD_FLAGS="-e --onlydeps"') else: build_packages_env += ' EXTRA_BOARD_FLAGS=--onlydeps' ret = cmd_executer.ChrootRunCommand( - options.chromeos_root, "CFLAGS=\"$(portageq-%s envvar CFLAGS) %s\" " - "CXXFLAGS=\"$(portageq-%s envvar CXXFLAGS) %s\" " - "LDFLAGS=\"$(portageq-%s envvar LDFLAGS) %s\" " + options.chromeos_root, 'CFLAGS="$(portageq-%s envvar CFLAGS) %s" ' + 'CXXFLAGS="$(portageq-%s envvar CXXFLAGS) %s" ' + 'LDFLAGS="$(portageq-%s envvar LDFLAGS) %s" ' 'CHROME_ORIGIN=SERVER_SOURCE ' '%s ' '%s --skip_chroot_upgrade' @@ -208,16 +211,16 @@ def Main(argv): # Secondly, build chromeos-chrome using debug mode. # Replace '--onlydeps' with '--nodeps'. - if options.rebuild == True: + if options.rebuild: build_packages_env = build_packages_env.replace( - 'EXTRA_BOARD_FLAGS=\"-e --onlydeps\"', 'EXTRA_BOARD_FLAGS=--nodeps') + 'EXTRA_BOARD_FLAGS="-e --onlydeps"', 'EXTRA_BOARD_FLAGS=--nodeps') else: build_packages_env = build_packages_env.replace( 'EXTRA_BOARD_FLAGS=--onlydeps', 'EXTRA_BOARD_FLAGS=--nodeps') ret = cmd_executer.ChrootRunCommand( - options.chromeos_root, "CFLAGS=\"$(portageq-%s envvar CFLAGS) %s\" " - "CXXFLAGS=\"$(portageq-%s envvar CXXFLAGS) %s\" " - "LDFLAGS=\"$(portageq-%s envvar LDFLAGS) %s\" " + options.chromeos_root, 'CFLAGS="$(portageq-%s envvar CFLAGS) %s" ' + 'CXXFLAGS="$(portageq-%s envvar CXXFLAGS) %s" ' + 'LDFLAGS="$(portageq-%s envvar LDFLAGS) %s" ' 'CHROME_ORIGIN=SERVER_SOURCE BUILDTYPE=Debug ' '%s ' '%s --skip_chroot_upgrade' @@ -237,11 +240,11 @@ def Main(argv): # Up to now, we have a debug built chromos-chrome browser. # Fall through to build the rest of the world. - # Build packages + # Build packages ret = cmd_executer.ChrootRunCommand( - options.chromeos_root, "CFLAGS=\"$(portageq-%s envvar CFLAGS) %s\" " - "CXXFLAGS=\"$(portageq-%s envvar CXXFLAGS) %s\" " - "LDFLAGS=\"$(portageq-%s envvar LDFLAGS) %s\" " + options.chromeos_root, 'CFLAGS="$(portageq-%s envvar CFLAGS) %s" ' + 'CXXFLAGS="$(portageq-%s envvar CXXFLAGS) %s" ' + 'LDFLAGS="$(portageq-%s envvar LDFLAGS) %s" ' 'CHROME_ORIGIN=SERVER_SOURCE ' '%s ' '%s --skip_chroot_upgrade' % @@ -261,19 +264,18 @@ def Main(argv): flags_file_name = 'flags.txt' flags_file_path = ('%s/src/build/images/%s/latest/%s' % (options.chromeos_root, options.board, flags_file_name)) - flags_file = open(flags_file_path, 'wb') - flags_file.write('CFLAGS=%s\n' % options.cflags) - flags_file.write('CXXFLAGS=%s\n' % options.cxxflags) - flags_file.write('LDFLAGS=%s\n' % options.ldflags) - flags_file.close() + with open(flags_file_path, 'w', encoding='utf-8') as flags_file: + flags_file.write('CFLAGS=%s\n' % options.cflags) + flags_file.write('CXXFLAGS=%s\n' % options.cxxflags) + flags_file.write('LDFLAGS=%s\n' % options.ldflags) if options.label: image_dir_path = ('%s/src/build/images/%s/latest' % (options.chromeos_root, options.board)) real_image_dir_path = os.path.realpath(image_dir_path) - command = ('ln -sf -T %s %s/%s' % - (os.path.basename(real_image_dir_path), - os.path.dirname(real_image_dir_path), options.label)) + command = ('ln -sf -T %s %s/%s' % (os.path.basename(real_image_dir_path), + os.path.dirname(real_image_dir_path), + options.label)) ret = cmd_executer.RunCommand(command) logger.GetLogger().LogFatalIf( diff --git a/build_tc.py b/build_tc.py index c14b6905..9b90f55c 100755 --- a/build_tc.py +++ b/build_tc.py @@ -1,8 +1,9 @@ -#!/usr/bin/env python2 -# +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- # Copyright 2010 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. + """Script to build the ChromeOS toolchain. This script sets up the toolchain if you give it the gcctools directory. @@ -100,8 +101,9 @@ class ToolchainPart(object): command = 'mkdir -p %s' % build_dir self._ce.RunCommand(command) - mounted_build_dir = os.path.join(self._chromeos_root, 'chroot', '%s-%s' % - (self._chroot_source_path, build_suffix)) + mounted_build_dir = os.path.join( + self._chromeos_root, 'chroot', + '%s-%s' % (self._chroot_source_path, build_suffix)) build_mp = tc_enter_chroot.MountPoint(build_dir, mounted_build_dir, getpass.getuser()) mount_points.append(build_mp) @@ -148,10 +150,10 @@ class ToolchainPart(object): if self._name == 'gcc' and not self._gcc_enable_ccache: env['USE'] += ' -wrapper_ccache' - env['%s_SOURCE_PATH' % self._name.upper()] = (os.path.join( - '/', self._chroot_source_path)) + env['%s_SOURCE_PATH' % self._name.upper()] = ( + os.path.join('/', self._chroot_source_path)) env['ACCEPT_KEYWORDS'] = '~*' - env_string = ' '.join(["%s=\"%s\"" % var for var in env.items()]) + env_string = ' '.join(['%s="%s"' % var for var in env.items()]) command = 'emerge =cross-%s/%s-9999' % (self._ctarget, self._name) full_command = 'sudo %s %s' % (env_string, command) rv = self._ce.ChrootRunCommand(self._chromeos_root, full_command) diff --git a/buildbot_test_llvm.py b/buildbot_test_llvm.py index 7e7c6e63..968c67b8 100755 --- a/buildbot_test_llvm.py +++ b/buildbot_test_llvm.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Copyright 2017 The Chromium OS Authors. All rights reserved. @@ -125,7 +125,7 @@ def WriteRotatingReportsData(results_dict, date): """Write data for waterfall report.""" fname = '%d-%02d-%02d.builds' % (date.year, date.month, date.day) filename = os.path.join(DATA_DIR, 'rotating-builders', fname) - with open(filename, 'w') as out_file: + with open(filename, 'w', encoding='utf-8') as out_file: for board in results_dict.keys(): buildbucket_id = results_dict[board] out_file.write('%s,%s\n' % (buildbucket_id, board)) @@ -172,7 +172,7 @@ def Main(argv): if options.board: fv = ToolchainVerifier(options.board, options.chromeos_root, options.weekday, options.patches, options.compiler) - return fv.Doall() + return fv.DoAll() today = datetime.date.today() delta = today - START_DATE @@ -190,7 +190,7 @@ def Main(argv): results_dict[board] = buildbucket_id except SystemExit: logfile = os.path.join(VALIDATION_RESULT_DIR, options.compiler, board) - with open(logfile, 'w') as f: + with open(logfile, 'w', encoding='utf-8') as f: f.write('Verifier got an exception, please check the log.\n') WriteRotatingReportsData(results_dict, today) diff --git a/buildbot_test_toolchains.py b/buildbot_test_toolchains.py index be18d467..5f7c21d3 100755 --- a/buildbot_test_toolchains.py +++ b/buildbot_test_toolchains.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Copyright 2016 The Chromium OS Authors. All rights reserved. @@ -195,7 +195,7 @@ class ToolchainComparator(object): } """ - with open(experiment_file, 'w') as f: + with open(experiment_file, 'w', encoding='utf-8') as f: f.write(experiment_header) f.write(experiment_tests) @@ -251,11 +251,10 @@ class ToolchainComparator(object): ret = self._ce.RunCommand(command) if ret != 0: raise RuntimeError('Crosperf execution error!') - else: - # Copy json report to pending archives directory. - command = 'cp %s/*.json %s/.' % (self._reports_dir, PENDING_ARCHIVES_DIR) - ret = self._ce.RunCommand(command) - return + + # Copy json report to pending archives directory. + command = 'cp %s/*.json %s/.' % (self._reports_dir, PENDING_ARCHIVES_DIR) + ret = self._ce.RunCommand(command) def _SendEmail(self): """Find email message generated by crosperf and send it.""" diff --git a/chromiumos_image_diff.py b/chromiumos_image_diff.py index 74906d32..66a54ccc 100755 --- a/chromiumos_image_diff.py +++ b/chromiumos_image_diff.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Copyright 2019 The Chromium OS Authors. All rights reserved. @@ -86,7 +86,7 @@ class CrosImage(object): '{r}/var {r}/mnt/stateful_partition {r}; sudo umount {s} ; ' 'rmdir {r} ; rmdir {s}\n').format( r=self.rootfs, s=self.stateful) - f = open(self.unmount_script, 'w') + f = open(self.unmount_script, 'w', encoding='utf-8') f.write(command) f.close() self._ce.RunCommand( @@ -160,9 +160,9 @@ class ImageComparator(object): i1 = self.images[0] i2 = self.images[1] t1 = i1.rootfs + '/' - elfset1 = set([e.replace(t1, '') for e in i1.elf_files]) + elfset1 = {e.replace(t1, '') for e in i1.elf_files} t2 = i2.rootfs + '/' - elfset2 = set([e.replace(t2, '') for e in i2.elf_files]) + elfset2 = {e.replace(t2, '') for e in i2.elf_files} dif1 = elfset1.difference(elfset2) msg = None if dif1: @@ -210,15 +210,15 @@ class ImageComparator(object): if full_path1 == full_path2: self.logger.LogError( - 'Error: We\'re comparing the SAME file - {0}'.format(f1)) + "Error: We're comparing the SAME file - {0}".format(f1)) continue command = ( 'objdump -d "{f1}" > {tempf1} ; ' 'objdump -d "{f2}" > {tempf2} ; ' # Remove path string inside the dissemble - 'sed -i \'s!{rootfs1}!!g\' {tempf1} ; ' - 'sed -i \'s!{rootfs2}!!g\' {tempf2} ; ' + "sed -i 's!{rootfs1}!!g' {tempf1} ; " + "sed -i 's!{rootfs2}!!g' {tempf2} ; " 'diff {tempf1} {tempf2} 1>/dev/null 2>&1').format( f1=full_path1, f2=full_path2, diff --git a/command_executer_timeout_test.py b/cros_utils/command_executer_timeout_test.py index 26f39334..1c9c74cd 100755 --- a/command_executer_timeout_test.py +++ b/cros_utils/command_executer_timeout_test.py @@ -1,6 +1,10 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- # -# Copyright 2010 Google Inc. All Rights Reserved. +# Copyright 2020 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + """Timeout test for command_executer.""" from __future__ import print_function diff --git a/remote_kill_test.py b/remote_kill_test.py deleted file mode 100755 index e0f29d0c..00000000 --- a/remote_kill_test.py +++ /dev/null @@ -1,44 +0,0 @@ -#!/usr/bin/env python2 -# -# Copyright 2010 Google Inc. All Rights Reserved. -"""Script to wrap test_that script. - -Run this script and kill it. Then run ps -ef to see if sleep -is still running,. -""" - -from __future__ import print_function - -__author__ = 'asharif@google.com (Ahmad Sharif)' - -import argparse -import os -import sys - -from cros_utils import command_executer - - -def Usage(parser, message): - print('ERROR: %s' % message) - parser.print_help() - sys.exit(0) - - -def Main(argv): - parser = argparse.ArgumentParser() - parser.add_argument( - '-c', - '--chromeos_root', - dest='chromeos_root', - help='ChromeOS root checkout directory') - parser.add_argument( - '-r', '--remote', dest='remote', help='Remote chromeos device.') - - _ = parser.parse_args(argv) - ce = command_executer.GetCommandExecuter() - ce.RunCommand('ls; sleep 10000', machine=os.uname()[1]) - return 0 - - -if __name__ == '__main__': - Main(sys.argv[1:]) diff --git a/remote_test.py b/remote_test.py index 62598d5a..98ff62a5 100755 --- a/remote_test.py +++ b/remote_test.py @@ -1,6 +1,10 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- # -# Copyright 2010 Google Inc. All Rights Reserved. +# Copyright 2020 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + """Script to wrap test_that script. This script can login to the chromeos machine using the test private key. diff --git a/run_tests_for.py b/run_tests_for.py index 6f77b12c..cb8e6430 100755 --- a/run_tests_for.py +++ b/run_tests_for.py @@ -1,4 +1,4 @@ -#!/usr/bin/env python2 +#!/usr/bin/env python3 # -*- coding: utf-8 -*- # # Copyright 2019 The Chromium OS Authors. All rights reserved. @@ -68,7 +68,8 @@ def _run_test(test_spec): cwd=test_spec.directory, stdin=open('/dev/null'), stdout=subprocess.PIPE, - stderr=subprocess.STDOUT) + stderr=subprocess.STDOUT, + encoding='utf-8') stdout, _ = p.communicate() exit_code = p.wait() return exit_code, stdout @@ -84,8 +85,8 @@ def _python_test_to_spec(test_file): if os.access(test_file, os.X_OK): command = ['./' + file_name] else: - # Assume the user wanted py2. - command = ['python2', file_name] + # Assume the user wanted py3. + command = ['python3', file_name] return TestSpec(directory=test_directory, command=command) diff --git a/setup_chromeos.py b/setup_chromeos.py index 0b51d830..63206492 100755 --- a/setup_chromeos.py +++ b/setup_chromeos.py @@ -1,8 +1,9 @@ -#!/usr/bin/env python2 -# +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- # Copyright 2010 The Chromium OS Authors. All rights reserved. # Use of this source code is governed by a BSD-style license that can be # found in the LICENSE file. + """Script to checkout the ChromeOS source. This script sets up the ChromeOS source in the given directory, matching a @@ -85,7 +86,7 @@ def GetVersionSpecFile(version, versions_git): def TimeToCommonVersion(timestamp): """Convert timestamp to common image version.""" tdt = datetime.fromtimestamp(float(timestamp)) - with open(COMMON_VERSIONS, 'r') as f: + with open(COMMON_VERSIONS, 'r', encoding='utf-8') as f: common_list = pickle.load(f) for sv in common_list: sdt = datetime.strptime(sv['date'], '%Y-%m-%d %H:%M:%S.%f') @@ -157,7 +158,7 @@ Default is 'latest_lkgm'.""") if version not in ('lkgm', 'common'): parser.print_help() logger.GetLogger().LogFatal('timestamp option only applies for ' - "versions \"lkgm\" or \"common\"") + 'versions "lkgm" or "common"') if not options.directory: parser.print_help() @@ -181,8 +182,8 @@ Default is 'latest_lkgm'.""") manifests = manifest_versions.ManifestVersions() version = manifests.TimeToVersionChromeOS(time.mktime(time.gmtime())) version, manifest = version.split('.', 1) - logger.GetLogger().LogOutput('found version %s.%s for latest LKGM' % - (version, manifest)) + logger.GetLogger().LogOutput( + 'found version %s.%s for latest LKGM' % (version, manifest)) init = ('repo init -u %s -m paladin/buildspecs/%s/%s.xml' % (versions_repo, version, manifest)) del manifests @@ -193,17 +194,16 @@ Default is 'latest_lkgm'.""") manifests = manifest_versions.ManifestVersions() version = manifests.TimeToVersion(timestamp) version, manifest = version.split('.', 1) - logger.GetLogger().LogOutput( - 'found version %s.%s for LKGM at timestamp %s' % (version, manifest, - timestamp)) + logger.GetLogger().LogOutput('found version %s.%s for LKGM at timestamp %s' + % (version, manifest, timestamp)) init = ('repo init -u %s -m paladin/buildspecs/%s/%s.xml' % (versions_repo, version, manifest)) del manifests elif version == 'latest_common': version = TimeToCommonVersion(time.mktime(time.gmtime())) version, manifest = version.split('.', 1) - logger.GetLogger().LogOutput('found version %s.%s for latest Common image' % - (version, manifest)) + logger.GetLogger().LogOutput( + 'found version %s.%s for latest Common image' % (version, manifest)) init = ('repo init -u %s -m buildspecs/%s/%s.xml' % (versions_repo, version, manifest)) elif version == 'common': @@ -212,9 +212,9 @@ Default is 'latest_lkgm'.""") logger.GetLogger().LogFatal('No timestamp specified for version=lkgm') version = TimeToCommonVersion(timestamp) version, manifest = version.split('.', 1) - logger.GetLogger().LogOutput('found version %s.%s for latest common image ' - 'at timestamp %s' % (version, manifest, - timestamp)) + logger.GetLogger().LogOutput( + 'found version %s.%s for latest common image ' + 'at timestamp %s' % (version, manifest, timestamp)) init = ('repo init -u %s -m buildspecs/%s/%s.xml' % (versions_repo, version, manifest)) else: diff --git a/tc_enter_chroot.py b/tc_enter_chroot.py index d919c96d..3a7538ad 100755 --- a/tc_enter_chroot.py +++ b/tc_enter_chroot.py @@ -1,6 +1,9 @@ -#!/usr/bin/env python2 -# -# Copyright 2010 Google Inc. All Rights Reserved. +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright 2010 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + """Script to enter the ChromeOS chroot with mounted sources. This script enters the chroot with mounted sources. @@ -191,10 +194,10 @@ def Main(argv, return_output=False): '%s/../../../third_party' % os.path.dirname(__file__)) if os.path.isdir(third_party_dir): - mount_point = MountPoint(third_party_dir, - ('%s/%s' % (full_mounted_tc_root, - os.path.basename(third_party_dir))), - getpass.getuser()) + mount_point = MountPoint( + third_party_dir, + ('%s/%s' % (full_mounted_tc_root, os.path.basename(third_party_dir))), + getpass.getuser()) mount_points.append(mount_point) output = options.output @@ -243,16 +246,15 @@ def Main(argv, return_output=False): inner_command = inner_command[3:] command_file = 'tc_enter_chroot.cmd' command_file_path = chromeos_root + '/src/scripts/' + command_file - retv = command_executer.GetCommandExecuter().RunCommand( - 'sudo rm -f ' + command_file_path) + retv = command_executer.GetCommandExecuter().RunCommand('sudo rm -f ' + + command_file_path) if retv != 0: return retv - f = open(command_file_path, 'w') - f.write(inner_command) - f.close() + with open(command_file_path, 'w', encoding='utf-8') as f: + f.write(inner_command) logger.GetLogger().LogCmd(inner_command) - retv = command_executer.GetCommandExecuter().RunCommand( - 'chmod +x ' + command_file_path) + retv = command_executer.GetCommandExecuter().RunCommand('chmod +x ' + + command_file_path) if retv != 0: return retv diff --git a/update_telemetry_defaults.py b/update_telemetry_defaults.py index 943dc261..c070aeb1 100755 --- a/update_telemetry_defaults.py +++ b/update_telemetry_defaults.py @@ -1,6 +1,9 @@ -#!/usr/bin/env python2 -# -# Copyright 2013 Google Inc. All Rights Reserved. +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# Copyright 2020 The Chromium OS Authors. All rights reserved. +# Use of this source code is governed by a BSD-style license that can be +# found in the LICENSE file. + """Script to maintain the Telemetry benchmark default results file. This script allows the user to see and update the set of default @@ -36,20 +39,20 @@ class TelemetryDefaults(object): def ReadDefaultsFile(self): if os.path.exists(self._filename): - with open(self._filename, 'r') as fp: + with open(self._filename, 'r', encoding='utf-8') as fp: self._defaults = json.load(fp) def WriteDefaultsFile(self): - with open(self._filename, 'w') as fp: + with open(self._filename, 'w', encoding='utf-8') as fp: json.dump(self._defaults, fp, indent=2) - def ListCurrentDefaults(self, benchmark=all): + def ListCurrentDefaults(self, benchmark='all'): # Show user current defaults. By default, show all. The user # can specify the name of a particular benchmark to see only that # benchmark's default values. if len(self._defaults) == 0: print('The benchmark default results are currently empty.') - if benchmark == all: + if benchmark == 'all': for b in self._defaults.keys(): results = self._defaults[b] out_str = b + ' : ' @@ -83,8 +86,8 @@ class TelemetryDefaults(object): print("Updated results set for '%s': " % benchmark) print('%s : %s' % (benchmark, repr(self._defaults[benchmark]))) else: - print("'%s' is not in '%s's default results list." % (result, - benchmark)) + print( + "'%s' is not in '%s's default results list." % (result, benchmark)) else: print("Cannot find benchmark named '%s'" % benchmark) @@ -145,14 +148,14 @@ lower) does not matter, for the command (case of the result name DOES matter): words = inp.split(' ') option = words[0] option = option.lower() - if option == 'h' or option == 'help': + if option in ('h', 'help'): self.ShowOptions() - elif option == 'l' or option == 'list': + elif option in ('l', 'list'): if len(words) == 1: self.ListCurrentDefaults() else: self.ListCurrentDefaults(benchmark=words[1]) - elif option == 'a' or option == 'add': + elif option in ('a', 'add'): if len(words) < 3: self.UsageError(inp) else: @@ -160,31 +163,30 @@ lower) does not matter, for the command (case of the result name DOES matter): resultList = words[2:] for r in resultList: self.AddDefault(benchmark, r) - elif option == 'd' or option == 'delete': + elif option in ('d', 'delete'): if len(words) != 3: self.UsageError(inp) else: benchmark = words[1] result = words[2] self.RemoveDefault(benchmark, result) - elif option == 'r' or option == 'remove': + elif option in ('r', 'remove'): if len(words) != 2: self.UsageError(inp) else: benchmark = words[1] self.RemoveBenchmark(benchmark) - elif option == 'm' or option == 'move': + elif option in ('m', 'move'): if len(words) != 3: self.UsageError(inp) else: old_name = words[1] new_name = words[2] self.RenameBenchmark(old_name, new_name) - elif option == 'q' or option == 'quit': + elif option in ('q', 'quit'): self.WriteDefaultsFile() - return (option == 'q' or option == 'quit' or option == 't' or - option == 'terminate') + return option in ('q', 'quit', 't', 'terminate') def Main(): |