Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/env python | 1 #!/usr/bin/env python |
| 2 # Copyright (c) 2011 The Chromium Authors. All rights reserved. | 2 # Copyright (c) 2011 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 """Applies an issue from Rietveld. | 6 """Applies an issue from Rietveld. |
| 7 """ | 7 """ |
| 8 | 8 |
| 9 import logging | 9 import logging |
| 10 import optparse | 10 import optparse |
| 11 import os | |
| 11 import sys | 12 import sys |
| 12 | 13 |
| 13 import breakpad # pylint: disable=W0611 | 14 import breakpad # pylint: disable=W0611 |
| 15 | |
| 16 import checkout | |
| 14 import fix_encoding | 17 import fix_encoding |
| 15 import rietveld | 18 import rietveld |
| 19 import scm | |
| 16 | 20 |
| 17 | 21 |
| 18 def main(): | 22 def main(): |
| 19 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) | 23 parser = optparse.OptionParser(description=sys.modules[__name__].__doc__) |
| 20 parser.add_option( | 24 parser.add_option( |
| 21 '-v', '--verbose', action='count', help='Prints debugging infos') | 25 '-v', '--verbose', action='count', help='Prints debugging infos') |
| 22 parser.add_option( | 26 parser.add_option( |
| 23 '-i', '--issue', type='int', help='Rietveld issue number') | 27 '-i', '--issue', type='int', help='Rietveld issue number') |
| 24 parser.add_option( | 28 parser.add_option( |
| 25 '-p', '--patchset', type='int', help='Rietveld issue\'s patchset number') | 29 '-p', '--patchset', type='int', help='Rietveld issue\'s patchset number') |
| 26 parser.add_option( | 30 parser.add_option( |
| 27 '-r', | 31 '-r', |
| 28 '--root_dir', | 32 '--root_dir', |
| 29 action='store', | 33 default=os.getcwd(), |
| 30 help='Root directory to apply the patch') | 34 help='Root directory to apply the patch') |
| 31 parser.add_option( | 35 parser.add_option( |
| 32 '-s', | 36 '-s', |
| 33 '--server', | 37 '--server', |
| 34 action='store', | |
| 35 default='http://codereview.chromium.org', | 38 default='http://codereview.chromium.org', |
| 36 help='Rietveld server') | 39 help='Rietveld server') |
| 37 options, args = parser.parse_args() | 40 options, args = parser.parse_args() |
| 38 LOG_FORMAT = '%(levelname)s %(filename)s(%(lineno)d): %(message)s' | 41 LOG_FORMAT = '%(levelname)s %(filename)s(%(lineno)d): %(message)s' |
| 39 if not options.verbose: | 42 if not options.verbose: |
| 40 logging.basicConfig(level=logging.WARNING, format=LOG_FORMAT) | 43 logging.basicConfig(level=logging.WARNING, format=LOG_FORMAT) |
| 41 elif options.verbose == 1: | 44 elif options.verbose == 1: |
| 42 logging.basicConfig(level=logging.INFO, format=LOG_FORMAT) | 45 logging.basicConfig(level=logging.INFO, format=LOG_FORMAT) |
| 43 elif options.verbose > 1: | 46 elif options.verbose > 1: |
| 44 logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT) | 47 logging.basicConfig(level=logging.DEBUG, format=LOG_FORMAT) |
| 45 if args: | 48 if args: |
| 46 parser.error('Extra argument(s) "%s" not understood' % ' '.join(args)) | 49 parser.error('Extra argument(s) "%s" not understood' % ' '.join(args)) |
| 47 if not options.issue: | 50 if not options.issue: |
| 48 parser.error('Require --issue') | 51 parser.error('Require --issue') |
| 49 | 52 |
| 50 obj = rietveld.Rietveld(options.server, None, None) | 53 obj = rietveld.Rietveld(options.server, None, None) |
| 51 | 54 |
| 52 if not options.patchset: | 55 if not options.patchset: |
| 53 options.patchset = obj.get_issue_properties( | 56 options.patchset = obj.get_issue_properties( |
| 54 options.issue, False)['patchsets'][-1] | 57 options.issue, False)['patchsets'][-1] |
| 55 logging.info('Using patchset %d' % options.patchset) | 58 logging.info('Using patchset %d' % options.patchset) |
| 56 obj.get_patch(options.issue, options.patchset) | 59 # Download the patch. |
| 60 patchset = obj.get_patch(options.issue, options.patchset) | |
| 61 | |
| 62 scm_type = scm.determine_scm(options.root_dir) | |
|
Dirk Pranke
2011/05/02 20:32:05
Nit ... seems like this block could be turned into
| |
| 63 if scm_type == 'svn': | |
| 64 scm_obj = checkout.SvnCheckout(options.root_dir, None, None, None, None) | |
| 65 elif scm_type == 'git': | |
| 66 scm_obj = checkout.GitCheckoutBase(options.root_dir, None, None) | |
| 67 elif scm_type == None: | |
| 68 scm_obj = checkout.RawCheckout(options.root_dir, None) | |
| 69 else: | |
| 70 parser.error('Couldn\'t determine the scm') | |
| 71 | |
| 72 # Apply the patch. | |
| 73 scm_obj.apply_patch(patchset) | |
| 57 return 0 | 74 return 0 |
| 58 | 75 |
| 59 | 76 |
| 60 if __name__ == "__main__": | 77 if __name__ == "__main__": |
| 61 fix_encoding.fix_encoding() | 78 fix_encoding.fix_encoding() |
| 62 sys.exit(main()) | 79 sys.exit(main()) |
| OLD | NEW |