overview.py 2.5 KB

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