예제 #1
0
파일: option.py 프로젝트: yodermk/holland
def merge_options(path, *defaults_files, **kwargs):
    defaults_config = INIConfig()
    defaults_config._new_namespace('client')
    for config in defaults_files:
        _my_config = load_options(config)
        update_config(defaults_config, _my_config)

    for key in ('user', 'password', 'socket', 'host', 'port'):
        if kwargs.get(key) is not None:
            defaults_config['client'][key] = kwargs[key]
    write_options(defaults_config, path)
예제 #2
0
def merge_options(path, *defaults_files, **kwargs):
    defaults_config = INIConfig()
    defaults_config._new_namespace("client")
    for config in defaults_files:
        _my_config = load_options(config)
        update_config(defaults_config, _my_config)

    for key in ("user", "password", "socket", "host", "port"):
        if kwargs.get(key) is not None:
            defaults_config["client"][key] = kwargs[key]
    write_options(defaults_config, path)
예제 #3
0
파일: option.py 프로젝트: yodermk/holland
def write_options(config, filename):
    quoted_config = INIConfig()
    update_config(quoted_config, config)
    for section in config:
        for key in config[section]:
            if '"' in config[section][key]:
                config[section][key] = quote(config[section][key])

    if isinstance(filename, basestring):
        filename = codecs.open(filename, 'w', 'utf8')
    data = unicode(config)
    print >> filename, data
    filename.close()
예제 #4
0
def write_options(config, filename):
    quoted_config = INIConfig()
    update_config(quoted_config, config)
    for section in config:
        for key in config[section]:
            if '"' in config[section][key]:
                config[section][key] = quote(config[section][key])

    if isinstance(filename, basestring):
        filename = codecs.open(filename, "w", "utf8")
    data = unicode(config)
    print >> filename, data
    filename.close()
예제 #5
0
파일: option.py 프로젝트: yodermk/holland
def client_sections(config):
    """Create a copy of config with only valid client auth sections

    This includes [client], [mysql] and [mysqldump] with only options
    related to mysql authentication.
    """

    clean_cfg = INIConfig()
    clean_cfg._new_namespace('client')
    valid_sections = ['client', 'mysql', 'holland']
    for section in valid_sections:
        if section in config:
            clean_section = client_keys(config[section])
            update_config(clean_cfg.client, clean_section)
    return clean_cfg
예제 #6
0
def client_sections(config):
    """Create a copy of config with only valid client auth sections

    This includes [client], [mysql] and [mysqldump] with only options
    related to mysql authentication.
    """

    clean_cfg = INIConfig()
    clean_cfg._new_namespace("client")
    valid_sections = ["client", "mysql", "holland"]
    for section in valid_sections:
        if section in config:
            clean_section = client_keys(config[section])
            update_config(clean_cfg.client, clean_section)
    return clean_cfg
예제 #7
0
파일: option.py 프로젝트: yodermk/holland
def client_keys(config):
    """Create a copy of option_section with non-authentication options
    stripped out.

    Authentication options supported are:
    user, password, host, port, and socket
    """

    clean_namespace = BasicConfig()
    update_config(clean_namespace, config)
    valid_keys = ['user', 'password', 'host', 'port', 'socket']
    for key in config:
        if key not in valid_keys:
            del clean_namespace[key]
        else:
            clean_namespace[key] = unquote(config[key])
    return clean_namespace
예제 #8
0
def client_keys(config):
    """Create a copy of option_section with non-authentication options
    stripped out.

    Authentication options supported are:
    user, password, host, port, and socket
    """

    clean_namespace = BasicConfig()
    update_config(clean_namespace, config)
    valid_keys = ["user", "password", "host", "port", "socket"]
    for key in config:
        if key not in valid_keys:
            del clean_namespace[key]
        else:
            clean_namespace[key] = unquote(config[key])
    return clean_namespace