list.py 1.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748
  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. from command import Command, MirrorSafeCommand
  16. class List(Command, MirrorSafeCommand):
  17. common = True
  18. helpSummary = "List projects and their associated directories"
  19. helpUsage = """
  20. %prog [<project>...]
  21. """
  22. helpDescription = """
  23. List all projects; pass '.' to list the project for the cwd.
  24. This is similar to running: repo forall -c 'echo "$REPO_PATH : $REPO_PROJECT"'.
  25. """
  26. def Execute(self, opt, args):
  27. """List all projects and the associated directories.
  28. This may be possible to do with 'repo forall', but repo newbies have
  29. trouble figuring that out. The idea here is that it should be more
  30. discoverable.
  31. Args:
  32. opt: The options. We don't take any.
  33. args: Positional args. Can be a list of projects to list, or empty.
  34. """
  35. projects = self.GetProjects(args)
  36. lines = []
  37. for project in projects:
  38. lines.append("%s : %s" % (project.relpath, project.name))
  39. lines.sort()
  40. print '\n'.join(lines)