The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 1 | # |
| 2 | # Copyright (C) 2008 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 | |
| 16 | import sys |
| 17 | |
| 18 | from color import Coloring |
| 19 | from command import InteractiveCommand |
| 20 | from git_command import GitCommand |
| 21 | |
| 22 | class _ProjectList(Coloring): |
| 23 | def __init__(self, gc): |
| 24 | Coloring.__init__(self, gc, 'interactive') |
| 25 | self.prompt = self.printer('prompt', fg='blue', attr='bold') |
| 26 | self.header = self.printer('header', attr='bold') |
| 27 | self.help = self.printer('help', fg='red', attr='bold') |
| 28 | |
| 29 | class Stage(InteractiveCommand): |
| 30 | common = True |
| 31 | helpSummary = "Stage file(s) for commit" |
| 32 | helpUsage = """ |
| 33 | %prog -i [<project>...] |
| 34 | """ |
| 35 | helpDescription = """ |
| 36 | The '%prog' command stages files to prepare the next commit. |
| 37 | """ |
| 38 | |
| 39 | def _Options(self, p): |
| 40 | p.add_option('-i', '--interactive', |
| 41 | dest='interactive', action='store_true', |
| 42 | help='use interactive staging') |
| 43 | |
| 44 | def Execute(self, opt, args): |
| 45 | if opt.interactive: |
| 46 | self._Interactive(opt, args) |
| 47 | else: |
| 48 | self.Usage() |
| 49 | |
| 50 | def _Interactive(self, opt, args): |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 51 | all_projects = filter(lambda x: x.IsDirty(), self.GetProjects(args)) |
| 52 | if not all_projects: |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 53 | print >>sys.stderr,'no projects have uncommitted modifications' |
| 54 | return |
| 55 | |
| 56 | out = _ProjectList(self.manifest.manifestProject.config) |
| 57 | while True: |
Shawn O. Pearce | deec053 | 2009-04-18 11:22:13 -0700 | [diff] [blame] | 58 | out.header(' %s', 'project') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 59 | out.nl() |
| 60 | |
Sarah Owens | a6053d5 | 2012-11-01 13:36:50 -0700 | [diff] [blame] | 61 | for i in range(len(all_projects)): |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 62 | p = all_projects[i] |
Shawn O. Pearce | deec053 | 2009-04-18 11:22:13 -0700 | [diff] [blame] | 63 | out.write('%3d: %s', i + 1, p.relpath + '/') |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 64 | out.nl() |
| 65 | out.nl() |
| 66 | |
| 67 | out.write('%3d: (', 0) |
| 68 | out.prompt('q') |
| 69 | out.write('uit)') |
| 70 | out.nl() |
| 71 | |
| 72 | out.prompt('project> ') |
| 73 | try: |
| 74 | a = sys.stdin.readline() |
| 75 | except KeyboardInterrupt: |
| 76 | out.nl() |
| 77 | break |
| 78 | if a == '': |
| 79 | out.nl() |
| 80 | break |
| 81 | |
| 82 | a = a.strip() |
| 83 | if a.lower() in ('q', 'quit', 'exit'): |
| 84 | break |
| 85 | if not a: |
| 86 | continue |
| 87 | |
| 88 | try: |
| 89 | a_index = int(a) |
| 90 | except ValueError: |
| 91 | a_index = None |
| 92 | |
| 93 | if a_index is not None: |
| 94 | if a_index == 0: |
| 95 | break |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 96 | if 0 < a_index and a_index <= len(all_projects): |
| 97 | _AddI(all_projects[a_index - 1]) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 98 | continue |
| 99 | |
David Pursehouse | 8a68ff9 | 2012-09-24 12:15:13 +0900 | [diff] [blame] | 100 | p = filter(lambda x: x.name == a or x.relpath == a, all_projects) |
The Android Open Source Project | cf31fe9 | 2008-10-21 07:00:00 -0700 | [diff] [blame] | 101 | if len(p) == 1: |
| 102 | _AddI(p[0]) |
| 103 | continue |
| 104 | print 'Bye.' |
| 105 | |
| 106 | def _AddI(project): |
| 107 | p = GitCommand(project, ['add', '--interactive'], bare=False) |
| 108 | p.Wait() |