diff options
Diffstat (limited to 'subcmds')
| -rw-r--r-- | subcmds/forall.py | 14 | ||||
| -rw-r--r-- | subcmds/list.py | 12 |
2 files changed, 13 insertions, 13 deletions
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 = """ |
| 47 | Executes the same shell command in each project. | 48 | Executes the same shell command in each project. |
| 48 | 49 | ||
| 50 | The -r option allows running the command only on projects matching | ||
| 51 | regex or wildcard expression. | ||
| 52 | |||
| 49 | Output Formatting | 53 | Output 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 | ||
| 16 | from __future__ import print_function | 16 | from __future__ import print_function |
| 17 | import re | ||
| 18 | import sys | 17 | import sys |
| 19 | 18 | ||
| 20 | from command import Command, MirrorSafeCommand | 19 | from 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 | ||
