Fix inconsistent indentation

The repo coding style is to indent at 2 characters, but there are
many places where this is not followed.

Enable pylint warning "W0311: Bad indentation" and make sure all
indentation is at multiples of 2 characters.

Change-Id: I68f0f64470789ce2429ab11104d15d380a63e6a8
This commit is contained in:
David Pursehouse 2012-11-14 11:36:51 +09:00
parent 98ffba1401
commit c1b86a2323
9 changed files with 215 additions and 215 deletions

View File

@ -53,7 +53,7 @@ load-plugins=
enable=RP0004 enable=RP0004
# Disable the message(s) with the given id(s). # Disable the message(s) with the given id(s).
disable=R0903,R0912,R0913,R0914,R0915,W0141,C0111,C0103,C0323,C0322,C0324,W0603,W0703,R0911,C0301,C0302,R0902,R0904,W0142,W0212,E1101,E1103,R0201,W0201,W0122,W0232,W0311,RP0001,RP0003,RP0101,RP0002,RP0401,RP0701,RP0801 disable=R0903,R0912,R0913,R0914,R0915,W0141,C0111,C0103,C0323,C0322,C0324,W0603,W0703,R0911,C0301,C0302,R0902,R0904,W0142,W0212,E1101,E1103,R0201,W0201,W0122,W0232,RP0001,RP0003,RP0101,RP0002,RP0401,RP0701,RP0801
[REPORTS] [REPORTS]

View File

@ -40,47 +40,47 @@ RESET = "\033[m" # pylint: disable=W1401
# backslash is not anomalous # backslash is not anomalous
def is_color(s): def is_color(s):
return s in COLORS return s in COLORS
def is_attr(s): def is_attr(s):
return s in ATTRS return s in ATTRS
def _Color(fg = None, bg = None, attr = None): def _Color(fg = None, bg = None, attr = None):
fg = COLORS[fg] fg = COLORS[fg]
bg = COLORS[bg] bg = COLORS[bg]
attr = ATTRS[attr] attr = ATTRS[attr]
if attr >= 0 or fg >= 0 or bg >= 0: if attr >= 0 or fg >= 0 or bg >= 0:
need_sep = False need_sep = False
code = "\033[" #pylint: disable=W1401 code = "\033[" #pylint: disable=W1401
if attr >= 0: if attr >= 0:
code += chr(ord('0') + attr) code += chr(ord('0') + attr)
need_sep = True need_sep = True
if fg >= 0: if fg >= 0:
if need_sep: if need_sep:
code += ';' code += ';'
need_sep = True need_sep = True
if fg < 8: if fg < 8:
code += '3%c' % (ord('0') + fg) code += '3%c' % (ord('0') + fg)
else: else:
code += '38;5;%d' % fg code += '38;5;%d' % fg
if bg >= 0: if bg >= 0:
if need_sep: if need_sep:
code += ';' code += ';'
need_sep = True need_sep = True
if bg < 8: if bg < 8:
code += '4%c' % (ord('0') + bg) code += '4%c' % (ord('0') + bg)
else: else:
code += '48;5;%d' % bg code += '48;5;%d' % bg
code += 'm' code += 'm'
else: else:
code = '' code = ''
return code return code
class Coloring(object): class Coloring(object):

View File

@ -303,10 +303,10 @@ class GitConfig(object):
for line in d.rstrip('\0').split('\0'): # pylint: disable=W1401 for line in d.rstrip('\0').split('\0'): # pylint: disable=W1401
# Backslash is not anomalous # Backslash is not anomalous
if '\n' in line: if '\n' in line:
key, val = line.split('\n', 1) key, val = line.split('\n', 1)
else: else:
key = line key = line
val = None val = None
if key in c: if key in c:
c[key].append(val) c[key].append(val)

22
main.py
View File

@ -275,17 +275,17 @@ class _UserAgentHandler(urllib.request.BaseHandler):
return req return req
def _AddPasswordFromUserInput(handler, msg, req): def _AddPasswordFromUserInput(handler, msg, req):
# If repo could not find auth info from netrc, try to get it from user input # If repo could not find auth info from netrc, try to get it from user input
url = req.get_full_url() url = req.get_full_url()
user, password = handler.passwd.find_user_password(None, url) user, password = handler.passwd.find_user_password(None, url)
if user is None: if user is None:
print(msg) print(msg)
try: try:
user = raw_input('User: ') user = raw_input('User: ')
password = getpass.getpass() password = getpass.getpass()
except KeyboardInterrupt: except KeyboardInterrupt:
return return
handler.passwd.add_password(None, url, user, password) handler.passwd.add_password(None, url, user, password)
class _BasicAuthHandler(urllib.request.HTTPBasicAuthHandler): class _BasicAuthHandler(urllib.request.HTTPBasicAuthHandler):
def http_error_401(self, req, fp, code, msg, headers): def http_error_401(self, req, fp, code, msg, headers):

View File

@ -67,7 +67,7 @@ class _XmlRemote(object):
# urljoin will get confused if there is no scheme in the base url # urljoin will get confused if there is no scheme in the base url
# ie, if manifestUrl is of the form <hostname:port> # ie, if manifestUrl is of the form <hostname:port>
if manifestUrl.find(':') != manifestUrl.find('/') - 1: if manifestUrl.find(':') != manifestUrl.find('/') - 1:
manifestUrl = 'gopher://' + manifestUrl manifestUrl = 'gopher://' + manifestUrl
url = urlparse.urljoin(manifestUrl, url) url = urlparse.urljoin(manifestUrl, url)
return re.sub(r'^gopher://', '', url) return re.sub(r'^gopher://', '', url)
@ -349,24 +349,24 @@ class XmlManifest(object):
nodes = [] nodes = []
for node in manifest.childNodes: # pylint:disable=W0631 for node in manifest.childNodes: # pylint:disable=W0631
# We only get here if manifest is initialised # We only get here if manifest is initialised
if node.nodeName == 'include': if node.nodeName == 'include':
name = self._reqatt(node, 'name') name = self._reqatt(node, 'name')
fp = os.path.join(include_root, name) fp = os.path.join(include_root, name)
if not os.path.isfile(fp): if not os.path.isfile(fp):
raise ManifestParseError, \ raise ManifestParseError, \
"include %s doesn't exist or isn't a file" % \ "include %s doesn't exist or isn't a file" % \
(name,) (name,)
try: try:
nodes.extend(self._ParseManifestXml(fp, include_root)) nodes.extend(self._ParseManifestXml(fp, include_root))
# should isolate this to the exact exception, but that's # should isolate this to the exact exception, but that's
# tricky. actual parsing implementation may vary. # tricky. actual parsing implementation may vary.
except (KeyboardInterrupt, RuntimeError, SystemExit): except (KeyboardInterrupt, RuntimeError, SystemExit):
raise raise
except Exception as e: except Exception as e:
raise ManifestParseError( raise ManifestParseError(
"failed parsing included manifest %s: %s", (name, e)) "failed parsing included manifest %s: %s", (name, e))
else: else:
nodes.append(node) nodes.append(node)
return nodes return nodes
def _ParseManifest(self, node_list): def _ParseManifest(self, node_list):
@ -404,9 +404,9 @@ class XmlManifest(object):
if node.nodeName == 'manifest-server': if node.nodeName == 'manifest-server':
url = self._reqatt(node, 'url') url = self._reqatt(node, 'url')
if self._manifest_server is not None: if self._manifest_server is not None:
raise ManifestParseError( raise ManifestParseError(
'duplicate manifest-server in %s' % 'duplicate manifest-server in %s' %
(self.manifestFile)) (self.manifestFile))
self._manifest_server = url self._manifest_server = url
for node in itertools.chain(*node_list): for node in itertools.chain(*node_list):

View File

@ -585,14 +585,14 @@ class Project(object):
return self._userident_email return self._userident_email
def _LoadUserIdentity(self): def _LoadUserIdentity(self):
u = self.bare_git.var('GIT_COMMITTER_IDENT') u = self.bare_git.var('GIT_COMMITTER_IDENT')
m = re.compile("^(.*) <([^>]*)> ").match(u) m = re.compile("^(.*) <([^>]*)> ").match(u)
if m: if m:
self._userident_name = m.group(1) self._userident_name = m.group(1)
self._userident_email = m.group(2) self._userident_email = m.group(2)
else: else:
self._userident_name = '' self._userident_name = ''
self._userident_email = '' self._userident_email = ''
def GetRemote(self, name): def GetRemote(self, name):
"""Get the configuration for a single remote. """Get the configuration for a single remote.
@ -1381,14 +1381,14 @@ class Project(object):
tag_name = None tag_name = None
def CheckForSha1(): def CheckForSha1():
try: try:
# if revision (sha or tag) is not present then following function # if revision (sha or tag) is not present then following function
# throws an error. # throws an error.
self.bare_git.rev_parse('--verify', '%s^0' % self.revisionExpr) self.bare_git.rev_parse('--verify', '%s^0' % self.revisionExpr)
return True return True
except GitError: except GitError:
# There is no such persistent revision. We have to fetch it. # There is no such persistent revision. We have to fetch it.
return False return False
if current_branch_only: if current_branch_only:
if ID_RE.match(self.revisionExpr) is not None: if ID_RE.match(self.revisionExpr) is not None:

View File

@ -197,62 +197,62 @@ later is required to fix a server side protocol bug.
help=SUPPRESS_HELP) help=SUPPRESS_HELP)
def _FetchHelper(self, opt, project, lock, fetched, pm, sem, err_event): def _FetchHelper(self, opt, project, lock, fetched, pm, sem, err_event):
"""Main function of the fetch threads when jobs are > 1. """Main function of the fetch threads when jobs are > 1.
Args: Args:
opt: Program options returned from optparse. See _Options(). opt: Program options returned from optparse. See _Options().
project: Project object for the project to fetch. project: Project object for the project to fetch.
lock: Lock for accessing objects that are shared amongst multiple lock: Lock for accessing objects that are shared amongst multiple
_FetchHelper() threads. _FetchHelper() threads.
fetched: set object that we will add project.gitdir to when we're done fetched: set object that we will add project.gitdir to when we're done
(with our lock held). (with our lock held).
pm: Instance of a Project object. We will call pm.update() (with our pm: Instance of a Project object. We will call pm.update() (with our
lock held). lock held).
sem: We'll release() this semaphore when we exit so that another thread sem: We'll release() this semaphore when we exit so that another thread
can be started up. can be started up.
err_event: We'll set this event in the case of an error (after printing err_event: We'll set this event in the case of an error (after printing
out info about the error). out info about the error).
""" """
# We'll set to true once we've locked the lock. # We'll set to true once we've locked the lock.
did_lock = False did_lock = False
# Encapsulate everything in a try/except/finally so that: # Encapsulate everything in a try/except/finally so that:
# - We always set err_event in the case of an exception. # - We always set err_event in the case of an exception.
# - We always make sure we call sem.release(). # - We always make sure we call sem.release().
# - We always make sure we unlock the lock if we locked it. # - We always make sure we unlock the lock if we locked it.
try:
try: try:
try: start = time.time()
start = time.time() success = project.Sync_NetworkHalf(
success = project.Sync_NetworkHalf( quiet=opt.quiet,
quiet=opt.quiet, current_branch_only=opt.current_branch_only,
current_branch_only=opt.current_branch_only, clone_bundle=not opt.no_clone_bundle)
clone_bundle=not opt.no_clone_bundle) self._fetch_times.Set(project, time.time() - start)
self._fetch_times.Set(project, time.time() - start)
# Lock around all the rest of the code, since printing, updating a set # Lock around all the rest of the code, since printing, updating a set
# and Progress.update() are not thread safe. # and Progress.update() are not thread safe.
lock.acquire() lock.acquire()
did_lock = True did_lock = True
if not success: if not success:
print('error: Cannot fetch %s' % project.name, file=sys.stderr) print('error: Cannot fetch %s' % project.name, file=sys.stderr)
if opt.force_broken: if opt.force_broken:
print('warn: --force-broken, continuing to sync', print('warn: --force-broken, continuing to sync',
file=sys.stderr) file=sys.stderr)
else: else:
raise _FetchError() raise _FetchError()
fetched.add(project.gitdir) fetched.add(project.gitdir)
pm.update() pm.update()
except _FetchError: except _FetchError:
err_event.set() err_event.set()
except: except:
err_event.set() err_event.set()
raise raise
finally: finally:
if did_lock: if did_lock:
lock.release() lock.release()
sem.release() sem.release()
def _Fetch(self, projects, opt): def _Fetch(self, projects, opt):
fetched = set() fetched = set()
@ -379,36 +379,36 @@ later is required to fix a server side protocol bug.
if path not in new_project_paths: if path not in new_project_paths:
# If the path has already been deleted, we don't need to do it # If the path has already been deleted, we don't need to do it
if os.path.exists(self.manifest.topdir + '/' + path): if os.path.exists(self.manifest.topdir + '/' + path):
project = Project( project = Project(
manifest = self.manifest, manifest = self.manifest,
name = path, name = path,
remote = RemoteSpec('origin'), remote = RemoteSpec('origin'),
gitdir = os.path.join(self.manifest.topdir, gitdir = os.path.join(self.manifest.topdir,
path, '.git'), path, '.git'),
worktree = os.path.join(self.manifest.topdir, path), worktree = os.path.join(self.manifest.topdir, path),
relpath = path, relpath = path,
revisionExpr = 'HEAD', revisionExpr = 'HEAD',
revisionId = None, revisionId = None,
groups = None) groups = None)
if project.IsDirty(): if project.IsDirty():
print('error: Cannot remove project "%s": uncommitted changes' print('error: Cannot remove project "%s": uncommitted changes'
'are present' % project.relpath, file=sys.stderr) 'are present' % project.relpath, file=sys.stderr)
print(' commit changes, then run sync again', print(' commit changes, then run sync again',
file=sys.stderr) file=sys.stderr)
return -1 return -1
else: else:
print('Deleting obsolete path %s' % project.worktree, print('Deleting obsolete path %s' % project.worktree,
file=sys.stderr) file=sys.stderr)
shutil.rmtree(project.worktree) shutil.rmtree(project.worktree)
# Try deleting parent subdirs if they are empty # Try deleting parent subdirs if they are empty
project_dir = os.path.dirname(project.worktree) project_dir = os.path.dirname(project.worktree)
while project_dir != self.manifest.topdir: while project_dir != self.manifest.topdir:
try: try:
os.rmdir(project_dir) os.rmdir(project_dir)
except OSError: except OSError:
break break
project_dir = os.path.dirname(project_dir) project_dir = os.path.dirname(project_dir)
new_project_paths.sort() new_project_paths.sort()
fd = open(file_path, 'w') fd = open(file_path, 'w')

View File

@ -312,23 +312,23 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
# Check if there are local changes that may have been forgotten # Check if there are local changes that may have been forgotten
if branch.project.HasChanges(): if branch.project.HasChanges():
key = 'review.%s.autoupload' % branch.project.remote.review key = 'review.%s.autoupload' % branch.project.remote.review
answer = branch.project.config.GetBoolean(key) answer = branch.project.config.GetBoolean(key)
# if they want to auto upload, let's not ask because it could be automated # if they want to auto upload, let's not ask because it could be automated
if answer is None: if answer is None:
sys.stdout.write('Uncommitted changes in ' + branch.project.name + ' (did you forget to amend?). Continue uploading? (y/N) ') sys.stdout.write('Uncommitted changes in ' + branch.project.name + ' (did you forget to amend?). Continue uploading? (y/N) ')
a = sys.stdin.readline().strip().lower() a = sys.stdin.readline().strip().lower()
if a not in ('y', 'yes', 't', 'true', 'on'): if a not in ('y', 'yes', 't', 'true', 'on'):
print("skipping upload", file=sys.stderr) print("skipping upload", file=sys.stderr)
branch.uploaded = False branch.uploaded = False
branch.error = 'User aborted' branch.error = 'User aborted'
continue continue
# Check if topic branches should be sent to the server during upload # Check if topic branches should be sent to the server during upload
if opt.auto_topic is not True: if opt.auto_topic is not True:
key = 'review.%s.uploadtopic' % branch.project.remote.review key = 'review.%s.uploadtopic' % branch.project.remote.review
opt.auto_topic = branch.project.config.GetBoolean(key) opt.auto_topic = branch.project.config.GetBoolean(key)
branch.UploadForReview(people, auto_topic=opt.auto_topic, draft=opt.draft) branch.UploadForReview(people, auto_topic=opt.auto_topic, draft=opt.draft)
branch.uploaded = True branch.uploaded = True
@ -355,11 +355,11 @@ Gerrit Code Review: http://code.google.com/p/gerrit/
print() print()
for branch in todo: for branch in todo:
if branch.uploaded: if branch.uploaded:
print('[OK ] %-15s %s' % ( print('[OK ] %-15s %s' % (
branch.project.relpath + '/', branch.project.relpath + '/',
branch.name), branch.name),
file=sys.stderr) file=sys.stderr)
if have_errors: if have_errors:
sys.exit(1) sys.exit(1)

View File

@ -4,49 +4,49 @@ import unittest
import git_config import git_config
def fixture(*paths): def fixture(*paths):
"""Return a path relative to test/fixtures. """Return a path relative to test/fixtures.
""" """
return os.path.join(os.path.dirname(__file__), 'fixtures', *paths) return os.path.join(os.path.dirname(__file__), 'fixtures', *paths)
class GitConfigUnitTest(unittest.TestCase): class GitConfigUnitTest(unittest.TestCase):
"""Tests the GitConfig class. """Tests the GitConfig class.
"""
def setUp(self):
"""Create a GitConfig object using the test.gitconfig fixture.
""" """
def setUp(self): config_fixture = fixture('test.gitconfig')
"""Create a GitConfig object using the test.gitconfig fixture. self.config = git_config.GitConfig(config_fixture)
"""
config_fixture = fixture('test.gitconfig')
self.config = git_config.GitConfig(config_fixture)
def test_GetString_with_empty_config_values(self): def test_GetString_with_empty_config_values(self):
""" """
Test config entries with no value. Test config entries with no value.
[section] [section]
empty empty
""" """
val = self.config.GetString('section.empty') val = self.config.GetString('section.empty')
self.assertEqual(val, None) self.assertEqual(val, None)
def test_GetString_with_true_value(self): def test_GetString_with_true_value(self):
""" """
Test config entries with a string value. Test config entries with a string value.
[section] [section]
nonempty = true nonempty = true
""" """
val = self.config.GetString('section.nonempty') val = self.config.GetString('section.nonempty')
self.assertEqual(val, 'true') self.assertEqual(val, 'true')
def test_GetString_from_missing_file(self): def test_GetString_from_missing_file(self):
""" """
Test missing config file Test missing config file
""" """
config_fixture = fixture('not.present.gitconfig') config_fixture = fixture('not.present.gitconfig')
config = git_config.GitConfig(config_fixture) config = git_config.GitConfig(config_fixture)
val = config.GetString('empty') val = config.GetString('empty')
self.assertEqual(val, None) self.assertEqual(val, None)
if __name__ == '__main__': if __name__ == '__main__':
unittest.main() unittest.main()