diff --git a/command.py b/command.py index 39dcf6c2..bc2f9501 100644 --- a/command.py +++ b/command.py @@ -193,14 +193,20 @@ class Command(object): result.sort(key=_getpath) return result - def FindProjects(self, args): + def FindProjects(self, args, inverse=False): result = [] patterns = [re.compile(r'%s' % a, re.IGNORECASE) for a in args] for project in self.GetProjects(''): for pattern in patterns: - if pattern.search(project.name) or pattern.search(project.relpath): + match = pattern.search(project.name) or pattern.search(project.relpath) + if not inverse and match: result.append(project) break + if inverse and match: + break + else: + if inverse: + result.append(project) result.sort(key=lambda project: project.relpath) return result diff --git a/subcmds/forall.py b/subcmds/forall.py index b10f34b3..07ee8d58 100644 --- a/subcmds/forall.py +++ b/subcmds/forall.py @@ -120,6 +120,9 @@ without iterating through the remaining projects. p.add_option('-r', '--regex', dest='regex', action='store_true', help="Execute the command only on projects matching regex or wildcard expression") + p.add_option('-i', '--inverse-regex', + dest='inverse_regex', action='store_true', + help="Execute the command only on projects not matching regex or wildcard expression") p.add_option('-g', '--groups', dest='groups', help="Execute the command only on projects matching the specified groups") @@ -215,10 +218,12 @@ without iterating through the remaining projects. if os.path.isfile(smart_sync_manifest_path): self.manifest.Override(smart_sync_manifest_path) - if not opt.regex: - projects = self.GetProjects(args, groups=opt.groups) - else: + if opt.regex: projects = self.FindProjects(args) + elif opt.inverse_regex: + projects = self.FindProjects(args, inverse=True) + else: + projects = self.GetProjects(args, groups=opt.groups) os.environ['REPO_COUNT'] = str(len(projects))