def load_options(filename): """Load mysql option file from filename""" filename = os.path.abspath(os.path.expanduser(filename)) cfg = INIConfig() try: cfg._readfp(open(filename, "r")) except ParsingError, exc: LOG.debug("Skipping unparsable lines") for lineno, line in exc.errors: LOG.debug("Ignored line %d: %s", lineno, line.rstrip())
def load_options(filename): """Load mysql option file from filename""" filename = os.path.abspath(os.path.expanduser(filename)) cfg = INIConfig() try: cfg._readfp(open(filename, 'r')) except ParsingError, exc: LOG.debug("Skipping unparsable lines") for lineno, line in exc.errors: LOG.debug("Ignored line %d: %s", lineno, line.rstrip())
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)
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)
def make_mysql_config(mysql_config): """Given a mysql:client config, create a config object that represents the auth parameters""" defaults_config = INIConfig() defaults_config._new_namespace('client') for config in mysql_config['defaults-extra-file']: LOG.info("Loading %s [%s]", config, os.path.expanduser(config)) _my_config = load_options(config) update_config(defaults_config, _my_config) for key in ('user', 'password', 'socket', 'host', 'port'): if key in mysql_config and mysql_config[key]: defaults_config['client'][key] = mysql_config[key] return defaults_config
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
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
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()