summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--command.py11
-rw-r--r--subcmds/forall.py14
-rw-r--r--subcmds/list.py12
3 files changed, 24 insertions, 13 deletions
diff --git a/command.py b/command.py
index 959805a2..66a9e74d 100644
--- a/command.py
+++ b/command.py
@@ -186,6 +186,17 @@ class Command(object):
186 result.sort(key=_getpath) 186 result.sort(key=_getpath)
187 return result 187 return result
188 188
189 def FindProjects(self, args):
190 result = []
191 for project in self.GetProjects(''):
192 for arg in args:
193 pattern = re.compile(r'%s' % arg, re.IGNORECASE)
194 if pattern.search(project.name) or pattern.search(project.relpath):
195 result.append(project)
196 break
197 result.sort(key=lambda project: project.relpath)
198 return result
199
189# pylint: disable=W0223 200# pylint: disable=W0223
190# Pylint warns that the `InteractiveCommand` and `PagedCommand` classes do not 201# Pylint warns that the `InteractiveCommand` and `PagedCommand` classes do not
191# override method `Execute` which is abstract in `Command`. Since that method 202# override method `Execute` which is abstract in `Command`. Since that method
diff --git a/subcmds/forall.py b/subcmds/forall.py
index 4c1c9ff8..7d5f7794 100644
--- a/subcmds/forall.py
+++ b/subcmds/forall.py
@@ -42,10 +42,14 @@ class Forall(Command, MirrorSafeCommand):
42 helpSummary = "Run a shell command in each project" 42 helpSummary = "Run a shell command in each project"
43 helpUsage = """ 43 helpUsage = """
44%prog [<project>...] -c <command> [<arg>...] 44%prog [<project>...] -c <command> [<arg>...]
45%prog -r str1 [str2] ... -c <command> [<arg>...]"
45""" 46"""
46 helpDescription = """ 47 helpDescription = """
47Executes the same shell command in each project. 48Executes the same shell command in each project.
48 49
50The -r option allows running the command only on projects matching
51regex or wildcard expression.
52
49Output Formatting 53Output Formatting
50----------------- 54-----------------
51 55
@@ -103,6 +107,9 @@ without iterating through the remaining projects.
103 setattr(parser.values, option.dest, list(parser.rargs)) 107 setattr(parser.values, option.dest, list(parser.rargs))
104 while parser.rargs: 108 while parser.rargs:
105 del parser.rargs[0] 109 del parser.rargs[0]
110 p.add_option('-r', '--regex',
111 dest='regex', action='store_true',
112 help="Execute the command only on projects matching regex or wildcard expression")
106 p.add_option('-c', '--command', 113 p.add_option('-c', '--command',
107 help='Command (and arguments) to execute', 114 help='Command (and arguments) to execute',
108 dest='command', 115 dest='command',
@@ -166,7 +173,12 @@ without iterating through the remaining projects.
166 rc = 0 173 rc = 0
167 first = True 174 first = True
168 175
169 for project in self.GetProjects(args): 176 if not opt.regex:
177 projects = self.GetProjects(args)
178 else:
179 projects = self.FindProjects(args)
180
181 for project in projects:
170 env = os.environ.copy() 182 env = os.environ.copy()
171 def setenv(name, val): 183 def setenv(name, val):
172 if val is None: 184 if val is None:
diff --git a/subcmds/list.py b/subcmds/list.py
index 8eb06cdd..a3358245 100644
--- a/subcmds/list.py
+++ b/subcmds/list.py
@@ -14,7 +14,6 @@
14# limitations under the License. 14# limitations under the License.
15 15
16from __future__ import print_function 16from __future__ import print_function
17import re
18import sys 17import sys
19 18
20from command import Command, MirrorSafeCommand 19from command import Command, MirrorSafeCommand
@@ -83,14 +82,3 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'.
83 82
84 lines.sort() 83 lines.sort()
85 print('\n'.join(lines)) 84 print('\n'.join(lines))
86
87 def FindProjects(self, args):
88 result = []
89 for project in self.GetProjects(''):
90 for arg in args:
91 pattern = re.compile(r'%s' % arg, re.IGNORECASE)
92 if pattern.search(project.name) or pattern.search(project.relpath):
93 result.append(project)
94 break
95 result.sort(key=lambda project: project.relpath)
96 return result