| OLD | NEW |
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. |
| 3 # Use of this source code is governed by a BSD-style license that can be | 3 # Use of this source code is governed by a BSD-style license that can be |
| 4 # found in the LICENSE file. | 4 # found in the LICENSE file. |
| 5 | 5 |
| 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> | 6 # Copyright (C) 2008 Evan Martin <martine@danga.com> |
| 7 | 7 |
| 8 """A git-command for integrating reviews on Rietveld.""" | 8 """A git-command for integrating reviews on Rietveld.""" |
| 9 | 9 |
| 10 from distutils.version import LooseVersion | 10 from distutils.version import LooseVersion |
| (...skipping 1059 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1070 - Red not sent for review or broken | 1070 - Red not sent for review or broken |
| 1071 - Cyan was committed, branch can be deleted | 1071 - Cyan was committed, branch can be deleted |
| 1072 | 1072 |
| 1073 Also see 'git cl comments'. | 1073 Also see 'git cl comments'. |
| 1074 """ | 1074 """ |
| 1075 parser.add_option('--field', | 1075 parser.add_option('--field', |
| 1076 help='print only specific field (desc|id|patch|url)') | 1076 help='print only specific field (desc|id|patch|url)') |
| 1077 parser.add_option('-f', '--fast', action='store_true', | 1077 parser.add_option('-f', '--fast', action='store_true', |
| 1078 help='Do not retrieve review status') | 1078 help='Do not retrieve review status') |
| 1079 (options, args) = parser.parse_args(args) | 1079 (options, args) = parser.parse_args(args) |
| 1080 if args: |
| 1081 parser.error('Unsupported args: %s' % args) |
| 1080 | 1082 |
| 1081 if options.field: | 1083 if options.field: |
| 1082 cl = Changelist() | 1084 cl = Changelist() |
| 1083 if options.field.startswith('desc'): | 1085 if options.field.startswith('desc'): |
| 1084 print cl.GetDescription() | 1086 print cl.GetDescription() |
| 1085 elif options.field == 'id': | 1087 elif options.field == 'id': |
| 1086 issueid = cl.GetIssue() | 1088 issueid = cl.GetIssue() |
| 1087 if issueid: | 1089 if issueid: |
| 1088 print issueid | 1090 print issueid |
| 1089 elif options.field == 'patch': | 1091 elif options.field == 'patch': |
| (...skipping 86 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 1176 if not cl.GetIssue(): | 1178 if not cl.GetIssue(): |
| 1177 print 'no issue assigned.' | 1179 print 'no issue assigned.' |
| 1178 return 0 | 1180 return 0 |
| 1179 print cl.GetBranch() | 1181 print cl.GetBranch() |
| 1180 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL()) | 1182 print 'Issue number: %s (%s)' % (cl.GetIssue(), cl.GetIssueURL()) |
| 1181 print 'Issue description:' | 1183 print 'Issue description:' |
| 1182 print cl.GetDescription(pretty=True) | 1184 print cl.GetDescription(pretty=True) |
| 1183 return 0 | 1185 return 0 |
| 1184 | 1186 |
| 1185 | 1187 |
| 1188 def colorize_CMDstatus_doc(): |
| 1189 """To be called once in main() to add colors to git cl status help.""" |
| 1190 colors = [i for i in dir(Fore) if i[0].isupper()] |
| 1191 |
| 1192 def colorize_line(line): |
| 1193 for color in colors: |
| 1194 if color in line.upper(): |
| 1195 # Extract whitespaces first and the leading '-'. |
| 1196 indent = len(line) - len(line.lstrip(' ')) + 1 |
| 1197 return line[:indent] + getattr(Fore, color) + line[indent:] + Fore.RESET |
| 1198 return line |
| 1199 |
| 1200 lines = CMDstatus.__doc__.splitlines() |
| 1201 CMDstatus.__doc__ = '\n'.join(colorize_line(l) for l in lines) |
| 1202 |
| 1203 |
| 1186 @subcommand.usage('[issue_number]') | 1204 @subcommand.usage('[issue_number]') |
| 1187 def CMDissue(parser, args): | 1205 def CMDissue(parser, args): |
| 1188 """Sets or displays the current code review issue number. | 1206 """Sets or displays the current code review issue number. |
| 1189 | 1207 |
| 1190 Pass issue number 0 to clear the current issue. | 1208 Pass issue number 0 to clear the current issue. |
| 1191 """ | 1209 """ |
| 1192 _, args = parser.parse_args(args) | 1210 _, args = parser.parse_args(args) |
| 1193 | 1211 |
| 1194 cl = Changelist() | 1212 cl = Changelist() |
| 1195 if len(args) > 0: | 1213 if len(args) > 0: |
| (...skipping 953 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 2149 self.add_option( | 2167 self.add_option( |
| 2150 '-v', '--verbose', action='count', default=0, | 2168 '-v', '--verbose', action='count', default=0, |
| 2151 help='Use 2 times for more debugging info') | 2169 help='Use 2 times for more debugging info') |
| 2152 | 2170 |
| 2153 def parse_args(self, args=None, values=None): | 2171 def parse_args(self, args=None, values=None): |
| 2154 options, args = optparse.OptionParser.parse_args(self, args, values) | 2172 options, args = optparse.OptionParser.parse_args(self, args, values) |
| 2155 levels = [logging.WARNING, logging.INFO, logging.DEBUG] | 2173 levels = [logging.WARNING, logging.INFO, logging.DEBUG] |
| 2156 logging.basicConfig(level=levels[min(options.verbose, len(levels) - 1)]) | 2174 logging.basicConfig(level=levels[min(options.verbose, len(levels) - 1)]) |
| 2157 return options, args | 2175 return options, args |
| 2158 | 2176 |
| 2159 def format_description(self, _): | |
| 2160 """Disables automatic reformatting.""" | |
| 2161 lines = self.description.rstrip().splitlines() | |
| 2162 lines_fixed = [lines[0]] + [l[2:] if len(l) >= 2 else l for l in lines[1:]] | |
| 2163 description = ''.join(l + '\n' for l in lines_fixed) | |
| 2164 return description[0].upper() + description[1:] | |
| 2165 | |
| 2166 | 2177 |
| 2167 def main(argv): | 2178 def main(argv): |
| 2168 if sys.hexversion < 0x02060000: | 2179 if sys.hexversion < 0x02060000: |
| 2169 print >> sys.stderr, ( | 2180 print >> sys.stderr, ( |
| 2170 '\nYour python version %s is unsupported, please upgrade.\n' % | 2181 '\nYour python version %s is unsupported, please upgrade.\n' % |
| 2171 sys.version.split(' ', 1)[0]) | 2182 sys.version.split(' ', 1)[0]) |
| 2172 return 2 | 2183 return 2 |
| 2173 | 2184 |
| 2174 # Reload settings. | 2185 # Reload settings. |
| 2175 global settings | 2186 global settings |
| 2176 settings = Settings() | 2187 settings = Settings() |
| 2177 | 2188 |
| 2189 colorize_CMDstatus_doc() |
| 2178 dispatcher = subcommand.CommandDispatcher(__name__) | 2190 dispatcher = subcommand.CommandDispatcher(__name__) |
| 2179 try: | 2191 try: |
| 2180 return dispatcher.execute(OptionParser(), argv) | 2192 return dispatcher.execute(OptionParser(), argv) |
| 2181 except urllib2.HTTPError, e: | 2193 except urllib2.HTTPError, e: |
| 2182 if e.code != 500: | 2194 if e.code != 500: |
| 2183 raise | 2195 raise |
| 2184 DieWithError( | 2196 DieWithError( |
| 2185 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' | 2197 ('AppEngine is misbehaving and returned HTTP %d, again. Keep faith ' |
| 2186 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) | 2198 'and retry or visit go/isgaeup.\n%s') % (e.code, str(e))) |
| 2187 | 2199 |
| 2188 | 2200 |
| 2189 if __name__ == '__main__': | 2201 if __name__ == '__main__': |
| 2190 # These affect sys.stdout so do it outside of main() to simplify mocks in | 2202 # These affect sys.stdout so do it outside of main() to simplify mocks in |
| 2191 # unit testing. | 2203 # unit testing. |
| 2192 fix_encoding.fix_encoding() | 2204 fix_encoding.fix_encoding() |
| 2193 colorama.init() | 2205 colorama.init() |
| 2194 sys.exit(main(sys.argv[1:])) | 2206 sys.exit(main(sys.argv[1:])) |
| OLD | NEW |