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