Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(973)

Side by Side Diff: roll_dep.py

Issue 1160833005: roll_dep.py: switch to argparse (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/tools/depot_tools
Patch Set: Created 5 years, 6 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright 2015 The Chromium Authors. All rights reserved. 2 # Copyright 2015 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 """Rolls DEPS controlled dependency. 6 """Rolls DEPS controlled dependency.
7 7
8 Works only with git checkout and git dependencies. 8 Works only with git checkout and git dependencies. Currently this
9 script will always roll to the tip of to origin/master.
9 """ 10 """
10 11
11 import optparse 12 import argparse
12 import os 13 import os
13 import re 14 import re
14 import subprocess 15 import subprocess
15 import sys 16 import sys
16 17
17 NEED_SHELL = sys.platform.startswith('win') 18 NEED_SHELL = sys.platform.startswith('win')
18 19
19 20
20 class Error(Exception): 21 class Error(Exception):
21 pass 22 pass
(...skipping 24 matching lines...) Expand all
46 with open(deps, 'rb') as f: 47 with open(deps, 'rb') as f:
47 deps_content = f.read() 48 deps_content = f.read()
48 except (IOError, OSError): 49 except (IOError, OSError):
49 raise Error('Ensure the script is run in the directory ' 50 raise Error('Ensure the script is run in the directory '
50 'containing DEPS file.') 51 'containing DEPS file.')
51 52
52 if not is_pristine(root): 53 if not is_pristine(root):
53 raise Error('Ensure %s is clean first.' % root) 54 raise Error('Ensure %s is clean first.' % root)
54 55
55 full_dir = os.path.normpath(os.path.join(os.path.dirname(root), deps_dir)) 56 full_dir = os.path.normpath(os.path.join(os.path.dirname(root), deps_dir))
57 if not os.path.isdir(full_dir):
58 raise Error('Directory not found: %s' % deps_dir)
56 head = check_output(['git', 'rev-parse', 'HEAD'], cwd=full_dir).strip() 59 head = check_output(['git', 'rev-parse', 'HEAD'], cwd=full_dir).strip()
57 60
58 if not head in deps_content: 61 if not head in deps_content:
59 print('Warning: %s is not checked out at the expected revision in DEPS' % 62 print('Warning: %s is not checked out at the expected revision in DEPS' %
60 deps_dir) 63 deps_dir)
61 if key is None: 64 if key is None:
62 print("Warning: no key specified. Using '%s'." % deps_dir) 65 print("Warning: no key specified. Using '%s'." % deps_dir)
63 key = deps_dir 66 key = deps_dir
64 67
65 # It happens if the user checked out a branch in the dependency by himself. 68 # It happens if the user checked out a branch in the dependency by himself.
(...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after
115 print('') 118 print('')
116 if not reviewers: 119 if not reviewers:
117 print('You forgot to pass -r, make sure to insert a R=foo@example.com line') 120 print('You forgot to pass -r, make sure to insert a R=foo@example.com line')
118 print('to the commit description before emailing.') 121 print('to the commit description before emailing.')
119 print('') 122 print('')
120 print('Run:') 123 print('Run:')
121 print(' git cl upload --send-mail') 124 print(' git cl upload --send-mail')
122 125
123 126
124 def main(): 127 def main():
125 parser = optparse.OptionParser( 128 parser = argparse.ArgumentParser(description=__doc__)
126 description=sys.modules[__name__].__doc__, 129 parser.add_argument('-r', '--reviewer',
127 usage='roll-dep [flags] <dependency path> <variable>')
128 parser.add_option(
129 '-r', '--reviewer', default='',
130 help='To specify multiple reviewers, use comma separated list, e.g. ' 130 help='To specify multiple reviewers, use comma separated list, e.g. '
131 '-r joe,jane,john. Defaults to @chromium.org') 131 '-r joe,jane,john. Defaults to @chromium.org')
132 parser.add_option('-b', '--bug', default='') 132 parser.add_argument('-b', '--bug')
133 options, args = parser.parse_args() 133 parser.add_argument('dep_path', help='path to dependency')
134 if not len(args) or len(args) > 2: 134 parser.add_argument('key', nargs='?',
135 parser.error('Expect one or two arguments' % args) 135 help='regexp for dependency in DEPS file')
136 args = parser.parse_args()
136 137
137 reviewers = None 138 reviewers = None
138 if options.reviewer: 139 if args.reviewer:
139 reviewers = options.reviewer.split(',') 140 reviewers = args.reviewer.split(',')
140 for i, r in enumerate(reviewers): 141 for i, r in enumerate(reviewers):
141 if not '@' in r: 142 if not '@' in r:
142 reviewers[i] = r + '@chromium.org' 143 reviewers[i] = r + '@chromium.org'
143 144
144 try: 145 try:
145 roll( 146 roll(
146 os.getcwd(), 147 os.getcwd(),
147 deps_dir=args[0], 148 args.dep_path,
148 key=args[1] if len(args) > 1 else None, 149 args.key,
149 reviewers=reviewers, 150 reviewers=reviewers,
150 bug=options.bug) 151 bug=args.bug)
151 152
152 except Error as e: 153 except Error as e:
153 sys.stderr.write('error: %s\n' % e) 154 sys.stderr.write('error: %s\n' % e)
154 return 1 155 return 1
155 156
156 return 0 157 return 0
157 158
158 159
159 if __name__ == '__main__': 160 if __name__ == '__main__':
160 sys.exit(main()) 161 sys.exit(main())
OLDNEW
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698