Add regex support for subcommand forall

Filter the project list based on regex or wildcard matching
of strings, then we can handle subset of all projects.

Change-Id: Ib6c23aec79e7d981f7b6a5eb0ae93c44effec467
Signed-off-by: Zhiguang Li <muzili@gmail.com>
This commit is contained in:
Zhiguang Li
2013-03-15 10:32:10 +08:00
committed by Chirayu Desai
parent 275e4b727a
commit a8864fba9f
3 changed files with 24 additions and 13 deletions

View File

@ -186,6 +186,17 @@ class Command(object):
result.sort(key=_getpath)
return result
def FindProjects(self, args):
result = []
for project in self.GetProjects(''):
for arg in args:
pattern = re.compile(r'%s' % arg, re.IGNORECASE)
if pattern.search(project.name) or pattern.search(project.relpath):
result.append(project)
break
result.sort(key=lambda project: project.relpath)
return result
# pylint: disable=W0223
# Pylint warns that the `InteractiveCommand` and `PagedCommand` classes do not
# override method `Execute` which is abstract in `Command`. Since that method