diff options
Diffstat (limited to 'command.py')
| -rw-r--r-- | command.py | 43 |
1 files changed, 29 insertions, 14 deletions
| @@ -31,7 +31,7 @@ class Command(object): | |||
| 31 | manifest = None | 31 | manifest = None |
| 32 | _optparse = None | 32 | _optparse = None |
| 33 | 33 | ||
| 34 | def WantPager(self, opt): | 34 | def WantPager(self, _opt): |
| 35 | return False | 35 | return False |
| 36 | 36 | ||
| 37 | def ReadEnvironmentOptions(self, opts): | 37 | def ReadEnvironmentOptions(self, opts): |
| @@ -63,7 +63,7 @@ class Command(object): | |||
| 63 | usage = self.helpUsage.strip().replace('%prog', me) | 63 | usage = self.helpUsage.strip().replace('%prog', me) |
| 64 | except AttributeError: | 64 | except AttributeError: |
| 65 | usage = 'repo %s' % self.NAME | 65 | usage = 'repo %s' % self.NAME |
| 66 | self._optparse = optparse.OptionParser(usage = usage) | 66 | self._optparse = optparse.OptionParser(usage=usage) |
| 67 | self._Options(self._optparse) | 67 | self._Options(self._optparse) |
| 68 | return self._optparse | 68 | return self._optparse |
| 69 | 69 | ||
| @@ -110,15 +110,20 @@ class Command(object): | |||
| 110 | project = None | 110 | project = None |
| 111 | if os.path.exists(path): | 111 | if os.path.exists(path): |
| 112 | oldpath = None | 112 | oldpath = None |
| 113 | while path \ | 113 | while path and \ |
| 114 | and path != oldpath \ | 114 | path != oldpath and \ |
| 115 | and path != manifest.topdir: | 115 | path != manifest.topdir: |
| 116 | try: | 116 | try: |
| 117 | project = self._by_path[path] | 117 | project = self._by_path[path] |
| 118 | break | 118 | break |
| 119 | except KeyError: | 119 | except KeyError: |
| 120 | oldpath = path | 120 | oldpath = path |
| 121 | path = os.path.dirname(path) | 121 | path = os.path.dirname(path) |
| 122 | if not project and path == manifest.topdir: | ||
| 123 | try: | ||
| 124 | project = self._by_path[path] | ||
| 125 | except KeyError: | ||
| 126 | pass | ||
| 122 | else: | 127 | else: |
| 123 | try: | 128 | try: |
| 124 | project = self._by_path[path] | 129 | project = self._by_path[path] |
| @@ -138,7 +143,7 @@ class Command(object): | |||
| 138 | mp = manifest.manifestProject | 143 | mp = manifest.manifestProject |
| 139 | 144 | ||
| 140 | if not groups: | 145 | if not groups: |
| 141 | groups = mp.config.GetString('manifest.groups') | 146 | groups = mp.config.GetString('manifest.groups') |
| 142 | if not groups: | 147 | if not groups: |
| 143 | groups = 'default,platform-' + platform.system().lower() | 148 | groups = 'default,platform-' + platform.system().lower() |
| 144 | groups = [x for x in re.split(r'[,\s]+', groups) if x] | 149 | groups = [x for x in re.split(r'[,\s]+', groups) if x] |
| @@ -151,8 +156,7 @@ class Command(object): | |||
| 151 | for p in project.GetDerivedSubprojects()) | 156 | for p in project.GetDerivedSubprojects()) |
| 152 | all_projects_list.extend(derived_projects.values()) | 157 | all_projects_list.extend(derived_projects.values()) |
| 153 | for project in all_projects_list: | 158 | for project in all_projects_list: |
| 154 | if ((missing_ok or project.Exists) and | 159 | if (missing_ok or project.Exists) and project.MatchesGroups(groups): |
| 155 | project.MatchesGroups(groups)): | ||
| 156 | result.append(project) | 160 | result.append(project) |
| 157 | else: | 161 | else: |
| 158 | self._ResetPathToProjectMap(all_projects_list) | 162 | self._ResetPathToProjectMap(all_projects_list) |
| @@ -166,8 +170,8 @@ class Command(object): | |||
| 166 | 170 | ||
| 167 | # If it's not a derived project, update path->project mapping and | 171 | # If it's not a derived project, update path->project mapping and |
| 168 | # search again, as arg might actually point to a derived subproject. | 172 | # search again, as arg might actually point to a derived subproject. |
| 169 | if (project and not project.Derived and | 173 | if (project and not project.Derived and (submodules_ok or |
| 170 | (submodules_ok or project.sync_s)): | 174 | project.sync_s)): |
| 171 | search_again = False | 175 | search_again = False |
| 172 | for subproject in project.GetDerivedSubprojects(): | 176 | for subproject in project.GetDerivedSubprojects(): |
| 173 | self._UpdatePathToProjectMap(subproject) | 177 | self._UpdatePathToProjectMap(subproject) |
| @@ -194,17 +198,24 @@ class Command(object): | |||
| 194 | result.sort(key=_getpath) | 198 | result.sort(key=_getpath) |
| 195 | return result | 199 | return result |
| 196 | 200 | ||
| 197 | def FindProjects(self, args): | 201 | def FindProjects(self, args, inverse=False): |
| 198 | result = [] | 202 | result = [] |
| 199 | patterns = [re.compile(r'%s' % a, re.IGNORECASE) for a in args] | 203 | patterns = [re.compile(r'%s' % a, re.IGNORECASE) for a in args] |
| 200 | for project in self.GetProjects(''): | 204 | for project in self.GetProjects(''): |
| 201 | for pattern in patterns: | 205 | for pattern in patterns: |
| 202 | if pattern.search(project.name) or pattern.search(project.relpath): | 206 | match = pattern.search(project.name) or pattern.search(project.relpath) |
| 207 | if not inverse and match: | ||
| 203 | result.append(project) | 208 | result.append(project) |
| 204 | break | 209 | break |
| 210 | if inverse and match: | ||
| 211 | break | ||
| 212 | else: | ||
| 213 | if inverse: | ||
| 214 | result.append(project) | ||
| 205 | result.sort(key=lambda project: project.relpath) | 215 | result.sort(key=lambda project: project.relpath) |
| 206 | return result | 216 | return result |
| 207 | 217 | ||
| 218 | |||
| 208 | # pylint: disable=W0223 | 219 | # pylint: disable=W0223 |
| 209 | # Pylint warns that the `InteractiveCommand` and `PagedCommand` classes do not | 220 | # Pylint warns that the `InteractiveCommand` and `PagedCommand` classes do not |
| 210 | # override method `Execute` which is abstract in `Command`. Since that method | 221 | # override method `Execute` which is abstract in `Command`. Since that method |
| @@ -214,28 +225,32 @@ class InteractiveCommand(Command): | |||
| 214 | """Command which requires user interaction on the tty and | 225 | """Command which requires user interaction on the tty and |
| 215 | must not run within a pager, even if the user asks to. | 226 | must not run within a pager, even if the user asks to. |
| 216 | """ | 227 | """ |
| 217 | def WantPager(self, opt): | 228 | def WantPager(self, _opt): |
| 218 | return False | 229 | return False |
| 219 | 230 | ||
| 231 | |||
| 220 | class PagedCommand(Command): | 232 | class PagedCommand(Command): |
| 221 | """Command which defaults to output in a pager, as its | 233 | """Command which defaults to output in a pager, as its |
| 222 | display tends to be larger than one screen full. | 234 | display tends to be larger than one screen full. |
| 223 | """ | 235 | """ |
| 224 | def WantPager(self, opt): | 236 | def WantPager(self, _opt): |
| 225 | return True | 237 | return True |
| 226 | 238 | ||
| 227 | # pylint: enable=W0223 | 239 | # pylint: enable=W0223 |
| 228 | 240 | ||
| 241 | |||
| 229 | class MirrorSafeCommand(object): | 242 | class MirrorSafeCommand(object): |
| 230 | """Command permits itself to run within a mirror, | 243 | """Command permits itself to run within a mirror, |
| 231 | and does not require a working directory. | 244 | and does not require a working directory. |
| 232 | """ | 245 | """ |
| 233 | 246 | ||
| 247 | |||
| 234 | class GitcAvailableCommand(object): | 248 | class GitcAvailableCommand(object): |
| 235 | """Command that requires GITC to be available, but does | 249 | """Command that requires GITC to be available, but does |
| 236 | not require the local client to be a GITC client. | 250 | not require the local client to be a GITC client. |
| 237 | """ | 251 | """ |
| 238 | 252 | ||
| 253 | |||
| 239 | class GitcClientCommand(object): | 254 | class GitcClientCommand(object): |
| 240 | """Command that requires the local client to be a GITC | 255 | """Command that requires the local client to be a GITC |
| 241 | client. | 256 | client. |
