Beispiel #1
0
Datei: cli.py Projekt: 20c/munge
def main(**options):
    conf = config.MungeConfig(try_read=options['config'])

    inp = options['input']
    outp = options['output']

    if not len(inp):
        # if there's only 1 argument, it's (incorrectly) put in output
        if outp:
            inp = (outp,)
            outp = None
        else:
            inp = ('-')
    elif len(inp) != 1:
        raise NotImplementedError("multi input not yet supported")

    src = config.parse_url(inp[0], conf.get('addrbook', []))
    data = src.cls().loadu(src.url.path)

    # use same input codec by defailt
    if not outp:
        dst = src
        dst.cls().dumpu(data, '-')
    else:
        dst = config.parse_url(outp, conf.get('addrbook', {}))
        dst.cls().dumpu(data, dst.url.path)
Beispiel #2
0
def config(config, skip_defaults):
    """
    Generates configuration file from config specifications
    """

    configurator = ClickConfigurator(
        vodka.plugin,
        skip_defaults=skip_defaults
    )

    configurator.configure(vodka.config.instance, vodka.config.InstanceHandler)

    try:
        dst = munge_config.parse_url(config)
    except ValueError:
        config = os.path.join(config, "config.yaml")
        dst = munge_config.parse_url(config)

    config_dir = os.path.dirname(config)
    if not os.path.exists(config_dir) and config_dir:
        os.makedirs(config_dir)

    dst.cls().dumpu(vodka.config.instance, dst.url.path)

    if configurator.action_required:
        click.echo("")
        click.echo("not all required values could be set by this script, please manually edit the config and set the following values")
        click.echo("")
        for item in configurator.action_required:
            click.echo("- %s" % item)
        click.echo("")

    click.echo("Config written to %s" % dst.url.path)
Beispiel #3
0
def dict_conf(filename):
  """
  Return dict object for *.conf file
  """

  f, ext = os.path.splitext(filename)
  ext = ext.lower()

  if ext == "conf" or ext == "ini":
    # python config via config parser

    config = ConfigParser()
    config.optionxform=str
    config.read(filename)
    rv = {}
    for section in config.sections():
      rv[section] = {}
      for key,value in config.items(section):
        rv[section][key] = value.strip('"').strip("'").decode("string_escape")
    return rv
  else:
    # other type of config, use munge
    if munge_config:
      src = munge_config.parse_url(filename)
      return src.cls().load(open(filename)).get("vodka")
    else:
      raise Exception("'%s' type of config encountered, install munge" % ext)
Beispiel #4
0
def test_parse_url():
    django = munge.get_codec('django')
    mysql = munge.get_codec('mysql')
    json = munge.get_codec('json')
    yaml = munge.get_codec('yaml')

    conf = config.parse_url('yaml:test')
    assert yaml == conf.cls
    assert 'test' == conf.url.path

    conf = config.parse_url('test.yaml')
    assert yaml == conf.cls
    assert 'test.yaml' == conf.url.path

    conf = config.parse_url('tyam:test', extra_schemes)
    assert yaml == conf.cls
    assert 'test' == conf.url.path

    conf = config.parse_url('django:///home/user/project/settings_dir.settings?app_name/model')
    assert django == conf.cls
    assert '/home/user/project/settings_dir.settings' == conf.url.path
    assert 'app_name/model' == conf.url.query

    conf = config.parse_url('json:http://example.com/test.txt')
    assert json == conf.cls
    assert 'http://example.com/test.txt' == conf.url.path
#    assert 'app_name/model' == conf.url.query

    with pytest.raises(ValueError):
        config.parse_url('nonexistant:test', extra_schemes)