diff options
| author | David Pursehouse <david.pursehouse@sonymobile.com> | 2012-10-11 16:44:48 +0900 |
|---|---|---|
| committer | David Pursehouse <david.pursehouse@sonymobile.com> | 2012-10-22 12:30:14 +0900 |
| commit | 5c6eeac8f0350fd6b14cf226ffcff655f1dd9582 (patch) | |
| tree | 3225695b9d2a97342a49127717ea5e2bc5935a63 | |
| parent | e98607248eec2b149d84efe944c12cbef419b82e (diff) | |
| download | git-repo-5c6eeac8f0350fd6b14cf226ffcff655f1dd9582.tar.gz | |
More coding style cleanup
Fixing more issues found with pylint. Some that were supposed to
have been fixed in the previous sweep (Ie0db839e) but were missed:
C0321: More than one statement on a single line
W0622: Redefining built-in 'name'
And some more:
W0631: Using possibly undefined loop variable 'name'
W0223: Method 'name' is abstract in class 'name' but is not overridden
W0231: __init__ method from base class 'name' is not called
Change-Id: Ie119183708609d6279e973057a385fde864230c3
| -rw-r--r-- | command.py | 7 | ||||
| -rw-r--r-- | error.py | 8 | ||||
| -rwxr-xr-x | main.py | 2 | ||||
| -rw-r--r-- | manifest_xml.py | 3 | ||||
| -rw-r--r-- | project.py | 24 | ||||
| -rw-r--r-- | subcmds/__init__.py | 8 | ||||
| -rw-r--r-- | subcmds/abandon.py | 6 | ||||
| -rw-r--r-- | subcmds/branches.py | 12 | ||||
| -rw-r--r-- | subcmds/checkout.py | 6 | ||||
| -rw-r--r-- | subcmds/forall.py | 6 |
10 files changed, 54 insertions, 28 deletions
| @@ -123,6 +123,11 @@ class Command(object): | |||
| 123 | result.sort(key=_getpath) | 123 | result.sort(key=_getpath) |
| 124 | return result | 124 | return result |
| 125 | 125 | ||
| 126 | # pylint: disable-msg=W0223 | ||
| 127 | # Pylint warns that the `InteractiveCommand` and `PagedCommand` classes do not | ||
| 128 | # override method `Execute` which is abstract in `Command`. Since that method | ||
| 129 | # is always implemented in classes derived from `InteractiveCommand` and | ||
| 130 | # `PagedCommand`, this warning can be suppressed. | ||
| 126 | class InteractiveCommand(Command): | 131 | class InteractiveCommand(Command): |
| 127 | """Command which requires user interaction on the tty and | 132 | """Command which requires user interaction on the tty and |
| 128 | must not run within a pager, even if the user asks to. | 133 | must not run within a pager, even if the user asks to. |
| @@ -137,6 +142,8 @@ class PagedCommand(Command): | |||
| 137 | def WantPager(self, opt): | 142 | def WantPager(self, opt): |
| 138 | return True | 143 | return True |
| 139 | 144 | ||
| 145 | # pylint: enable-msg=W0223 | ||
| 146 | |||
| 140 | class MirrorSafeCommand(object): | 147 | class MirrorSafeCommand(object): |
| 141 | """Command permits itself to run within a mirror, | 148 | """Command permits itself to run within a mirror, |
| 142 | and does not require a working directory. | 149 | and does not require a working directory. |
| @@ -25,6 +25,7 @@ class EditorError(Exception): | |||
| 25 | """Unspecified error from the user's text editor. | 25 | """Unspecified error from the user's text editor. |
| 26 | """ | 26 | """ |
| 27 | def __init__(self, reason): | 27 | def __init__(self, reason): |
| 28 | super(EditorError, self).__init__() | ||
| 28 | self.reason = reason | 29 | self.reason = reason |
| 29 | 30 | ||
| 30 | def __str__(self): | 31 | def __str__(self): |
| @@ -34,6 +35,7 @@ class GitError(Exception): | |||
| 34 | """Unspecified internal error from git. | 35 | """Unspecified internal error from git. |
| 35 | """ | 36 | """ |
| 36 | def __init__(self, command): | 37 | def __init__(self, command): |
| 38 | super(GitError, self).__init__() | ||
| 37 | self.command = command | 39 | self.command = command |
| 38 | 40 | ||
| 39 | def __str__(self): | 41 | def __str__(self): |
| @@ -43,6 +45,7 @@ class UploadError(Exception): | |||
| 43 | """A bundle upload to Gerrit did not succeed. | 45 | """A bundle upload to Gerrit did not succeed. |
| 44 | """ | 46 | """ |
| 45 | def __init__(self, reason): | 47 | def __init__(self, reason): |
| 48 | super(UploadError, self).__init__() | ||
| 46 | self.reason = reason | 49 | self.reason = reason |
| 47 | 50 | ||
| 48 | def __str__(self): | 51 | def __str__(self): |
| @@ -52,6 +55,7 @@ class DownloadError(Exception): | |||
| 52 | """Cannot download a repository. | 55 | """Cannot download a repository. |
| 53 | """ | 56 | """ |
| 54 | def __init__(self, reason): | 57 | def __init__(self, reason): |
| 58 | super(DownloadError, self).__init__() | ||
| 55 | self.reason = reason | 59 | self.reason = reason |
| 56 | 60 | ||
| 57 | def __str__(self): | 61 | def __str__(self): |
| @@ -61,6 +65,7 @@ class NoSuchProjectError(Exception): | |||
| 61 | """A specified project does not exist in the work tree. | 65 | """A specified project does not exist in the work tree. |
| 62 | """ | 66 | """ |
| 63 | def __init__(self, name=None): | 67 | def __init__(self, name=None): |
| 68 | super(NoSuchProjectError, self).__init__() | ||
| 64 | self.name = name | 69 | self.name = name |
| 65 | 70 | ||
| 66 | def __str__(self): | 71 | def __str__(self): |
| @@ -73,6 +78,7 @@ class InvalidProjectGroupsError(Exception): | |||
| 73 | """A specified project is not suitable for the specified groups | 78 | """A specified project is not suitable for the specified groups |
| 74 | """ | 79 | """ |
| 75 | def __init__(self, name=None): | 80 | def __init__(self, name=None): |
| 81 | super(InvalidProjectGroupsError, self).__init__() | ||
| 76 | self.name = name | 82 | self.name = name |
| 77 | 83 | ||
| 78 | def __str__(self): | 84 | def __str__(self): |
| @@ -86,6 +92,7 @@ class RepoChangedException(Exception): | |||
| 86 | use exec to re-execute repo with the new code and manifest. | 92 | use exec to re-execute repo with the new code and manifest. |
| 87 | """ | 93 | """ |
| 88 | def __init__(self, extra_args=None): | 94 | def __init__(self, extra_args=None): |
| 95 | super(RepoChangedException, self).__init__() | ||
| 89 | self.extra_args = extra_args or [] | 96 | self.extra_args = extra_args or [] |
| 90 | 97 | ||
| 91 | class HookError(Exception): | 98 | class HookError(Exception): |
| @@ -93,4 +100,3 @@ class HookError(Exception): | |||
| 93 | 100 | ||
| 94 | The common case is that the file wasn't present when we tried to run it. | 101 | The common case is that the file wasn't present when we tried to run it. |
| 95 | """ | 102 | """ |
| 96 | pass | ||
| @@ -45,7 +45,7 @@ from error import RepoChangedException | |||
| 45 | from manifest_xml import XmlManifest | 45 | from manifest_xml import XmlManifest |
| 46 | from pager import RunPager | 46 | from pager import RunPager |
| 47 | 47 | ||
| 48 | from subcmds import all as all_commands | 48 | from subcmds import all_commands |
| 49 | 49 | ||
| 50 | global_options = optparse.OptionParser( | 50 | global_options = optparse.OptionParser( |
| 51 | usage="repo [-p|--paginate|--no-pager] COMMAND [ARGS]" | 51 | usage="repo [-p|--paginate|--no-pager] COMMAND [ARGS]" |
diff --git a/manifest_xml.py b/manifest_xml.py index 12072441..04cabaad 100644 --- a/manifest_xml.py +++ b/manifest_xml.py | |||
| @@ -321,7 +321,8 @@ class XmlManifest(object): | |||
| 321 | raise ManifestParseError("no <manifest> in %s" % (path,)) | 321 | raise ManifestParseError("no <manifest> in %s" % (path,)) |
| 322 | 322 | ||
| 323 | nodes = [] | 323 | nodes = [] |
| 324 | for node in manifest.childNodes: | 324 | for node in manifest.childNodes: # pylint:disable-msg=W0631 |
| 325 | # We only get here if manifest is initialised | ||
| 325 | if node.nodeName == 'include': | 326 | if node.nodeName == 'include': |
| 326 | name = self._reqatt(node, 'name') | 327 | name = self._reqatt(node, 'name') |
| 327 | fp = os.path.join(include_root, name) | 328 | fp = os.path.join(include_root, name) |
| @@ -724,17 +724,25 @@ class Project(object): | |||
| 724 | paths.sort() | 724 | paths.sort() |
| 725 | 725 | ||
| 726 | for p in paths: | 726 | for p in paths: |
| 727 | try: i = di[p] | 727 | try: |
| 728 | except KeyError: i = None | 728 | i = di[p] |
| 729 | except KeyError: | ||
| 730 | i = None | ||
| 729 | 731 | ||
| 730 | try: f = df[p] | 732 | try: |
| 731 | except KeyError: f = None | 733 | f = df[p] |
| 734 | except KeyError: | ||
| 735 | f = None | ||
| 732 | 736 | ||
| 733 | if i: i_status = i.status.upper() | 737 | if i: |
| 734 | else: i_status = '-' | 738 | i_status = i.status.upper() |
| 739 | else: | ||
| 740 | i_status = '-' | ||
| 735 | 741 | ||
| 736 | if f: f_status = f.status.lower() | 742 | if f: |
| 737 | else: f_status = '-' | 743 | f_status = f.status.lower() |
| 744 | else: | ||
| 745 | f_status = '-' | ||
| 738 | 746 | ||
| 739 | if i and i.src_path: | 747 | if i and i.src_path: |
| 740 | line = ' %s%s\t%s => %s (%s%%)' % (i_status, f_status, | 748 | line = ' %s%s\t%s => %s (%s%%)' % (i_status, f_status, |
diff --git a/subcmds/__init__.py b/subcmds/__init__.py index a2286e78..1fac802e 100644 --- a/subcmds/__init__.py +++ b/subcmds/__init__.py | |||
| @@ -15,7 +15,7 @@ | |||
| 15 | 15 | ||
| 16 | import os | 16 | import os |
| 17 | 17 | ||
| 18 | all = {} | 18 | all_commands = {} |
| 19 | 19 | ||
| 20 | my_dir = os.path.dirname(__file__) | 20 | my_dir = os.path.dirname(__file__) |
| 21 | for py in os.listdir(my_dir): | 21 | for py in os.listdir(my_dir): |
| @@ -43,7 +43,7 @@ for py in os.listdir(my_dir): | |||
| 43 | 43 | ||
| 44 | name = name.replace('_', '-') | 44 | name = name.replace('_', '-') |
| 45 | cmd.NAME = name | 45 | cmd.NAME = name |
| 46 | all[name] = cmd | 46 | all_commands[name] = cmd |
| 47 | 47 | ||
| 48 | if 'help' in all: | 48 | if 'help' in all_commands: |
| 49 | all['help'].commands = all | 49 | all_commands['help'].commands = all_commands |
diff --git a/subcmds/abandon.py b/subcmds/abandon.py index 42abb2ff..e17ab2b6 100644 --- a/subcmds/abandon.py +++ b/subcmds/abandon.py | |||
| @@ -42,10 +42,10 @@ It is equivalent to "git branch -D <branchname>". | |||
| 42 | nb = args[0] | 42 | nb = args[0] |
| 43 | err = [] | 43 | err = [] |
| 44 | success = [] | 44 | success = [] |
| 45 | all = self.GetProjects(args[1:]) | 45 | all_projects = self.GetProjects(args[1:]) |
| 46 | 46 | ||
| 47 | pm = Progress('Abandon %s' % nb, len(all)) | 47 | pm = Progress('Abandon %s' % nb, len(all_projects)) |
| 48 | for project in all: | 48 | for project in all_projects: |
| 49 | pm.update() | 49 | pm.update() |
| 50 | 50 | ||
| 51 | status = project.AbandonBranch(nb) | 51 | status = project.AbandonBranch(nb) |
diff --git a/subcmds/branches.py b/subcmds/branches.py index 81aa5b18..a7ba3d6d 100644 --- a/subcmds/branches.py +++ b/subcmds/branches.py | |||
| @@ -93,17 +93,17 @@ is shown, then the branch appears in all projects. | |||
| 93 | def Execute(self, opt, args): | 93 | def Execute(self, opt, args): |
| 94 | projects = self.GetProjects(args) | 94 | projects = self.GetProjects(args) |
| 95 | out = BranchColoring(self.manifest.manifestProject.config) | 95 | out = BranchColoring(self.manifest.manifestProject.config) |
| 96 | all = {} | 96 | all_branches = {} |
| 97 | project_cnt = len(projects) | 97 | project_cnt = len(projects) |
| 98 | 98 | ||
| 99 | for project in projects: | 99 | for project in projects: |
| 100 | for name, b in project.GetBranches().iteritems(): | 100 | for name, b in project.GetBranches().iteritems(): |
| 101 | b.project = project | 101 | b.project = project |
| 102 | if name not in all: | 102 | if name not in all_branches: |
| 103 | all[name] = BranchInfo(name) | 103 | all_branches[name] = BranchInfo(name) |
| 104 | all[name].add(b) | 104 | all_branches[name].add(b) |
| 105 | 105 | ||
| 106 | names = all.keys() | 106 | names = all_branches.keys() |
| 107 | names.sort() | 107 | names.sort() |
| 108 | 108 | ||
| 109 | if not names: | 109 | if not names: |
| @@ -116,7 +116,7 @@ is shown, then the branch appears in all projects. | |||
| 116 | width = len(name) | 116 | width = len(name) |
| 117 | 117 | ||
| 118 | for name in names: | 118 | for name in names: |
| 119 | i = all[name] | 119 | i = all_branches[name] |
| 120 | in_cnt = len(i.projects) | 120 | in_cnt = len(i.projects) |
| 121 | 121 | ||
| 122 | if i.IsCurrent: | 122 | if i.IsCurrent: |
diff --git a/subcmds/checkout.py b/subcmds/checkout.py index 533d20e1..bfbe9921 100644 --- a/subcmds/checkout.py +++ b/subcmds/checkout.py | |||
| @@ -39,10 +39,10 @@ The command is equivalent to: | |||
| 39 | nb = args[0] | 39 | nb = args[0] |
| 40 | err = [] | 40 | err = [] |
| 41 | success = [] | 41 | success = [] |
| 42 | all = self.GetProjects(args[1:]) | 42 | all_projects = self.GetProjects(args[1:]) |
| 43 | 43 | ||
| 44 | pm = Progress('Checkout %s' % nb, len(all)) | 44 | pm = Progress('Checkout %s' % nb, len(all_projects)) |
| 45 | for project in all: | 45 | for project in all_projects: |
| 46 | pm.update() | 46 | pm.update() |
| 47 | 47 | ||
| 48 | status = project.CheckoutBranch(nb) | 48 | status = project.CheckoutBranch(nb) |
diff --git a/subcmds/forall.py b/subcmds/forall.py index 76a02688..2ece95ed 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py | |||
| @@ -141,12 +141,16 @@ terminal and are not redirected. | |||
| 141 | for cn in cmd[1:]: | 141 | for cn in cmd[1:]: |
| 142 | if not cn.startswith('-'): | 142 | if not cn.startswith('-'): |
| 143 | break | 143 | break |
| 144 | if cn in _CAN_COLOR: | 144 | else: |
| 145 | cn = None | ||
| 146 | # pylint: disable-msg=W0631 | ||
| 147 | if cn and cn in _CAN_COLOR: | ||
| 145 | class ColorCmd(Coloring): | 148 | class ColorCmd(Coloring): |
| 146 | def __init__(self, config, cmd): | 149 | def __init__(self, config, cmd): |
| 147 | Coloring.__init__(self, config, cmd) | 150 | Coloring.__init__(self, config, cmd) |
| 148 | if ColorCmd(self.manifest.manifestProject.config, cn).is_on: | 151 | if ColorCmd(self.manifest.manifestProject.config, cn).is_on: |
| 149 | cmd.insert(cmd.index(cn) + 1, '--color') | 152 | cmd.insert(cmd.index(cn) + 1, '--color') |
| 153 | # pylint: enable-msg=W0631 | ||
| 150 | 154 | ||
| 151 | mirror = self.manifest.IsMirror | 155 | mirror = self.manifest.IsMirror |
| 152 | out = ForallColoring(self.manifest.manifestProject.config) | 156 | out = ForallColoring(self.manifest.manifestProject.config) |
