Sha256: bc41e21d4894e658cc2b9fa88004ce12f661dc654e3bdc255347543a0950682e

Contents?: true

Size: 1.56 KB

Versions: 39

Compression:

Stored size: 1.56 KB

Contents

# Copyright (c) 2013 The Chromium Authors. All rights reserved.
# Use of this source code is governed by a BSD-style license that can be
# found in the LICENSE file.

"""This module holds utilities which make writing configs easier."""

import json


class Config(object):
  """Base class for all configs.

  Provides methods that are expected to be overridden by child classes. Also
  provides an command-line parsing method that converts the unified command-line
  interface used in depot_tools to the unified python interface defined here."""

  @staticmethod
  def fetch_spec(_props):
    """Returns instructions to check out the project, conditioned on |props|."""
    raise NotImplementedError

  @staticmethod
  def expected_root(_props):
    """Returns the directory into which the checkout will be performed."""
    raise NotImplementedError

  def handle_args(self, argv):
    """Passes the command-line arguments through to the appropriate method."""
    methods = {'fetch': self.fetch_spec,
               'root':  self.expected_root}
    if len(argv) <= 1 or argv[1] not in methods:
      print 'Must specify a a fetch/root action'
      return 1

    def looks_like_arg(arg):
      return arg.startswith('--') and arg.count('=') == 1

    bad_parms = [x for x in argv[2:] if not looks_like_arg(x)]
    if bad_parms:
      print 'Got bad arguments %s' % bad_parms
      return 1

    method = methods[argv[1]]
    props = dict(x.split('=', 1) for x in (y.lstrip('-') for y in argv[2:]))

    self.output(method(props))

  @staticmethod
  def output(data):
    print(json.dumps(data))

Version data entries

39 entries across 39 versions & 1 rubygems

Version Path
libv8-6.7.288.46.1 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.7.288.46.0 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.7.288.46.1beta0 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.3.292.48.1 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.3.292.48.0 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.3.292.48.0beta2 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.3.292.48.0beta1 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.2.414.42.1 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.2.414.42.0 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.2.414.42.0beta1 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.0.286.54.3 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.0.286.54.2 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.0.286.54.1 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.0.286.54.0 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.0.286.54.0beta2 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.0.286.54.0beta1 vendor/depot_tools/fetch_configs/config_util.py
libv8-6.0.286.44.0beta1 vendor/depot_tools/fetch_configs/config_util.py
libv8-5.9.211.38.1 vendor/depot_tools/fetch_configs/config_util.py
libv8-5.9.211.38.0 vendor/depot_tools/fetch_configs/config_util.py
libv8-5.9.211.38.0beta0 vendor/depot_tools/fetch_configs/config_util.py