repo: Cleaned up pylint/pep8 violations

I noticed when running pylint (as the SUBMITTING_PATCHES file directs)
that there were a number of violations reported. This makes it difficult
to see violations I might have introduced. This commit corrects all
pylint violations in the repo script.

First I ran this to clean up the formatting:

 autopep8 --max-line-length=80 --indent-size 2 repo

Following that the following violations remained:

% pylint --rcfile=.pylintrc repo
************* Module repo
W:220,21: Redefining name 'init_optparse' from outer scope (line 156)
(redefined-outer-name)
W:482, 2: No exception type(s) specified (bare-except)
C:704, 0: Old-style class defined. (old-style-class)

For line 220, the parameter to _GitcInitOptions was renamed so as not to
mask the init_optparse global.

For line 482, a pylint directive was added to disable the bare-execpt
violation for just that line.

For line 704, the _Options class was changed to subclass object.

Additionally, the comments at lines 107-113 were spaced out to line up
with the comment at line 112 that autopep8 moved.

This script now has a pylint score of 10.0

Change-Id: I779b66eb6b061a195d3c4372b99dec1b6d2a214f
This commit is contained in:
Mark E. Hamilton 2016-02-10 10:44:30 -07:00
parent 5553628601
commit 4088eb434b

30
repo
View File

@ -1,7 +1,7 @@
#!/usr/bin/env python
## repo default configuration
##
# repo default configuration
#
import os
REPO_URL = os.environ.get('REPO_URL', None)
if not REPO_URL:
@ -216,9 +216,10 @@ group.add_option('--config-name',
dest='config_name', action="store_true", default=False,
help='Always prompt for name/e-mail')
def _GitcInitOptions(init_optparse):
init_optparse.set_usage("repo gitc-init -u url -c client [options]")
g = init_optparse.add_option_group('GITC options')
def _GitcInitOptions(init_optparse_arg):
init_optparse_arg.set_usage("repo gitc-init -u url -c client [options]")
g = init_optparse_arg.add_option_group('GITC options')
g.add_option('-f', '--manifest-file',
dest='manifest_file',
help='Optional manifest file to use for this GITC client.')
@ -227,6 +228,8 @@ def _GitcInitOptions(init_optparse):
help='The name of the gitc_client instance to create or modify.')
_gitc_manifest_dir = None
def get_gitc_manifest_dir():
global _gitc_manifest_dir
if _gitc_manifest_dir is None:
@ -241,6 +244,7 @@ def get_gitc_manifest_dir():
pass
return _gitc_manifest_dir
def gitc_parse_clientdir(gitc_fs_path):
"""Parse a path in the GITC FS and return its client name.
@ -263,7 +267,9 @@ def gitc_parse_clientdir(gitc_fs_path):
return gitc_fs_path.split(manifest_dir)[1].split('/')[0]
return gitc_fs_path.split(GITC_FS_ROOT_DIR)[1].split('/')[0]
class CloneFailure(Exception):
"""Indicate the remote clone of repo itself failed.
"""
@ -473,7 +479,7 @@ def _InitHttp():
p = n.hosts[host]
mgr.add_password(p[1], 'http://%s/' % host, p[0], p[2])
mgr.add_password(p[1], 'https://%s/' % host, p[0], p[2])
except:
except: # pylint: disable=bare-except
pass
handlers.append(urllib.request.HTTPBasicAuthHandler(mgr))
handlers.append(urllib.request.HTTPDigestAuthHandler(mgr))
@ -486,6 +492,7 @@ def _InitHttp():
handlers.append(urllib.request.HTTPSHandler(debuglevel=1))
urllib.request.install_opener(urllib.request.build_opener(*handlers))
def _Fetch(url, local, src, quiet):
if not quiet:
_print('Get %s' % url, file=sys.stderr)
@ -507,6 +514,7 @@ def _Fetch(url, local, src, quiet):
if proc.wait() != 0:
raise CloneFailure()
def _DownloadBundle(url, local, quiet):
if not url.endswith('/'):
url += '/'
@ -557,6 +565,7 @@ def _DownloadBundle(url, local, quiet):
finally:
dest.close()
def _ImportBundle(local):
path = os.path.join(local, '.git', 'clone.bundle')
try:
@ -564,6 +573,7 @@ def _ImportBundle(local):
finally:
os.remove(path)
def _Clone(url, local, quiet):
"""Clones a git repository to a new subdirectory of repodir
"""
@ -591,7 +601,8 @@ def _Clone(url, local, quiet):
_InitHttp()
_SetConfig(local, 'remote.origin.url', url)
_SetConfig(local, 'remote.origin.fetch',
_SetConfig(local,
'remote.origin.fetch',
'+refs/heads/*:refs/remotes/origin/*')
if _DownloadBundle(url, local, quiet):
_ImportBundle(local)
@ -690,7 +701,7 @@ def _FindRepo():
return (repo, os.path.join(curdir, repodir))
class _Options:
class _Options(object):
help = False
@ -814,7 +825,8 @@ def main(orig_args):
if get_gitc_manifest_dir() and cwd.startswith(get_gitc_manifest_dir()):
_print('error: repo cannot be used in the GITC local manifest directory.'
'\nIf you want to work on this GITC client please rerun this '
'command from the corresponding client under /gitc/', file=sys.stderr)
'command from the corresponding client under /gitc/',
file=sys.stderr)
sys.exit(1)
if not repo_main:
if opt.help: