Reformat python files checked by pylint (part 1/2).
After recently changing .pylintrc (see [1]) we discovered that
the presubmit check always checks all the python files when just
one python file gets updated.
This CL moves all these files one step closer to what the linter
wants.
Autogenerated with:
# Added all the files under pylint control to ~/Desktop/to-reformat
cat ~/Desktop/to-reformat | xargs sed -i '1i\\'
git cl format --python --full
This is part 1 out of 2. The second part will fix function names and
will not be automated.
[1] - https://webrtc-review.googlesource.com/c/src/+/186664
No-Presubmit: True
Bug: webrtc:12114
Change-Id: Idfec4d759f209a2090440d0af2413a1ddc01b841
Reviewed-on: https://webrtc-review.googlesource.com/c/src/+/190980
Commit-Queue: Mirko Bonadei <mbonadei@webrtc.org>
Reviewed-by: Karl Wiberg <kwiberg@webrtc.org>
Cr-Commit-Position: refs/heads/master@{#32530}
diff --git a/rtc_tools/testing/build_apprtc.py b/rtc_tools/testing/build_apprtc.py
index 367a260..e93b7e0 100755
--- a/rtc_tools/testing/build_apprtc.py
+++ b/rtc_tools/testing/build_apprtc.py
@@ -6,7 +6,6 @@
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
-
"""Builds the AppRTC collider using the golang toolchain.
The golang toolchain is downloaded by download_apprtc.py. We use that here
@@ -24,44 +23,44 @@
import utils
-
USAGE_STR = "Usage: {} <apprtc_dir> <go_dir> <output_dir>"
def _ConfigureApprtcServerToDeveloperMode(app_yaml_path):
- for line in fileinput.input(app_yaml_path, inplace=True):
- # We can't click past these in browser-based tests, so disable them.
- line = line.replace('BYPASS_JOIN_CONFIRMATION: false',
- 'BYPASS_JOIN_CONFIRMATION: true')
- sys.stdout.write(line)
+ for line in fileinput.input(app_yaml_path, inplace=True):
+ # We can't click past these in browser-based tests, so disable them.
+ line = line.replace('BYPASS_JOIN_CONFIRMATION: false',
+ 'BYPASS_JOIN_CONFIRMATION: true')
+ sys.stdout.write(line)
def main(argv):
- if len(argv) != 4:
- return USAGE_STR.format(argv[0])
+ if len(argv) != 4:
+ return USAGE_STR.format(argv[0])
- apprtc_dir = os.path.abspath(argv[1])
- go_root_dir = os.path.abspath(argv[2])
- golang_workspace = os.path.abspath(argv[3])
+ apprtc_dir = os.path.abspath(argv[1])
+ go_root_dir = os.path.abspath(argv[2])
+ golang_workspace = os.path.abspath(argv[3])
- app_yaml_path = os.path.join(apprtc_dir, 'out', 'app_engine', 'app.yaml')
- _ConfigureApprtcServerToDeveloperMode(app_yaml_path)
+ app_yaml_path = os.path.join(apprtc_dir, 'out', 'app_engine', 'app.yaml')
+ _ConfigureApprtcServerToDeveloperMode(app_yaml_path)
- utils.RemoveDirectory(golang_workspace)
+ utils.RemoveDirectory(golang_workspace)
- collider_dir = os.path.join(apprtc_dir, 'src', 'collider')
- shutil.copytree(collider_dir, os.path.join(golang_workspace, 'src'))
+ collider_dir = os.path.join(apprtc_dir, 'src', 'collider')
+ shutil.copytree(collider_dir, os.path.join(golang_workspace, 'src'))
- golang_path = os.path.join(go_root_dir, 'bin',
- 'go' + utils.GetExecutableExtension())
- golang_env = os.environ.copy()
- golang_env['GOROOT'] = go_root_dir
- golang_env['GOPATH'] = golang_workspace
- collider_out = os.path.join(golang_workspace,
- 'collidermain' + utils.GetExecutableExtension())
- subprocess.check_call([golang_path, 'build', '-o', collider_out,
- 'collidermain'], env=golang_env)
+ golang_path = os.path.join(go_root_dir, 'bin',
+ 'go' + utils.GetExecutableExtension())
+ golang_env = os.environ.copy()
+ golang_env['GOROOT'] = go_root_dir
+ golang_env['GOPATH'] = golang_workspace
+ collider_out = os.path.join(
+ golang_workspace, 'collidermain' + utils.GetExecutableExtension())
+ subprocess.check_call(
+ [golang_path, 'build', '-o', collider_out, 'collidermain'],
+ env=golang_env)
if __name__ == '__main__':
- sys.exit(main(sys.argv))
+ sys.exit(main(sys.argv))
diff --git a/rtc_tools/testing/download_apprtc.py b/rtc_tools/testing/download_apprtc.py
index f6db785..a77955a 100755
--- a/rtc_tools/testing/download_apprtc.py
+++ b/rtc_tools/testing/download_apprtc.py
@@ -6,7 +6,6 @@
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
-
"""Downloads prebuilt AppRTC and Go from WebRTC storage and unpacks it.
Requires that depot_tools is installed and in the PATH.
@@ -21,38 +20,37 @@
import utils
-
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
def _GetGoArchivePathForPlatform():
- archive_extension = 'zip' if utils.GetPlatform() == 'win' else 'tar.gz'
- return os.path.join(utils.GetPlatform(), 'go.%s' % archive_extension)
+ archive_extension = 'zip' if utils.GetPlatform() == 'win' else 'tar.gz'
+ return os.path.join(utils.GetPlatform(), 'go.%s' % archive_extension)
def main(argv):
- if len(argv) > 2:
- return 'Usage: %s [output_dir]' % argv[0]
+ if len(argv) > 2:
+ return 'Usage: %s [output_dir]' % argv[0]
- output_dir = os.path.abspath(argv[1]) if len(argv) > 1 else None
+ output_dir = os.path.abspath(argv[1]) if len(argv) > 1 else None
- apprtc_zip_path = os.path.join(SCRIPT_DIR, 'prebuilt_apprtc.zip')
- if os.path.isfile(apprtc_zip_path + '.sha1'):
- utils.DownloadFilesFromGoogleStorage(SCRIPT_DIR, auto_platform=False)
+ apprtc_zip_path = os.path.join(SCRIPT_DIR, 'prebuilt_apprtc.zip')
+ if os.path.isfile(apprtc_zip_path + '.sha1'):
+ utils.DownloadFilesFromGoogleStorage(SCRIPT_DIR, auto_platform=False)
- if output_dir is not None:
- utils.RemoveDirectory(os.path.join(output_dir, 'apprtc'))
- utils.UnpackArchiveTo(apprtc_zip_path, output_dir)
+ if output_dir is not None:
+ utils.RemoveDirectory(os.path.join(output_dir, 'apprtc'))
+ utils.UnpackArchiveTo(apprtc_zip_path, output_dir)
- golang_path = os.path.join(SCRIPT_DIR, 'golang')
- golang_zip_path = os.path.join(golang_path, _GetGoArchivePathForPlatform())
- if os.path.isfile(golang_zip_path + '.sha1'):
- utils.DownloadFilesFromGoogleStorage(golang_path)
+ golang_path = os.path.join(SCRIPT_DIR, 'golang')
+ golang_zip_path = os.path.join(golang_path, _GetGoArchivePathForPlatform())
+ if os.path.isfile(golang_zip_path + '.sha1'):
+ utils.DownloadFilesFromGoogleStorage(golang_path)
- if output_dir is not None:
- utils.RemoveDirectory(os.path.join(output_dir, 'go'))
- utils.UnpackArchiveTo(golang_zip_path, output_dir)
+ if output_dir is not None:
+ utils.RemoveDirectory(os.path.join(output_dir, 'go'))
+ utils.UnpackArchiveTo(golang_zip_path, output_dir)
if __name__ == '__main__':
- sys.exit(main(sys.argv))
+ sys.exit(main(sys.argv))
diff --git a/rtc_tools/testing/setup_apprtc.py b/rtc_tools/testing/setup_apprtc.py
index 2b463e0..387ba69 100755
--- a/rtc_tools/testing/setup_apprtc.py
+++ b/rtc_tools/testing/setup_apprtc.py
@@ -6,7 +6,6 @@
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
-
"""This script sets up AppRTC and its dependencies.
Requires that depot_tools is installed and in the PATH.
@@ -19,27 +18,26 @@
import utils
-
SCRIPT_DIR = os.path.dirname(os.path.abspath(__file__))
def main(argv):
- if len(argv) == 1:
- return 'Usage %s <output_dir>' % argv[0]
+ if len(argv) == 1:
+ return 'Usage %s <output_dir>' % argv[0]
- output_dir = os.path.abspath(argv[1])
+ output_dir = os.path.abspath(argv[1])
- download_apprtc_path = os.path.join(SCRIPT_DIR, 'download_apprtc.py')
- utils.RunSubprocessWithRetry([sys.executable, download_apprtc_path,
- output_dir])
+ download_apprtc_path = os.path.join(SCRIPT_DIR, 'download_apprtc.py')
+ utils.RunSubprocessWithRetry(
+ [sys.executable, download_apprtc_path, output_dir])
- build_apprtc_path = os.path.join(SCRIPT_DIR, 'build_apprtc.py')
- apprtc_dir = os.path.join(output_dir, 'apprtc')
- go_dir = os.path.join(output_dir, 'go')
- collider_dir = os.path.join(output_dir, 'collider')
- utils.RunSubprocessWithRetry([sys.executable, build_apprtc_path,
- apprtc_dir, go_dir, collider_dir])
+ build_apprtc_path = os.path.join(SCRIPT_DIR, 'build_apprtc.py')
+ apprtc_dir = os.path.join(output_dir, 'apprtc')
+ go_dir = os.path.join(output_dir, 'go')
+ collider_dir = os.path.join(output_dir, 'collider')
+ utils.RunSubprocessWithRetry(
+ [sys.executable, build_apprtc_path, apprtc_dir, go_dir, collider_dir])
if __name__ == '__main__':
- sys.exit(main(sys.argv))
+ sys.exit(main(sys.argv))
diff --git a/rtc_tools/testing/utils.py b/rtc_tools/testing/utils.py
index 7968dad..8a5de50 100755
--- a/rtc_tools/testing/utils.py
+++ b/rtc_tools/testing/utils.py
@@ -6,7 +6,6 @@
# tree. An additional intellectual property rights grant can be found
# in the file PATENTS. All contributing project authors may
# be found in the AUTHORS file in the root of the source tree.
-
"""Utilities for all our deps-management stuff."""
from __future__ import absolute_import
@@ -23,36 +22,37 @@
def RunSubprocessWithRetry(cmd):
- """Invokes the subprocess and backs off exponentially on fail."""
- for i in range(5):
- try:
- subprocess.check_call(cmd)
- return
- except subprocess.CalledProcessError as exception:
- backoff = pow(2, i)
- print('Got %s, retrying in %d seconds...' % (exception, backoff))
- time.sleep(backoff)
+ """Invokes the subprocess and backs off exponentially on fail."""
+ for i in range(5):
+ try:
+ subprocess.check_call(cmd)
+ return
+ except subprocess.CalledProcessError as exception:
+ backoff = pow(2, i)
+ print('Got %s, retrying in %d seconds...' % (exception, backoff))
+ time.sleep(backoff)
- print('Giving up.')
- raise exception
+ print('Giving up.')
+ raise exception
def DownloadFilesFromGoogleStorage(path, auto_platform=True):
- print('Downloading files in %s...' % path)
+ print('Downloading files in %s...' % path)
- extension = 'bat' if 'win32' in sys.platform else 'py'
- cmd = ['download_from_google_storage.%s' % extension,
- '--bucket=chromium-webrtc-resources',
- '--directory', path]
- if auto_platform:
- cmd += ['--auto_platform', '--recursive']
- subprocess.check_call(cmd)
+ extension = 'bat' if 'win32' in sys.platform else 'py'
+ cmd = [
+ 'download_from_google_storage.%s' % extension,
+ '--bucket=chromium-webrtc-resources', '--directory', path
+ ]
+ if auto_platform:
+ cmd += ['--auto_platform', '--recursive']
+ subprocess.check_call(cmd)
# Code partially copied from
# https://cs.chromium.org#chromium/build/scripts/common/chromium_utils.py
def RemoveDirectory(*path):
- """Recursively removes a directory, even if it's marked read-only.
+ """Recursively removes a directory, even if it's marked read-only.
Remove the directory located at *path, if it exists.
@@ -67,62 +67,63 @@
bit and try again, so we do that too. It's hand-waving, but sometimes it
works. :/
"""
- file_path = os.path.join(*path)
- print('Deleting `{}`.'.format(file_path))
- if not os.path.exists(file_path):
- print('`{}` does not exist.'.format(file_path))
- return
+ file_path = os.path.join(*path)
+ print('Deleting `{}`.'.format(file_path))
+ if not os.path.exists(file_path):
+ print('`{}` does not exist.'.format(file_path))
+ return
- if sys.platform == 'win32':
- # Give up and use cmd.exe's rd command.
- file_path = os.path.normcase(file_path)
- for _ in range(3):
- print('RemoveDirectory running %s' % (' '.join(
- ['cmd.exe', '/c', 'rd', '/q', '/s', file_path])))
- if not subprocess.call(['cmd.exe', '/c', 'rd', '/q', '/s', file_path]):
- break
- print(' Failed')
- time.sleep(3)
- return
- else:
- shutil.rmtree(file_path, ignore_errors=True)
+ if sys.platform == 'win32':
+ # Give up and use cmd.exe's rd command.
+ file_path = os.path.normcase(file_path)
+ for _ in range(3):
+ print('RemoveDirectory running %s' %
+ (' '.join(['cmd.exe', '/c', 'rd', '/q', '/s', file_path])))
+ if not subprocess.call(
+ ['cmd.exe', '/c', 'rd', '/q', '/s', file_path]):
+ break
+ print(' Failed')
+ time.sleep(3)
+ return
+ else:
+ shutil.rmtree(file_path, ignore_errors=True)
def UnpackArchiveTo(archive_path, output_dir):
- extension = os.path.splitext(archive_path)[1]
- if extension == '.zip':
- _UnzipArchiveTo(archive_path, output_dir)
- else:
- _UntarArchiveTo(archive_path, output_dir)
+ extension = os.path.splitext(archive_path)[1]
+ if extension == '.zip':
+ _UnzipArchiveTo(archive_path, output_dir)
+ else:
+ _UntarArchiveTo(archive_path, output_dir)
def _UnzipArchiveTo(archive_path, output_dir):
- print('Unzipping {} in {}.'.format(archive_path, output_dir))
- zip_file = zipfile.ZipFile(archive_path)
- try:
- zip_file.extractall(output_dir)
- finally:
- zip_file.close()
+ print('Unzipping {} in {}.'.format(archive_path, output_dir))
+ zip_file = zipfile.ZipFile(archive_path)
+ try:
+ zip_file.extractall(output_dir)
+ finally:
+ zip_file.close()
def _UntarArchiveTo(archive_path, output_dir):
- print('Untarring {} in {}.'.format(archive_path, output_dir))
- tar_file = tarfile.open(archive_path, 'r:gz')
- try:
- tar_file.extractall(output_dir)
- finally:
- tar_file.close()
+ print('Untarring {} in {}.'.format(archive_path, output_dir))
+ tar_file = tarfile.open(archive_path, 'r:gz')
+ try:
+ tar_file.extractall(output_dir)
+ finally:
+ tar_file.close()
def GetPlatform():
- if sys.platform.startswith('win'):
- return 'win'
- if sys.platform.startswith('linux'):
- return 'linux'
- if sys.platform.startswith('darwin'):
- return 'mac'
- raise Exception("Can't run on platform %s." % sys.platform)
+ if sys.platform.startswith('win'):
+ return 'win'
+ if sys.platform.startswith('linux'):
+ return 'linux'
+ if sys.platform.startswith('darwin'):
+ return 'mac'
+ raise Exception("Can't run on platform %s." % sys.platform)
def GetExecutableExtension():
- return '.exe' if GetPlatform() == 'win' else ''
+ return '.exe' if GetPlatform() == 'win' else ''