overview.py 2.7 KB

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