overview.py 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081
  1. #
  2. # Copyright (C) 2012 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 __future__ import print_function
  16. from color import Coloring
  17. from command import PagedCommand
  18. class Overview(PagedCommand):
  19. common = True
  20. helpSummary = "Display overview of unmerged project branches"
  21. helpUsage = """
  22. %prog [--current-branch] [<project>...]
  23. """
  24. helpDescription = """
  25. The '%prog' command is used to display an overview of the projects branches,
  26. and list any local commits that have not yet been merged into the project.
  27. The -b/--current-branch option can be used to restrict the output to only
  28. branches currently checked out in each project. By default, all branches
  29. are displayed.
  30. """
  31. def _Options(self, p):
  32. p.add_option('-b', '--current-branch',
  33. dest="current_branch", action="store_true",
  34. help="Consider only checked out branches")
  35. def Execute(self, opt, args):
  36. all_branches = []
  37. for project in self.GetProjects(args):
  38. br = [project.GetUploadableBranch(x)
  39. for x in project.GetBranches().keys()]
  40. br = [x for x in br if x]
  41. if opt.current_branch:
  42. br = [x for x in br if x.name == project.CurrentBranch]
  43. all_branches.extend(br)
  44. if not all_branches:
  45. return
  46. class Report(Coloring):
  47. def __init__(self, config):
  48. Coloring.__init__(self, config, 'status')
  49. self.project = self.printer('header', attr='bold')
  50. out = Report(all_branches[0].project.config)
  51. out.project('Projects Overview')
  52. out.nl()
  53. project = None
  54. for branch in all_branches:
  55. if project != branch.project:
  56. project = branch.project
  57. out.nl()
  58. out.project('project %s/' % project.relpath)
  59. out.nl()
  60. commits = branch.commits
  61. date = branch.date
  62. print('%s %-33s (%2d commit%s, %s)' % (
  63. branch.name == project.CurrentBranch and '*' or ' ',
  64. branch.name,
  65. len(commits),
  66. len(commits) != 1 and 's' or ' ',
  67. date))
  68. for commit in commits:
  69. print('%-35s - %s' % ('', commit))