diff options
Diffstat (limited to 'subcmds/list.py')
-rw-r--r-- | subcmds/list.py | 49 |
1 files changed, 32 insertions, 17 deletions
diff --git a/subcmds/list.py b/subcmds/list.py index 00172f0e..6adf85b7 100644 --- a/subcmds/list.py +++ b/subcmds/list.py | |||
@@ -1,5 +1,3 @@ | |||
1 | # -*- coding:utf-8 -*- | ||
2 | # | ||
3 | # Copyright (C) 2011 The Android Open Source Project | 1 | # Copyright (C) 2011 The Android Open Source Project |
4 | # | 2 | # |
5 | # Licensed under the Apache License, Version 2.0 (the "License"); | 3 | # Licensed under the Apache License, Version 2.0 (the "License"); |
@@ -14,45 +12,59 @@ | |||
14 | # See the License for the specific language governing permissions and | 12 | # See the License for the specific language governing permissions and |
15 | # limitations under the License. | 13 | # limitations under the License. |
16 | 14 | ||
17 | from __future__ import print_function | 15 | import os |
18 | import sys | ||
19 | 16 | ||
20 | from command import Command, MirrorSafeCommand | 17 | from command import Command, MirrorSafeCommand |
21 | 18 | ||
19 | |||
22 | class List(Command, MirrorSafeCommand): | 20 | class List(Command, MirrorSafeCommand): |
23 | common = True | 21 | COMMON = True |
24 | helpSummary = "List projects and their associated directories" | 22 | helpSummary = "List projects and their associated directories" |
25 | helpUsage = """ | 23 | helpUsage = """ |
26 | %prog [-f] [<project>...] | 24 | %prog [-f] [<project>...] |
27 | %prog [-f] -r str1 [str2]..." | 25 | %prog [-f] -r str1 [str2]... |
28 | """ | 26 | """ |
29 | helpDescription = """ | 27 | helpDescription = """ |
30 | List all projects; pass '.' to list the project for the cwd. | 28 | List all projects; pass '.' to list the project for the cwd. |
31 | 29 | ||
30 | By default, only projects that currently exist in the checkout are shown. If | ||
31 | you want to list all projects (using the specified filter settings), use the | ||
32 | --all option. If you want to show all projects regardless of the manifest | ||
33 | groups, then also pass --groups all. | ||
34 | |||
32 | This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. | 35 | This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. |
33 | """ | 36 | """ |
34 | 37 | ||
35 | def _Options(self, p): | 38 | def _Options(self, p): |
36 | p.add_option('-r', '--regex', | 39 | p.add_option('-r', '--regex', |
37 | dest='regex', action='store_true', | 40 | dest='regex', action='store_true', |
38 | help="Filter the project list based on regex or wildcard matching of strings") | 41 | help='filter the project list based on regex or wildcard matching of strings') |
39 | p.add_option('-g', '--groups', | 42 | p.add_option('-g', '--groups', |
40 | dest='groups', | 43 | dest='groups', |
41 | help="Filter the project list based on the groups the project is in") | 44 | help='filter the project list based on the groups the project is in') |
42 | p.add_option('-f', '--fullpath', | 45 | p.add_option('-a', '--all', |
43 | dest='fullpath', action='store_true', | 46 | action='store_true', |
44 | help="Display the full work tree path instead of the relative path") | 47 | help='show projects regardless of checkout state') |
45 | p.add_option('-n', '--name-only', | 48 | p.add_option('-n', '--name-only', |
46 | dest='name_only', action='store_true', | 49 | dest='name_only', action='store_true', |
47 | help="Display only the name of the repository") | 50 | help='display only the name of the repository') |
48 | p.add_option('-p', '--path-only', | 51 | p.add_option('-p', '--path-only', |
49 | dest='path_only', action='store_true', | 52 | dest='path_only', action='store_true', |
50 | help="Display only the path of the repository") | 53 | help='display only the path of the repository') |
54 | p.add_option('-f', '--fullpath', | ||
55 | dest='fullpath', action='store_true', | ||
56 | help='display the full work tree path instead of the relative path') | ||
57 | p.add_option('--relative-to', metavar='PATH', | ||
58 | help='display paths relative to this one (default: top of repo client checkout)') | ||
51 | 59 | ||
52 | def ValidateOptions(self, opt, args): | 60 | def ValidateOptions(self, opt, args): |
53 | if opt.fullpath and opt.name_only: | 61 | if opt.fullpath and opt.name_only: |
54 | self.OptionParser.error('cannot combine -f and -n') | 62 | self.OptionParser.error('cannot combine -f and -n') |
55 | 63 | ||
64 | # Resolve any symlinks so the output is stable. | ||
65 | if opt.relative_to: | ||
66 | opt.relative_to = os.path.realpath(opt.relative_to) | ||
67 | |||
56 | def Execute(self, opt, args): | 68 | def Execute(self, opt, args): |
57 | """List all projects and the associated directories. | 69 | """List all projects and the associated directories. |
58 | 70 | ||
@@ -65,23 +77,26 @@ This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. | |||
65 | args: Positional args. Can be a list of projects to list, or empty. | 77 | args: Positional args. Can be a list of projects to list, or empty. |
66 | """ | 78 | """ |
67 | if not opt.regex: | 79 | if not opt.regex: |
68 | projects = self.GetProjects(args, groups=opt.groups) | 80 | projects = self.GetProjects(args, groups=opt.groups, missing_ok=opt.all) |
69 | else: | 81 | else: |
70 | projects = self.FindProjects(args) | 82 | projects = self.FindProjects(args) |
71 | 83 | ||
72 | def _getpath(x): | 84 | def _getpath(x): |
73 | if opt.fullpath: | 85 | if opt.fullpath: |
74 | return x.worktree | 86 | return x.worktree |
87 | if opt.relative_to: | ||
88 | return os.path.relpath(x.worktree, opt.relative_to) | ||
75 | return x.relpath | 89 | return x.relpath |
76 | 90 | ||
77 | lines = [] | 91 | lines = [] |
78 | for project in projects: | 92 | for project in projects: |
79 | if opt.name_only and not opt.path_only: | 93 | if opt.name_only and not opt.path_only: |
80 | lines.append("%s" % ( project.name)) | 94 | lines.append("%s" % (project.name)) |
81 | elif opt.path_only and not opt.name_only: | 95 | elif opt.path_only and not opt.name_only: |
82 | lines.append("%s" % (_getpath(project))) | 96 | lines.append("%s" % (_getpath(project))) |
83 | else: | 97 | else: |
84 | lines.append("%s : %s" % (_getpath(project), project.name)) | 98 | lines.append("%s : %s" % (_getpath(project), project.name)) |
85 | 99 | ||
86 | lines.sort() | 100 | if lines: |
87 | print('\n'.join(lines)) | 101 | lines.sort() |
102 | print('\n'.join(lines)) | ||