Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 #!/usr/bin/python | 1 #!/usr/bin/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 """Convert SVN based DEPS into .DEPS.git for use with NewGit.""" | 6 """Convert SVN based DEPS into .DEPS.git for use with NewGit.""" |
| 7 | 7 |
| 8 import collections | 8 import collections |
| 9 from cStringIO import StringIO | 9 from cStringIO import StringIO |
| 10 import json | 10 import json |
| (...skipping 262 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 273 message_th.start() | 273 message_th.start() |
| 274 | 274 |
| 275 for th in threads: | 275 for th in threads: |
| 276 th.join() | 276 th.join() |
| 277 message_q.put(Queue.Empty) | 277 message_q.put(Queue.Empty) |
| 278 message_th.join() | 278 message_th.join() |
| 279 | 279 |
| 280 return results | 280 return results |
| 281 | 281 |
| 282 | 282 |
| 283 def convert_json(option, _, value, parser): | |
| 284 """Provide an OptionParser callback to unmarshal a JSON string.""" | |
| 285 setattr(parser.values, option.dest, json.loads(value)) | |
| 286 | |
| 287 | |
| 283 def main(): | 288 def main(): |
| 284 parser = optparse.OptionParser() | 289 parser = optparse.OptionParser() |
| 285 parser.add_option('-d', '--deps', default='DEPS', | 290 parser.add_option('-d', '--deps', default='DEPS', |
| 286 help='path to the DEPS file to convert') | 291 help='path to the DEPS file to convert') |
| 287 parser.add_option('-o', '--out', | 292 parser.add_option('-o', '--out', |
| 288 help='path to the converted DEPS file (default: stdout)') | 293 help='path to the converted DEPS file (default: stdout)') |
| 289 parser.add_option('-j', '--num-threads', type='int', default=4, | 294 parser.add_option('-j', '--num-threads', type='int', default=4, |
| 290 help='Maximum number of threads') | 295 help='Maximum number of threads') |
| 291 parser.add_option('-t', '--type', | 296 parser.add_option('-t', '--type', |
| 292 help='[DEPRECATED] type of DEPS file (public, etc)') | 297 help='[DEPRECATED] type of DEPS file (public, etc)') |
| 293 parser.add_option('-x', '--extra-rules', | 298 parser.add_option('-x', '--extra-rules', |
| 294 help='Path to file with additional conversion rules.') | 299 help='Path to file with additional conversion rules.') |
| 295 parser.add_option('-r', '--repos', | 300 parser.add_option('-r', '--repos', |
| 296 help='path to the directory holding all the Git repos') | 301 help='path to the directory holding all the Git repos') |
| 297 parser.add_option('-w', '--workspace', metavar='PATH', | 302 parser.add_option('-w', '--workspace', metavar='PATH', |
| 298 help='top level of a git-based gclient checkout') | 303 help='top level of a git-based gclient checkout') |
| 299 parser.add_option('-c', '--cache_dir', | 304 parser.add_option('-c', '--cache_dir', |
| 300 help='top level of a gclient git cache diretory.') | 305 help='top level of a gclient git cache diretory.') |
| 301 parser.add_option('-s', '--shallow', action='store_true', | 306 parser.add_option('-s', '--shallow', action='store_true', |
| 302 help='Use shallow checkouts when populating cache dirs.') | 307 help='Use shallow checkouts when populating cache dirs.') |
| 308 parser.add_option('--custom_vars', action='callback', callback=convert_json, | |
| 309 type='string', nargs=1, default={}, | |
|
hinoka
2014/10/02 21:05:51
nargs is redundant.
szager1
2014/10/02 21:16:22
Prefer default=None
kjellander_chromium
2014/10/03 07:13:31
Done.
kjellander_chromium
2014/10/03 07:13:31
Done.
| |
| 310 help='custom_vars dict in JSON format') | |
| 303 parser.add_option('--no_fail_fast', action='store_true', | 311 parser.add_option('--no_fail_fast', action='store_true', |
| 304 help='Try to process the whole DEPS, rather than failing ' | 312 help='Try to process the whole DEPS, rather than failing ' |
| 305 'on the first bad entry.') | 313 'on the first bad entry.') |
| 306 parser.add_option('--verify', action='store_true', | 314 parser.add_option('--verify', action='store_true', |
| 307 help='ping each Git repo to make sure it exists') | 315 help='ping each Git repo to make sure it exists') |
| 308 parser.add_option('--json', | 316 parser.add_option('--json', |
| 309 help='path to a JSON file for machine-readable output') | 317 help='path to a JSON file for machine-readable output') |
| 310 options = parser.parse_args()[0] | 318 options = parser.parse_args()[0] |
| 311 | 319 |
| 312 # Get the content of the DEPS file. | 320 # Get the content of the DEPS file. |
| 313 deps, deps_os, include_rules, skip_child_includes, hooks, deps_vars = ( | 321 deps, deps_os, include_rules, skip_child_includes, hooks, deps_vars = ( |
| 314 deps_utils.GetDepsContent(options.deps)) | 322 deps_utils.GetDepsContent(options.deps, options.custom_vars)) |
| 315 | 323 |
| 316 if options.extra_rules and options.type: | 324 if options.extra_rules and options.type: |
| 317 parser.error('Can\'t specify type and extra-rules at the same time.') | 325 parser.error('Can\'t specify type and extra-rules at the same time.') |
| 318 elif options.type: | 326 elif options.type: |
| 319 options.extra_rules = os.path.join( | 327 options.extra_rules = os.path.join( |
| 320 os.path.abspath(os.path.dirname(__file__)), | 328 os.path.abspath(os.path.dirname(__file__)), |
| 321 'svn_to_git_%s.py' % options.type) | 329 'svn_to_git_%s.py' % options.type) |
| 322 if options.cache_dir and options.repos: | 330 if options.cache_dir and options.repos: |
| 323 parser.error('Can\'t specify both cache_dir and repos at the same time.') | 331 parser.error('Can\'t specify both cache_dir and repos at the same time.') |
| 324 if options.shallow and not options.cache_dir: | 332 if options.shallow and not options.cache_dir: |
| (...skipping 101 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 426 return 0 | 434 return 0 |
| 427 | 435 |
| 428 # Write the DEPS file to disk. | 436 # Write the DEPS file to disk. |
| 429 deps_utils.WriteDeps(options.out, deps_vars, results.new_deps, deps_os, | 437 deps_utils.WriteDeps(options.out, deps_vars, results.new_deps, deps_os, |
| 430 include_rules, skip_child_includes, hooks) | 438 include_rules, skip_child_includes, hooks) |
| 431 return 0 | 439 return 0 |
| 432 | 440 |
| 433 | 441 |
| 434 if '__main__' == __name__: | 442 if '__main__' == __name__: |
| 435 sys.exit(main()) | 443 sys.exit(main()) |
| OLD | NEW |