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