overview.py 2.6 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182
  1. # Copyright (C) 2012 The Android Open Source Project
  2. #
  3. # Licensed under the Apache License, Version 2.0 (the "License");
  4. # you may not use this file except in compliance with the License.
  5. # You may obtain a copy of the License at
  6. #
  7. # http://www.apache.org/licenses/LICENSE-2.0
  8. #
  9. # Unless required by applicable law or agreed to in writing, software
  10. # distributed under the License is distributed on an "AS IS" BASIS,
  11. # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  12. # See the License for the specific language governing permissions and
  13. # limitations under the License.
  14. from color import Coloring
  15. from command import PagedCommand
  16. class Overview(PagedCommand):
  17. common = True
  18. helpSummary = "Display overview of unmerged project branches"
  19. helpUsage = """
  20. %prog [--current-branch] [<project>...]
  21. """
  22. helpDescription = """
  23. The '%prog' command is used to display an overview of the projects branches,
  24. and list any local commits that have not yet been merged into the project.
  25. The -b/--current-branch option can be used to restrict the output to only
  26. branches currently checked out in each project. By default, all branches
  27. are displayed.
  28. """
  29. def _Options(self, p):
  30. p.add_option('-b', '--current-branch',
  31. dest="current_branch", action="store_true",
  32. help="Consider only checked out branches")
  33. def Execute(self, opt, args):
  34. all_branches = []
  35. for project in self.GetProjects(args):
  36. br = [project.GetUploadableBranch(x)
  37. for x in project.GetBranches()]
  38. br = [x for x in br if x]
  39. if opt.current_branch:
  40. br = [x for x in br if x.name == project.CurrentBranch]
  41. all_branches.extend(br)
  42. if not all_branches:
  43. return
  44. class Report(Coloring):
  45. def __init__(self, config):
  46. Coloring.__init__(self, config, 'status')
  47. self.project = self.printer('header', attr='bold')
  48. self.text = self.printer('text')
  49. out = Report(all_branches[0].project.config)
  50. out.text("Deprecated. See repo info -o.")
  51. out.nl()
  52. out.project('Projects Overview')
  53. out.nl()
  54. project = None
  55. for branch in all_branches:
  56. if project != branch.project:
  57. project = branch.project
  58. out.nl()
  59. out.project('project %s/' % project.relpath)
  60. out.nl()
  61. commits = branch.commits
  62. date = branch.date
  63. print('%s %-33s (%2d commit%s, %s)' % (
  64. branch.name == project.CurrentBranch and '*' or ' ',
  65. branch.name,
  66. len(commits),
  67. len(commits) != 1 and 's' or ' ',
  68. date))
  69. for commit in commits:
  70. print('%-35s - %s' % ('', commit))