summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorConley Owens <cco3@android.com>2012-10-25 10:00:41 -0700
committerGerrit Code Review <noreply-gerritcodereview@google.com>2012-10-25 10:00:42 -0700
commit13657c407d0424d0866993bea39ed01094caa1c1 (patch)
tree74f69003f5f71602e7ed0a6d2d5dd92d03f95caa
parente4ed8f65f376009f70fab0e7978fdfc223f23a76 (diff)
parentd75c669fac50f5224b567127291976fd36b31546 (diff)
downloadgit-repo-13657c407d0424d0866993bea39ed01094caa1c1.tar.gz
Merge "Add regex matching to repo list command"
-rw-r--r--subcmds/list.py38
1 files changed, 34 insertions, 4 deletions
diff --git a/subcmds/list.py b/subcmds/list.py
index 2be82570..6058a755 100644
--- a/subcmds/list.py
+++ b/subcmds/list.py
@@ -13,13 +13,16 @@
13# See the License for the specific language governing permissions and 13# See the License for the specific language governing permissions and
14# limitations under the License. 14# limitations under the License.
15 15
16import re
17
16from command import Command, MirrorSafeCommand 18from command import Command, MirrorSafeCommand
17 19
18class List(Command, MirrorSafeCommand): 20class List(Command, MirrorSafeCommand):
19 common = True 21 common = True
20 helpSummary = "List projects and their associated directories" 22 helpSummary = "List projects and their associated directories"
21 helpUsage = """ 23 helpUsage = """
22%prog [<project>...] 24%prog [-f] [<project>...]
25%prog [-f] -r str1 [str2]..."
23""" 26"""
24 helpDescription = """ 27 helpDescription = """
25List all projects; pass '.' to list the project for the cwd. 28List all projects; pass '.' to list the project for the cwd.
@@ -27,6 +30,14 @@ List all projects; pass '.' to list the project for the cwd.
27This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. 30This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'.
28""" 31"""
29 32
33 def _Options(self, p, show_smart=True):
34 p.add_option('-r', '--regex',
35 dest='regex', action='store_true',
36 help="Filter the project list based on regex or wildcard matching of strings")
37 p.add_option('-f', '--fullpath',
38 dest='fullpath', action='store_true',
39 help="Display the full work tree path instead of the relative path")
40
30 def Execute(self, opt, args): 41 def Execute(self, opt, args):
31 """List all projects and the associated directories. 42 """List all projects and the associated directories.
32 43
@@ -35,14 +46,33 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'.
35 discoverable. 46 discoverable.
36 47
37 Args: 48 Args:
38 opt: The options. We don't take any. 49 opt: The options.
39 args: Positional args. Can be a list of projects to list, or empty. 50 args: Positional args. Can be a list of projects to list, or empty.
40 """ 51 """
41 projects = self.GetProjects(args) 52 if not opt.regex:
53 projects = self.GetProjects(args)
54 else:
55 projects = self.FindProjects(args)
56
57 def _getpath(x):
58 if opt.fullpath:
59 return x.worktree
60 return x.relpath
42 61
43 lines = [] 62 lines = []
44 for project in projects: 63 for project in projects:
45 lines.append("%s : %s" % (project.relpath, project.name)) 64 lines.append("%s : %s" % (_getpath(project), project.name))
46 65
47 lines.sort() 66 lines.sort()
48 print '\n'.join(lines) 67 print '\n'.join(lines)
68
69 def FindProjects(self, args):
70 result = []
71 for project in self.GetProjects(''):
72 for arg in args:
73 pattern = re.compile(r'%s' % arg, re.IGNORECASE)
74 if pattern.search(project.name) or pattern.search(project.relpath):
75 result.append(project)
76 break
77 result.sort(key=lambda project: project.relpath)
78 return result