diff options
Diffstat (limited to 'subcmds/list.py')
-rw-r--r-- | subcmds/list.py | 38 |
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 | ||
16 | import re | ||
17 | |||
16 | from command import Command, MirrorSafeCommand | 18 | from command import Command, MirrorSafeCommand |
17 | 19 | ||
18 | class List(Command, MirrorSafeCommand): | 20 | class 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 = """ |
25 | List all projects; pass '.' to list the project for the cwd. | 28 | List 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. | |||
27 | This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. | 30 | This 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 | ||