| OLD | NEW |
| (Empty) |
| 1 # Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 # Use of this source code is governed by a BSD-style license that can be | |
| 3 # found in the LICENSE file. | |
| 4 | |
| 5 """This module holds utilities which make writing recipes easier.""" | |
| 6 | |
| 7 import json | |
| 8 | |
| 9 | |
| 10 class Recipe(object): | |
| 11 """Base class for all recipes. | |
| 12 | |
| 13 Provides methods that are expected to be overridden by child classes. Also | |
| 14 provides an command-line parsing method that converts the unified command-line | |
| 15 interface used in depot_tools to the unified python interface defined here.""" | |
| 16 | |
| 17 @staticmethod | |
| 18 def fetch_spec(_props): | |
| 19 """Returns instructions to check out the project, conditioned on |props|.""" | |
| 20 raise NotImplementedError | |
| 21 | |
| 22 @staticmethod | |
| 23 def expected_root(_props): | |
| 24 """Returns the directory into which the checkout will be performed.""" | |
| 25 raise NotImplementedError | |
| 26 | |
| 27 def handle_args(self, argv): | |
| 28 """Passes the command-line arguments through to the appropriate method.""" | |
| 29 methods = {'fetch': self.fetch_spec, | |
| 30 'root': self.expected_root} | |
| 31 if len(argv) <= 1 or argv[1] not in methods: | |
| 32 print 'Must specify a a fetch/root action' | |
| 33 return 1 | |
| 34 | |
| 35 def looks_like_arg(arg): | |
| 36 return arg.startswith('--') and arg.count('=') == 1 | |
| 37 | |
| 38 bad_parms = [x for x in argv[2:] if not looks_like_arg(x)] | |
| 39 if bad_parms: | |
| 40 print 'Got bad arguments %s' % bad_parms | |
| 41 return 1 | |
| 42 | |
| 43 method = methods[argv[1]] | |
| 44 props = dict(x.split('=', 1) for x in (y.lstrip('-') for y in argv[2:])) | |
| 45 | |
| 46 self.output(method(props)) | |
| 47 | |
| 48 @staticmethod | |
| 49 def output(data): | |
| 50 print(json.dumps(data)) | |
| OLD | NEW |