diff --git a/color.py b/color.py index 9200a298..33bc8779 100644 --- a/color.py +++ b/color.py @@ -36,7 +36,8 @@ ATTRS = {None :-1, 'blink' : 5, 'reverse': 7} -RESET = "\033[m" +RESET = "\033[m" # pylint: disable=W1401 + # backslash is not anomalous def is_color(s): return s in COLORS @@ -51,7 +52,7 @@ def _Color(fg = None, bg = None, attr = None): if attr >= 0 or fg >= 0 or bg >= 0: need_sep = False - code = "\033[" + code = "\033[" #pylint: disable=W1401 if attr >= 0: code += chr(ord('0') + attr) diff --git a/command.py b/command.py index 0c3b360c..babb8338 100644 --- a/command.py +++ b/command.py @@ -71,7 +71,7 @@ class Command(object): groups = mp.config.GetString('manifest.groups') if not groups: groups = 'all,-notdefault,platform-' + platform.system().lower() - groups = [x for x in re.split('[,\s]+', groups) if x] + groups = [x for x in re.split(r'[,\s]+', groups) if x] if not args: for project in all_projects.values(): diff --git a/git_command.py b/git_command.py index a40e6c05..39f795ff 100644 --- a/git_command.py +++ b/git_command.py @@ -132,15 +132,15 @@ class GitCommand(object): gitdir = None): env = os.environ.copy() - for e in [REPO_TRACE, + for key in [REPO_TRACE, GIT_DIR, 'GIT_ALTERNATE_OBJECT_DIRECTORIES', 'GIT_OBJECT_DIRECTORY', 'GIT_WORK_TREE', 'GIT_GRAFT_FILE', 'GIT_INDEX_FILE']: - if e in env: - del env[e] + if key in env: + del env[key] if disable_editor: _setenv(env, 'GIT_EDITOR', ':') diff --git a/git_config.py b/git_config.py index ae288558..d6510aae 100644 --- a/git_config.py +++ b/git_config.py @@ -35,7 +35,7 @@ from git_command import terminate_ssh_clients R_HEADS = 'refs/heads/' R_TAGS = 'refs/tags/' -ID_RE = re.compile('^[0-9a-f]{40}$') +ID_RE = re.compile(r'^[0-9a-f]{40}$') REVIEW_CACHE = dict() @@ -288,7 +288,8 @@ class GitConfig(object): d = self._do('--null', '--list') if d is None: return c - for line in d.rstrip('\0').split('\0'): + for line in d.rstrip('\0').split('\0'): # pylint: disable=W1401 + # Backslash is not anomalous if '\n' in line: key, val = line.split('\n', 1) else: diff --git a/git_refs.py b/git_refs.py index 18c9230c..cfeffba9 100644 --- a/git_refs.py +++ b/git_refs.py @@ -138,14 +138,14 @@ class GitRefs(object): def _ReadLoose1(self, path, name): try: fd = open(path, 'rb') - except: + except IOError: return try: try: mtime = os.path.getmtime(path) ref_id = fd.readline() - except: + except (IOError, OSError): return finally: fd.close() diff --git a/main.py b/main.py index ba40d56b..7a09c6ba 100755 --- a/main.py +++ b/main.py @@ -27,7 +27,6 @@ import imp import netrc import optparse import os -import re import sys import time import urllib2 diff --git a/manifest_xml.py b/manifest_xml.py index dd163bed..cdee87a6 100644 --- a/manifest_xml.py +++ b/manifest_xml.py @@ -584,7 +584,7 @@ class XmlManifest(object): groups = '' if node.hasAttribute('groups'): groups = node.getAttribute('groups') - groups = [x for x in re.split('[,\s]+', groups) if x] + groups = [x for x in re.split(r'[,\s]+', groups) if x] default_groups = ['all', 'name:%s' % name, 'path:%s' % path] groups.extend(set(default_groups).difference(groups)) diff --git a/project.py b/project.py index 2f471692..6e8bb032 100644 --- a/project.py +++ b/project.py @@ -1012,6 +1012,10 @@ class Project(object): self.CleanPublishedCache(all_refs) revid = self.GetRevisionId(all_refs) + def _doff(): + self._FastForward(revid) + self._CopyFiles() + self._InitWorkTree() head = self.work_git.GetHead() if head.startswith(R_HEADS): @@ -1090,9 +1094,6 @@ class Project(object): # All published commits are merged, and thus we are a # strict subset. We can fast-forward safely. # - def _doff(): - self._FastForward(revid) - self._CopyFiles() syncbuf.later1(self, _doff) return @@ -1155,9 +1156,6 @@ class Project(object): syncbuf.fail(self, e) return else: - def _doff(): - self._FastForward(revid) - self._CopyFiles() syncbuf.later1(self, _doff) def AddCopyFile(self, src, dest, absdest): @@ -1836,7 +1834,8 @@ class Project(object): if p.Wait() == 0: out = p.stdout if out: - return out[:-1].split("\0") + return out[:-1].split('\0') # pylint: disable=W1401 + # Backslash is not anomalous return [] def DiffZ(self, name, *args): @@ -1852,7 +1851,7 @@ class Project(object): out = p.process.stdout.read() r = {} if out: - out = iter(out[:-1].split('\0')) + out = iter(out[:-1].split('\0')) # pylint: disable=W1401 while out: try: info = out.next() diff --git a/subcmds/grep.py b/subcmds/grep.py index 0dc8f9f6..b067629a 100644 --- a/subcmds/grep.py +++ b/subcmds/grep.py @@ -51,7 +51,7 @@ Examples Look for a line that has '#define' and either 'MAX_PATH or 'PATH_MAX': - repo grep -e '#define' --and -\( -e MAX_PATH -e PATH_MAX \) + repo grep -e '#define' --and -\\( -e MAX_PATH -e PATH_MAX \\) Look for a line that has 'NODE' or 'Unexpected' in files that contain a line that matches both expressions: diff --git a/subcmds/init.py b/subcmds/init.py index e56b9223..48df9e89 100644 --- a/subcmds/init.py +++ b/subcmds/init.py @@ -147,7 +147,7 @@ to update the working directory files. r.ResetFetch() r.Save() - groups = re.split('[,\s]+', opt.groups) + groups = re.split(r'[,\s]+', opt.groups) all_platforms = ['linux', 'darwin'] platformize = lambda x: 'platform-' + x if opt.platform == 'auto': diff --git a/subcmds/sync.py b/subcmds/sync.py index d4637d0c..8e9477a3 100644 --- a/subcmds/sync.py +++ b/subcmds/sync.py @@ -696,7 +696,7 @@ class _FetchTimes(object): try: try: self._times = pickle.load(f) - except: + except IOError: try: os.remove(self._path) except OSError: diff --git a/subcmds/upload.py b/subcmds/upload.py index 84a5e440..39721ac2 100644 --- a/subcmds/upload.py +++ b/subcmds/upload.py @@ -297,7 +297,7 @@ Gerrit Code Review: http://code.google.com/p/gerrit/ try: # refs/changes/XYZ/N --> XYZ return refs.get(last_pub).split('/')[-2] - except: + except (AttributeError, IndexError): return "" def _UploadAndReport(self, opt, todo, original_people):