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/tools_webrtc/libs/generate_licenses.py b/tools_webrtc/libs/generate_licenses.py
index 0e5a9ef..b1587af 100755
--- a/tools_webrtc/libs/generate_licenses.py
+++ b/tools_webrtc/libs/generate_licenses.py
@@ -36,12 +36,16 @@
     'abseil-cpp': ['third_party/abseil-cpp/LICENSE'],
     'android_ndk': ['third_party/android_ndk/NOTICE'],
     'android_sdk': ['third_party/android_sdk/LICENSE'],
-    'auto': ['third_party/android_deps/libs/'
-             'com_google_auto_service_auto_service/LICENSE'],
+    'auto': [
+        'third_party/android_deps/libs/'
+        'com_google_auto_service_auto_service/LICENSE'
+    ],
     'bazel': ['third_party/bazel/LICENSE'],
     'boringssl': ['third_party/boringssl/src/LICENSE'],
-    'errorprone': ['third_party/android_deps/libs/'
-                   'com_google_errorprone_error_prone_core/LICENSE'],
+    'errorprone': [
+        'third_party/android_deps/libs/'
+        'com_google_errorprone_error_prone_core/LICENSE'
+    ],
     'fiat': ['third_party/boringssl/src/third_party/fiat/LICENSE'],
     'guava': ['third_party/guava/LICENSE'],
     'ijar': ['third_party/ijar/LICENSE'],
@@ -95,11 +99,11 @@
 
 
 def FindSrcDirPath():
-  """Returns the abs path to the src/ dir of the project."""
-  src_dir = os.path.dirname(os.path.abspath(__file__))
-  while os.path.basename(src_dir) != 'src':
-    src_dir = os.path.normpath(os.path.join(src_dir, os.pardir))
-  return src_dir
+    """Returns the abs path to the src/ dir of the project."""
+    src_dir = os.path.dirname(os.path.abspath(__file__))
+    while os.path.basename(src_dir) != 'src':
+        src_dir = os.path.normpath(os.path.join(src_dir, os.pardir))
+    return src_dir
 
 
 SCRIPT_DIR = os.path.dirname(os.path.realpath(sys.argv[0]))
@@ -113,29 +117,28 @@
 
 
 class LicenseBuilder(object):
+    def __init__(self,
+                 buildfile_dirs,
+                 targets,
+                 lib_to_licenses_dict=None,
+                 lib_regex_to_licenses_dict=None):
+        if lib_to_licenses_dict is None:
+            lib_to_licenses_dict = LIB_TO_LICENSES_DICT
 
-  def __init__(self,
-               buildfile_dirs,
-               targets,
-               lib_to_licenses_dict=None,
-               lib_regex_to_licenses_dict=None):
-    if lib_to_licenses_dict is None:
-      lib_to_licenses_dict = LIB_TO_LICENSES_DICT
+        if lib_regex_to_licenses_dict is None:
+            lib_regex_to_licenses_dict = LIB_REGEX_TO_LICENSES_DICT
 
-    if lib_regex_to_licenses_dict is None:
-      lib_regex_to_licenses_dict = LIB_REGEX_TO_LICENSES_DICT
+        self.buildfile_dirs = buildfile_dirs
+        self.targets = targets
+        self.lib_to_licenses_dict = lib_to_licenses_dict
+        self.lib_regex_to_licenses_dict = lib_regex_to_licenses_dict
 
-    self.buildfile_dirs = buildfile_dirs
-    self.targets = targets
-    self.lib_to_licenses_dict = lib_to_licenses_dict
-    self.lib_regex_to_licenses_dict = lib_regex_to_licenses_dict
+        self.common_licenses_dict = self.lib_to_licenses_dict.copy()
+        self.common_licenses_dict.update(self.lib_regex_to_licenses_dict)
 
-    self.common_licenses_dict = self.lib_to_licenses_dict.copy()
-    self.common_licenses_dict.update(self.lib_regex_to_licenses_dict)
-
-  @staticmethod
-  def _ParseLibraryName(dep):
-    """Returns library name after third_party
+    @staticmethod
+    def _ParseLibraryName(dep):
+        """Returns library name after third_party
 
     Input one of:
     //a/b/third_party/libname:c
@@ -144,11 +147,11 @@
 
     Outputs libname or None if this is not a third_party dependency.
     """
-    groups = re.match(THIRD_PARTY_LIB_SIMPLE_NAME_REGEX, dep)
-    return groups.group(1) if groups else None
+        groups = re.match(THIRD_PARTY_LIB_SIMPLE_NAME_REGEX, dep)
+        return groups.group(1) if groups else None
 
-  def _ParseLibrary(self, dep):
-    """Returns library simple or regex name that matches `dep` after third_party
+    def _ParseLibrary(self, dep):
+        """Returns library simple or regex name that matches `dep` after third_party
 
     This method matches `dep` dependency against simple names in
     LIB_TO_LICENSES_DICT and regular expression names in
@@ -156,104 +159,109 @@
 
     Outputs matched dict key or None if this is not a third_party dependency.
     """
-    libname = LicenseBuilder._ParseLibraryName(dep)
+        libname = LicenseBuilder._ParseLibraryName(dep)
 
-    for lib_regex in self.lib_regex_to_licenses_dict:
-      if re.match(THIRD_PARTY_LIB_REGEX_TEMPLATE % lib_regex, dep):
-        return lib_regex
+        for lib_regex in self.lib_regex_to_licenses_dict:
+            if re.match(THIRD_PARTY_LIB_REGEX_TEMPLATE % lib_regex, dep):
+                return lib_regex
 
-    return libname
+        return libname
 
-  @staticmethod
-  def _RunGN(buildfile_dir, target):
-    cmd = [
-        sys.executable,
-        os.path.join(find_depot_tools.DEPOT_TOOLS_PATH, 'gn.py'),
-        'desc',
-        '--all',
-        '--format=json',
-        os.path.abspath(buildfile_dir),
-        target,
-    ]
-    logging.debug('Running: %r', cmd)
-    output_json = subprocess.check_output(cmd, cwd=WEBRTC_ROOT)
-    logging.debug('Output: %s', output_json)
-    return output_json
+    @staticmethod
+    def _RunGN(buildfile_dir, target):
+        cmd = [
+            sys.executable,
+            os.path.join(find_depot_tools.DEPOT_TOOLS_PATH, 'gn.py'),
+            'desc',
+            '--all',
+            '--format=json',
+            os.path.abspath(buildfile_dir),
+            target,
+        ]
+        logging.debug('Running: %r', cmd)
+        output_json = subprocess.check_output(cmd, cwd=WEBRTC_ROOT)
+        logging.debug('Output: %s', output_json)
+        return output_json
 
-  def _GetThirdPartyLibraries(self, buildfile_dir, target):
-    output = json.loads(LicenseBuilder._RunGN(buildfile_dir, target))
-    libraries = set()
-    for described_target in output.values():
-      third_party_libs = (
-          self._ParseLibrary(dep) for dep in described_target['deps'])
-      libraries |= set(lib for lib in third_party_libs if lib)
-    return libraries
+    def _GetThirdPartyLibraries(self, buildfile_dir, target):
+        output = json.loads(LicenseBuilder._RunGN(buildfile_dir, target))
+        libraries = set()
+        for described_target in output.values():
+            third_party_libs = (self._ParseLibrary(dep)
+                                for dep in described_target['deps'])
+            libraries |= set(lib for lib in third_party_libs if lib)
+        return libraries
 
-  def GenerateLicenseText(self, output_dir):
-    # Get a list of third_party libs from gn. For fat libraries we must consider
-    # all architectures, hence the multiple buildfile directories.
-    third_party_libs = set()
-    for buildfile in self.buildfile_dirs:
-      for target in self.targets:
-        third_party_libs |= self._GetThirdPartyLibraries(buildfile, target)
-    assert len(third_party_libs) > 0
+    def GenerateLicenseText(self, output_dir):
+        # Get a list of third_party libs from gn. For fat libraries we must consider
+        # all architectures, hence the multiple buildfile directories.
+        third_party_libs = set()
+        for buildfile in self.buildfile_dirs:
+            for target in self.targets:
+                third_party_libs |= self._GetThirdPartyLibraries(
+                    buildfile, target)
+        assert len(third_party_libs) > 0
 
-    missing_licenses = third_party_libs - set(self.common_licenses_dict.keys())
-    if missing_licenses:
-      error_msg = 'Missing licenses for following third_party targets: %s' % \
-                  ', '.join(missing_licenses)
-      logging.error(error_msg)
-      raise Exception(error_msg)
+        missing_licenses = third_party_libs - set(
+            self.common_licenses_dict.keys())
+        if missing_licenses:
+            error_msg = 'Missing licenses for following third_party targets: %s' % \
+                        ', '.join(missing_licenses)
+            logging.error(error_msg)
+            raise Exception(error_msg)
 
-    # Put webrtc at the front of the list.
-    license_libs = sorted(third_party_libs)
-    license_libs.insert(0, 'webrtc')
+        # Put webrtc at the front of the list.
+        license_libs = sorted(third_party_libs)
+        license_libs.insert(0, 'webrtc')
 
-    logging.info('List of licenses: %s', ', '.join(license_libs))
+        logging.info('List of licenses: %s', ', '.join(license_libs))
 
-    # Generate markdown.
-    output_license_file = open(os.path.join(output_dir, 'LICENSE.md'), 'w+')
-    for license_lib in license_libs:
-      if len(self.common_licenses_dict[license_lib]) == 0:
-        logging.info('Skipping compile time or internal dependency: %s',
-                     license_lib)
-        continue  # Compile time dependency
+        # Generate markdown.
+        output_license_file = open(os.path.join(output_dir, 'LICENSE.md'),
+                                   'w+')
+        for license_lib in license_libs:
+            if len(self.common_licenses_dict[license_lib]) == 0:
+                logging.info(
+                    'Skipping compile time or internal dependency: %s',
+                    license_lib)
+                continue  # Compile time dependency
 
-      output_license_file.write('# %s\n' % license_lib)
-      output_license_file.write('```\n')
-      for path in self.common_licenses_dict[license_lib]:
-        license_path = os.path.join(WEBRTC_ROOT, path)
-        with open(license_path, 'r') as license_file:
-          license_text = cgi.escape(license_file.read(), quote=True)
-          output_license_file.write(license_text)
-          output_license_file.write('\n')
-      output_license_file.write('```\n\n')
+            output_license_file.write('# %s\n' % license_lib)
+            output_license_file.write('```\n')
+            for path in self.common_licenses_dict[license_lib]:
+                license_path = os.path.join(WEBRTC_ROOT, path)
+                with open(license_path, 'r') as license_file:
+                    license_text = cgi.escape(license_file.read(), quote=True)
+                    output_license_file.write(license_text)
+                    output_license_file.write('\n')
+            output_license_file.write('```\n\n')
 
-    output_license_file.close()
+        output_license_file.close()
 
 
 def main():
-  parser = argparse.ArgumentParser(description='Generate WebRTC LICENSE.md')
-  parser.add_argument(
-      '--verbose', action='store_true', default=False, help='Debug logging.')
-  parser.add_argument(
-      '--target',
-      required=True,
-      action='append',
-      default=[],
-      help='Name of the GN target to generate a license for')
-  parser.add_argument('output_dir', help='Directory to output LICENSE.md to.')
-  parser.add_argument(
-      'buildfile_dirs',
-      nargs='+',
-      help='Directories containing gn generated ninja files')
-  args = parser.parse_args()
+    parser = argparse.ArgumentParser(description='Generate WebRTC LICENSE.md')
+    parser.add_argument('--verbose',
+                        action='store_true',
+                        default=False,
+                        help='Debug logging.')
+    parser.add_argument('--target',
+                        required=True,
+                        action='append',
+                        default=[],
+                        help='Name of the GN target to generate a license for')
+    parser.add_argument('output_dir',
+                        help='Directory to output LICENSE.md to.')
+    parser.add_argument('buildfile_dirs',
+                        nargs='+',
+                        help='Directories containing gn generated ninja files')
+    args = parser.parse_args()
 
-  logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
+    logging.basicConfig(level=logging.DEBUG if args.verbose else logging.INFO)
 
-  builder = LicenseBuilder(args.buildfile_dirs, args.target)
-  builder.GenerateLicenseText(args.output_dir)
+    builder = LicenseBuilder(args.buildfile_dirs, args.target)
+    builder.GenerateLicenseText(args.output_dir)
 
 
 if __name__ == '__main__':
-  sys.exit(main())
+    sys.exit(main())