From 8a68ff96057ec58e524a3e41a2d8dca7b5d016bc Mon Sep 17 00:00:00 2001 From: David Pursehouse Date: Mon, 24 Sep 2012 12:15:13 +0900 Subject: Coding style cleanup Fix the following issues reported by pylint: C0321: More than one statement on a single line W0622: Redefining built-in 'name' W0612: Unused variable 'name' W0613: Unused argument 'name' W0102: Dangerous default value 'value' as argument W0105: String statement has no effect Also fixed a few cases of inconsistent indentation. Change-Id: Ie0db839e7c57d576cff12d8c055fe87030d00744 --- subcmds/branches.py | 8 ++++---- subcmds/forall.py | 7 ++----- subcmds/help.py | 6 +++--- subcmds/init.py | 8 +++----- subcmds/manifest.py | 6 +++--- subcmds/overview.py | 10 +++++----- subcmds/prune.py | 10 +++++----- subcmds/rebase.py | 6 +++--- subcmds/stage.py | 14 +++++++------- subcmds/start.py | 6 +++--- subcmds/status.py | 8 ++++---- subcmds/sync.py | 13 ++++++------- subcmds/upload.py | 20 ++++++++++---------- 13 files changed, 58 insertions(+), 64 deletions(-) (limited to 'subcmds') diff --git a/subcmds/branches.py b/subcmds/branches.py index a4f8d360..81aa5b18 100644 --- a/subcmds/branches.py +++ b/subcmds/branches.py @@ -140,12 +140,12 @@ is shown, then the branch appears in all projects. fmt = out.write paths = [] if in_cnt < project_cnt - in_cnt: - type = 'in' + in_type = 'in' for b in i.projects: paths.append(b.project.relpath) else: fmt = out.notinproject - type = 'not in' + in_type = 'not in' have = set() for b in i.projects: have.add(b.project) @@ -153,11 +153,11 @@ is shown, then the branch appears in all projects. if not p in have: paths.append(p.relpath) - s = ' %s %s' % (type, ', '.join(paths)) + s = ' %s %s' % (in_type, ', '.join(paths)) if width + 7 + len(s) < 80: fmt(s) else: - fmt(' %s:' % type) + fmt(' %s:' % in_type) for p in paths: out.nl() fmt(width*' ' + ' %s' % p) diff --git a/subcmds/forall.py b/subcmds/forall.py index 9436f4e5..76a02688 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py @@ -208,7 +208,6 @@ terminal and are not redirected. return self.fd.fileno() empty = True - didout = False errbuf = '' p.stdin.close() @@ -220,7 +219,7 @@ terminal and are not redirected. fcntl.fcntl(s.fd, fcntl.F_SETFL, flags | os.O_NONBLOCK) while s_in: - in_ready, out_ready, err_ready = select.select(s_in, [], []) + in_ready, _out_ready, _err_ready = select.select(s_in, [], []) for s in in_ready: buf = s.fd.read(4096) if not buf: @@ -229,9 +228,7 @@ terminal and are not redirected. continue if not opt.verbose: - if s.fd == p.stdout: - didout = True - else: + if s.fd != p.stdout: errbuf += buf continue diff --git a/subcmds/help.py b/subcmds/help.py index 0df3c14b..375d04d2 100644 --- a/subcmds/help.py +++ b/subcmds/help.py @@ -120,8 +120,8 @@ See 'repo help --all' for a complete list of recognized commands. m = asciidoc_hdr.match(para) if m: title = m.group(1) - type = m.group(2) - if type[0] in ('=', '-'): + section_type = m.group(2) + if section_type[0] in ('=', '-'): p = self.heading else: def _p(fmt, *args): @@ -131,7 +131,7 @@ See 'repo help --all' for a complete list of recognized commands. p('%s', title) self.nl() - p('%s', ''.ljust(len(title),type[0])) + p('%s', ''.ljust(len(title),section_type[0])) self.nl() continue diff --git a/subcmds/init.py b/subcmds/init.py index 9a4f7118..697d6bec 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -213,8 +213,6 @@ to update the working directory files. sys.exit(1) def _Prompt(self, prompt, value): - mp = self.manifest.manifestProject - sys.stdout.write('%-10s [%s]: ' % (prompt, value)) a = sys.stdin.readline().strip() if a == '': @@ -328,9 +326,9 @@ to update the working directory files. self._ConfigureDepth(opt) if self.manifest.IsMirror: - type = 'mirror ' + init_type = 'mirror ' else: - type = '' + init_type = '' print '' - print 'repo %sinitialized in %s' % (type, self.manifest.topdir) + print 'repo %sinitialized in %s' % (init_type, self.manifest.topdir) diff --git a/subcmds/manifest.py b/subcmds/manifest.py index 43887654..5592a37d 100644 --- a/subcmds/manifest.py +++ b/subcmds/manifest.py @@ -35,14 +35,14 @@ in a Git repository for use during future 'repo init' invocations. @property def helpDescription(self): - help = self._helpDescription + '\n' + helptext = self._helpDescription + '\n' r = os.path.dirname(__file__) r = os.path.dirname(r) fd = open(os.path.join(r, 'docs', 'manifest-format.txt')) for line in fd: - help += line + helptext += line fd.close() - return help + return helptext def _Options(self, p): p.add_option('-r', '--revision-as-HEAD', diff --git a/subcmds/overview.py b/subcmds/overview.py index 96fa93d8..a509bd9a 100644 --- a/subcmds/overview.py +++ b/subcmds/overview.py @@ -38,16 +38,16 @@ are displayed. help="Consider only checked out branches") def Execute(self, opt, args): - all = [] + all_branches = [] for project in self.GetProjects(args): br = [project.GetUploadableBranch(x) for x in project.GetBranches().keys()] br = [x for x in br if x] if opt.current_branch: br = [x for x in br if x.name == project.CurrentBranch] - all.extend(br) + all_branches.extend(br) - if not all: + if not all_branches: return class Report(Coloring): @@ -55,13 +55,13 @@ are displayed. Coloring.__init__(self, config, 'status') self.project = self.printer('header', attr='bold') - out = Report(all[0].project.config) + out = Report(all_branches[0].project.config) out.project('Projects Overview') out.nl() project = None - for branch in all: + for branch in all_branches: if project != branch.project: project = branch.project out.nl() diff --git a/subcmds/prune.py b/subcmds/prune.py index f412bd48..c50a5507 100644 --- a/subcmds/prune.py +++ b/subcmds/prune.py @@ -24,11 +24,11 @@ class Prune(PagedCommand): """ def Execute(self, opt, args): - all = [] + all_branches = [] for project in self.GetProjects(args): - all.extend(project.PruneHeads()) + all_branches.extend(project.PruneHeads()) - if not all: + if not all_branches: return class Report(Coloring): @@ -36,13 +36,13 @@ class Prune(PagedCommand): Coloring.__init__(self, config, 'status') self.project = self.printer('header', attr='bold') - out = Report(all[0].project.config) + out = Report(all_branches[0].project.config) out.project('Pending Branches') out.nl() project = None - for branch in all: + for branch in all_branches: if project != branch.project: project = branch.project out.nl() diff --git a/subcmds/rebase.py b/subcmds/rebase.py index 2c1752d7..a8d58cdb 100644 --- a/subcmds/rebase.py +++ b/subcmds/rebase.py @@ -55,14 +55,14 @@ branch but need to incorporate new upstream changes "underneath" them. help='Stash local modifications before starting') def Execute(self, opt, args): - all = self.GetProjects(args) - one_project = len(all) == 1 + all_projects = self.GetProjects(args) + one_project = len(all_projects) == 1 if opt.interactive and not one_project: print >>sys.stderr, 'error: interactive rebase not supported with multiple projects' return -1 - for project in all: + for project in all_projects: cb = project.CurrentBranch if not cb: if one_project: diff --git a/subcmds/stage.py b/subcmds/stage.py index 4c221dba..2ec48069 100644 --- a/subcmds/stage.py +++ b/subcmds/stage.py @@ -48,8 +48,8 @@ The '%prog' command stages files to prepare the next commit. self.Usage() def _Interactive(self, opt, args): - all = filter(lambda x: x.IsDirty(), self.GetProjects(args)) - if not all: + all_projects = filter(lambda x: x.IsDirty(), self.GetProjects(args)) + if not all_projects: print >>sys.stderr,'no projects have uncommitted modifications' return @@ -58,8 +58,8 @@ The '%prog' command stages files to prepare the next commit. out.header(' %s', 'project') out.nl() - for i in xrange(0, len(all)): - p = all[i] + for i in xrange(0, len(all_projects)): + p = all_projects[i] out.write('%3d: %s', i + 1, p.relpath + '/') out.nl() out.nl() @@ -93,11 +93,11 @@ The '%prog' command stages files to prepare the next commit. if a_index is not None: if a_index == 0: break - if 0 < a_index and a_index <= len(all): - _AddI(all[a_index - 1]) + if 0 < a_index and a_index <= len(all_projects): + _AddI(all_projects[a_index - 1]) continue - p = filter(lambda x: x.name == a or x.relpath == a, all) + p = filter(lambda x: x.name == a or x.relpath == a, all_projects) if len(p) == 1: _AddI(p[0]) continue diff --git a/subcmds/start.py b/subcmds/start.py index 00885076..be645314 100644 --- a/subcmds/start.py +++ b/subcmds/start.py @@ -52,10 +52,10 @@ revision specified in the manifest. print >>sys.stderr, "error: at least one project must be specified" sys.exit(1) - all = self.GetProjects(projects) + all_projects = self.GetProjects(projects) - pm = Progress('Starting %s' % nb, len(all)) - for project in all: + pm = Progress('Starting %s' % nb, len(all_projects)) + for project in all_projects: pm.update() # If the current revision is a specific SHA1 then we can't push back # to it so substitute the manifest default revision instead. diff --git a/subcmds/status.py b/subcmds/status.py index 75d68ebc..7611621e 100644 --- a/subcmds/status.py +++ b/subcmds/status.py @@ -98,18 +98,18 @@ the following meanings: sem.release() def Execute(self, opt, args): - all = self.GetProjects(args) + all_projects = self.GetProjects(args) counter = itertools.count() if opt.jobs == 1: - for project in all: + for project in all_projects: state = project.PrintWorkTreeStatus() if state == 'CLEAN': counter.next() else: sem = _threading.Semaphore(opt.jobs) threads_and_output = [] - for project in all: + for project in all_projects: sem.acquire() class BufList(StringIO.StringIO): @@ -128,5 +128,5 @@ the following meanings: t.join() output.dump(sys.stdout) output.close() - if len(all) == counter.next(): + if len(all_projects) == counter.next(): print 'nothing to commit (working directory clean)' diff --git a/subcmds/sync.py b/subcmds/sync.py index b84d169f..1b716351 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -316,8 +316,7 @@ later is required to fix a server side protocol bug. if not path: continue 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): project = Project( manifest = self.manifest, @@ -495,16 +494,16 @@ uncommitted changes are present' % project.relpath self.manifest._Unload() if opt.jobs is None: self.jobs = self.manifest.default.sync_j - all = self.GetProjects(args, missing_ok=True) + all_projects = self.GetProjects(args, missing_ok=True) if not opt.local_only: to_fetch = [] now = time.time() if (24 * 60 * 60) <= (now - rp.LastFetch): to_fetch.append(rp) - to_fetch.extend(all) + to_fetch.extend(all_projects) - fetched = self._Fetch(to_fetch, opt) + self._Fetch(to_fetch, opt) _PostRepoFetch(rp, opt.no_repo_verify) if opt.network_only: # bail out now; the rest touches the working tree @@ -519,8 +518,8 @@ uncommitted changes are present' % project.relpath syncbuf = SyncBuffer(mp.config, detach_head = opt.detach_head) - pm = Progress('Syncing work tree', len(all)) - for project in all: + pm = Progress('Syncing work tree', len(all_projects)) + for project in all_projects: pm.update() if project.worktree: project.Sync_LocalHalf(syncbuf) diff --git a/subcmds/upload.py b/subcmds/upload.py index c9312973..685e3420 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py @@ -40,8 +40,8 @@ def _die(fmt, *args): def _SplitEmails(values): result = [] - for str in values: - result.extend([s.strip() for s in str.split(',')]) + for value in values: + result.extend([s.strip() for s in value.split(',')]) return result class Upload(InteractiveCommand): @@ -174,15 +174,15 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ if answer is None: date = branch.date - list = branch.commits + commit_list = branch.commits print 'Upload project %s/ to remote branch %s:' % (project.relpath, project.revisionExpr) print ' branch %s (%2d commit%s, %s):' % ( name, - len(list), - len(list) != 1 and 's' or '', + len(commit_list), + len(commit_list) != 1 and 's' or '', date) - for commit in list: + for commit in commit_list: print ' %s' % commit sys.stdout.write('to %s (y/N)? ' % remote.review) @@ -212,17 +212,17 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ for branch in avail: name = branch.name date = branch.date - list = branch.commits + commit_list = branch.commits if b: script.append('#') script.append('# branch %s (%2d commit%s, %s) to remote branch %s:' % ( name, - len(list), - len(list) != 1 and 's' or '', + len(commit_list), + len(commit_list) != 1 and 's' or '', date, project.revisionExpr)) - for commit in list: + for commit in commit_list: script.append('# %s' % commit) b[name] = branch -- cgit v1.2.3-54-g00ecf