diff options
Diffstat (limited to 'subcmds/list.py')
-rw-r--r-- | subcmds/list.py | 31 |
1 files changed, 18 insertions, 13 deletions
diff --git a/subcmds/list.py b/subcmds/list.py index 0d5c27f7..a3358245 100644 --- a/subcmds/list.py +++ b/subcmds/list.py | |||
@@ -14,7 +14,7 @@ | |||
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 | 17 | import sys |
18 | 18 | ||
19 | from command import Command, MirrorSafeCommand | 19 | from command import Command, MirrorSafeCommand |
20 | 20 | ||
@@ -38,6 +38,12 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. | |||
38 | p.add_option('-f', '--fullpath', | 38 | p.add_option('-f', '--fullpath', |
39 | dest='fullpath', action='store_true', | 39 | dest='fullpath', action='store_true', |
40 | help="Display the full work tree path instead of the relative path") | 40 | help="Display the full work tree path instead of the relative path") |
41 | p.add_option('-n', '--name-only', | ||
42 | dest='name_only', action='store_true', | ||
43 | help="Display only the name of the repository") | ||
44 | p.add_option('-p', '--path-only', | ||
45 | dest='path_only', action='store_true', | ||
46 | help="Display only the path of the repository") | ||
41 | 47 | ||
42 | def Execute(self, opt, args): | 48 | def Execute(self, opt, args): |
43 | """List all projects and the associated directories. | 49 | """List all projects and the associated directories. |
@@ -50,6 +56,11 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. | |||
50 | opt: The options. | 56 | opt: The options. |
51 | args: Positional args. Can be a list of projects to list, or empty. | 57 | args: Positional args. Can be a list of projects to list, or empty. |
52 | """ | 58 | """ |
59 | |||
60 | if opt.fullpath and opt.name_only: | ||
61 | print('error: cannot combine -f and -n', file=sys.stderr) | ||
62 | sys.exit(1) | ||
63 | |||
53 | if not opt.regex: | 64 | if not opt.regex: |
54 | projects = self.GetProjects(args) | 65 | projects = self.GetProjects(args) |
55 | else: | 66 | else: |
@@ -62,18 +73,12 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. | |||
62 | 73 | ||
63 | lines = [] | 74 | lines = [] |
64 | for project in projects: | 75 | for project in projects: |
65 | lines.append("%s : %s" % (_getpath(project), project.name)) | 76 | if opt.name_only and not opt.path_only: |
77 | lines.append("%s" % ( project.name)) | ||
78 | elif opt.path_only and not opt.name_only: | ||
79 | lines.append("%s" % (_getpath(project))) | ||
80 | else: | ||
81 | lines.append("%s : %s" % (_getpath(project), project.name)) | ||
66 | 82 | ||
67 | lines.sort() | 83 | lines.sort() |
68 | print('\n'.join(lines)) | 84 | print('\n'.join(lines)) |
69 | |||
70 | def FindProjects(self, args): | ||
71 | result = [] | ||
72 | for project in self.GetProjects(''): | ||
73 | for arg in args: | ||
74 | pattern = re.compile(r'%s' % arg, re.IGNORECASE) | ||
75 | if pattern.search(project.name) or pattern.search(project.relpath): | ||
76 | result.append(project) | ||
77 | break | ||
78 | result.sort(key=lambda project: project.relpath) | ||
79 | return result | ||