diff options
Diffstat (limited to 'subcmds/list.py')
| -rw-r--r-- | subcmds/list.py | 48 |
1 files changed, 48 insertions, 0 deletions
diff --git a/subcmds/list.py b/subcmds/list.py new file mode 100644 index 00000000..2be82570 --- /dev/null +++ b/subcmds/list.py | |||
| @@ -0,0 +1,48 @@ | |||
| 1 | # | ||
| 2 | # Copyright (C) 2011 The Android Open Source Project | ||
| 3 | # | ||
| 4 | # Licensed under the Apache License, Version 2.0 (the "License"); | ||
| 5 | # you may not use this file except in compliance with the License. | ||
| 6 | # You may obtain a copy of the License at | ||
| 7 | # | ||
| 8 | # http://www.apache.org/licenses/LICENSE-2.0 | ||
| 9 | # | ||
| 10 | # Unless required by applicable law or agreed to in writing, software | ||
| 11 | # distributed under the License is distributed on an "AS IS" BASIS, | ||
| 12 | # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| 13 | # See the License for the specific language governing permissions and | ||
| 14 | # limitations under the License. | ||
| 15 | |||
| 16 | from command import Command, MirrorSafeCommand | ||
| 17 | |||
| 18 | class List(Command, MirrorSafeCommand): | ||
| 19 | common = True | ||
| 20 | helpSummary = "List projects and their associated directories" | ||
| 21 | helpUsage = """ | ||
| 22 | %prog [<project>...] | ||
| 23 | """ | ||
| 24 | helpDescription = """ | ||
| 25 | List all projects; pass '.' to list the project for the cwd. | ||
| 26 | |||
| 27 | This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'. | ||
| 28 | """ | ||
| 29 | |||
| 30 | def Execute(self, opt, args): | ||
| 31 | """List all projects and the associated directories. | ||
| 32 | |||
| 33 | This may be possible to do with 'repo forall', but repo newbies have | ||
| 34 | trouble figuring that out. The idea here is that it should be more | ||
| 35 | discoverable. | ||
| 36 | |||
| 37 | Args: | ||
| 38 | opt: The options. We don't take any. | ||
| 39 | args: Positional args. Can be a list of projects to list, or empty. | ||
| 40 | """ | ||
| 41 | projects = self.GetProjects(args) | ||
| 42 | |||
| 43 | lines = [] | ||
| 44 | for project in projects: | ||
| 45 | lines.append("%s : %s" % (project.relpath, project.name)) | ||
| 46 | |||
| 47 | lines.sort() | ||
| 48 | print '\n'.join(lines) | ||
