diff options
Diffstat (limited to 'command.py')
-rw-r--r-- | command.py | 38 |
1 files changed, 24 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,9 +110,9 @@ 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 |
@@ -138,7 +138,7 @@ class Command(object): | |||
138 | mp = manifest.manifestProject | 138 | mp = manifest.manifestProject |
139 | 139 | ||
140 | if not groups: | 140 | if not groups: |
141 | groups = mp.config.GetString('manifest.groups') | 141 | groups = mp.config.GetString('manifest.groups') |
142 | if not groups: | 142 | if not groups: |
143 | groups = 'default,platform-' + platform.system().lower() | 143 | groups = 'default,platform-' + platform.system().lower() |
144 | groups = [x for x in re.split(r'[,\s]+', groups) if x] | 144 | groups = [x for x in re.split(r'[,\s]+', groups) if x] |
@@ -151,8 +151,7 @@ class Command(object): | |||
151 | for p in project.GetDerivedSubprojects()) | 151 | for p in project.GetDerivedSubprojects()) |
152 | all_projects_list.extend(derived_projects.values()) | 152 | all_projects_list.extend(derived_projects.values()) |
153 | for project in all_projects_list: | 153 | for project in all_projects_list: |
154 | if ((missing_ok or project.Exists) and | 154 | if (missing_ok or project.Exists) and project.MatchesGroups(groups): |
155 | project.MatchesGroups(groups)): | ||
156 | result.append(project) | 155 | result.append(project) |
157 | else: | 156 | else: |
158 | self._ResetPathToProjectMap(all_projects_list) | 157 | self._ResetPathToProjectMap(all_projects_list) |
@@ -166,8 +165,8 @@ class Command(object): | |||
166 | 165 | ||
167 | # If it's not a derived project, update path->project mapping and | 166 | # If it's not a derived project, update path->project mapping and |
168 | # search again, as arg might actually point to a derived subproject. | 167 | # search again, as arg might actually point to a derived subproject. |
169 | if (project and not project.Derived and | 168 | if (project and not project.Derived and (submodules_ok or |
170 | (submodules_ok or project.sync_s)): | 169 | project.sync_s)): |
171 | search_again = False | 170 | search_again = False |
172 | for subproject in project.GetDerivedSubprojects(): | 171 | for subproject in project.GetDerivedSubprojects(): |
173 | self._UpdatePathToProjectMap(subproject) | 172 | self._UpdatePathToProjectMap(subproject) |
@@ -194,17 +193,24 @@ class Command(object): | |||
194 | result.sort(key=_getpath) | 193 | result.sort(key=_getpath) |
195 | return result | 194 | return result |
196 | 195 | ||
197 | def FindProjects(self, args): | 196 | def FindProjects(self, args, inverse=False): |
198 | result = [] | 197 | result = [] |
199 | patterns = [re.compile(r'%s' % a, re.IGNORECASE) for a in args] | 198 | patterns = [re.compile(r'%s' % a, re.IGNORECASE) for a in args] |
200 | for project in self.GetProjects(''): | 199 | for project in self.GetProjects(''): |
201 | for pattern in patterns: | 200 | for pattern in patterns: |
202 | if pattern.search(project.name) or pattern.search(project.relpath): | 201 | match = pattern.search(project.name) or pattern.search(project.relpath) |
202 | if not inverse and match: | ||
203 | result.append(project) | 203 | result.append(project) |
204 | break | 204 | break |
205 | if inverse and match: | ||
206 | break | ||
207 | else: | ||
208 | if inverse: | ||
209 | result.append(project) | ||
205 | result.sort(key=lambda project: project.relpath) | 210 | result.sort(key=lambda project: project.relpath) |
206 | return result | 211 | return result |
207 | 212 | ||
213 | |||
208 | # pylint: disable=W0223 | 214 | # pylint: disable=W0223 |
209 | # Pylint warns that the `InteractiveCommand` and `PagedCommand` classes do not | 215 | # Pylint warns that the `InteractiveCommand` and `PagedCommand` classes do not |
210 | # override method `Execute` which is abstract in `Command`. Since that method | 216 | # override method `Execute` which is abstract in `Command`. Since that method |
@@ -214,28 +220,32 @@ class InteractiveCommand(Command): | |||
214 | """Command which requires user interaction on the tty and | 220 | """Command which requires user interaction on the tty and |
215 | must not run within a pager, even if the user asks to. | 221 | must not run within a pager, even if the user asks to. |
216 | """ | 222 | """ |
217 | def WantPager(self, opt): | 223 | def WantPager(self, _opt): |
218 | return False | 224 | return False |
219 | 225 | ||
226 | |||
220 | class PagedCommand(Command): | 227 | class PagedCommand(Command): |
221 | """Command which defaults to output in a pager, as its | 228 | """Command which defaults to output in a pager, as its |
222 | display tends to be larger than one screen full. | 229 | display tends to be larger than one screen full. |
223 | """ | 230 | """ |
224 | def WantPager(self, opt): | 231 | def WantPager(self, _opt): |
225 | return True | 232 | return True |
226 | 233 | ||
227 | # pylint: enable=W0223 | 234 | # pylint: enable=W0223 |
228 | 235 | ||
236 | |||
229 | class MirrorSafeCommand(object): | 237 | class MirrorSafeCommand(object): |
230 | """Command permits itself to run within a mirror, | 238 | """Command permits itself to run within a mirror, |
231 | and does not require a working directory. | 239 | and does not require a working directory. |
232 | """ | 240 | """ |
233 | 241 | ||
242 | |||
234 | class GitcAvailableCommand(object): | 243 | class GitcAvailableCommand(object): |
235 | """Command that requires GITC to be available, but does | 244 | """Command that requires GITC to be available, but does |
236 | not require the local client to be a GITC client. | 245 | not require the local client to be a GITC client. |
237 | """ | 246 | """ |
238 | 247 | ||
248 | |||
239 | class GitcClientCommand(object): | 249 | class GitcClientCommand(object): |
240 | """Command that requires the local client to be a GITC | 250 | """Command that requires the local client to be a GITC |
241 | client. | 251 | client. |