Python ConfigParser.SafeConfigParser() Examples
The following are 30
code examples of ConfigParser.SafeConfigParser().
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example.
You may also want to check out all available functions/classes of the module
ConfigParser
, or try the search function
.

Example #1
Source File: configparserwrapper.py From CAMISIM with Apache License 2.0 | 6 votes |
def __init__(self, logfile=None, verbose=True): """ Wrapper for the SafeConfigParser class for easy use. @attention: config_file argument may be file path or stream. @param logfile: file handler or file path to a log file @type logfile: file | FileIO | StringIO | None @param verbose: No stdout or stderr messages. Warnings and errors will be only logged to a file, if one is given @type verbose: bool @return: None @rtype: None """ super(ConfigParserWrapper, self).__init__( label="ConfigParserWrapper", logfile=logfile, verbose=verbose) self._config = ConfigParser() self._config_file_path = None
Example #2
Source File: setup.py From PyOptiX with MIT License | 6 votes |
def save_pyoptix_conf(nvcc_path, compile_args, include_dirs, library_dirs, libraries): try: config = ConfigParser() config.add_section('pyoptix') config.set('pyoptix', 'nvcc_path', nvcc_path) config.set('pyoptix', 'compile_args', os.pathsep.join(compile_args)) config.set('pyoptix', 'include_dirs', os.pathsep.join(include_dirs)) config.set('pyoptix', 'library_dirs', os.pathsep.join(library_dirs)) config.set('pyoptix', 'libraries', os.pathsep.join(libraries)) tmp = NamedTemporaryFile(mode='w+', delete=False) config.write(tmp) tmp.close() config_path = os.path.join(os.path.dirname(sys.executable), 'pyoptix.conf') check_call_sudo_if_fails(['cp', tmp.name, config_path]) check_call_sudo_if_fails(['cp', tmp.name, '/etc/pyoptix.conf']) check_call_sudo_if_fails(['chmod', '644', config_path]) check_call_sudo_if_fails(['chmod', '644', '/etc/pyoptix.conf']) except Exception as e: print("PyOptiX configuration could not be saved. When you use pyoptix.Compiler, " "nvcc path must be in PATH, OptiX library paths must be in LD_LIBRARY_PATH, and pyoptix.Compiler " "attributes should be set manually.")
Example #3
Source File: getlogs_servicenow.py From InsightAgent with Apache License 2.0 | 6 votes |
def update_state(setting, value, append=False, write=False): # update in-mem if append: current = ','.join(agent_config_vars['state'][setting]) value = '{},{}'.format(current, value) if current else value agent_config_vars['state'][setting] = value.split(',') else: agent_config_vars['state'][setting] = value logger.debug('setting {} to {}'.format(setting, value)) # update config file if write and not cli_config_vars['testing']: config_ini = config_ini_path() if os.path.exists(config_ini): config_parser = ConfigParser.SafeConfigParser() config_parser.read(config_ini) config_parser.set('state', setting, str(value)) with open(config_ini, 'w') as config_file: config_parser.write(config_file) # return new value (if append) return value
Example #4
Source File: getmessages_file_replay.py From InsightAgent with Apache License 2.0 | 6 votes |
def update_state(setting, value, append=False): # update in-mem if append: current = ','.join(agent_config_vars['state'][setting]) value = '{},{}'.format(current, value) if current else value agent_config_vars['state'][setting] = value.split(',') else: agent_config_vars['state'][setting] = value logger.debug('setting {} to {}'.format(setting, value)) # update config file if 'TAIL' in agent_config_vars['data_format']: config_ini = config_ini_path() if os.path.exists(config_ini): config_parser = ConfigParser.SafeConfigParser() config_parser.read(config_ini) config_parser.set('state', setting, str(value)) with open(config_ini, 'w') as config_file: config_parser.write(config_file) # return new value (if append) return value
Example #5
Source File: insightagent-boilerplate.py From InsightAgent with Apache License 2.0 | 6 votes |
def update_state(setting, value, append=False, write=False): # update in-mem if append: current = ','.join(agent_config_vars['state'][setting]) value = '{},{}'.format(current, value) if current else value agent_config_vars['state'][setting] = value.split(',') else: agent_config_vars['state'][setting] = value logger.debug('setting {} to {}'.format(setting, value)) # update config file if write and not cli_config_vars['testing']: config_ini = config_ini_path() if os.path.exists(config_ini): config_parser = ConfigParser.SafeConfigParser() config_parser.read(config_ini) config_parser.set('state', setting, str(value)) with open(config_ini, 'w') as config_file: config_parser.write(config_file) # return new value (if append) return value
Example #6
Source File: getmessages_mariadb.py From InsightAgent with Apache License 2.0 | 6 votes |
def update_state(setting, value, append=False, write=False): # update in-mem if append: current = ','.join(agent_config_vars['state'][setting]) value = '{},{}'.format(current, value) if current else value agent_config_vars['state'][setting] = value.split(',') else: agent_config_vars['state'][setting] = value logger.debug('setting {} to {}'.format(setting, value)) # update config file if write and not cli_config_vars['testing']: config_ini = config_ini_path() if os.path.exists(config_ini): config_parser = ConfigParser.SafeConfigParser() config_parser.read(config_ini) config_parser.set('state', setting, str(value)) with open(config_ini, 'w') as config_file: config_parser.write(config_file) # return new value (if append) return value
Example #7
Source File: versioneer.py From landmarkerio-server with BSD 3-Clause "New" or "Revised" License | 6 votes |
def get_config_from_root(root): # This might raise EnvironmentError (if setup.cfg is missing), or # configparser.NoSectionError (if it lacks a [versioneer] section), or # configparser.NoOptionError (if it lacks "VCS="). See the docstring at # the top of versioneer.py for instructions on writing your setup.cfg . setup_cfg = os.path.join(root, "setup.cfg") parser = configparser.SafeConfigParser() with open(setup_cfg, "r") as f: parser.readfp(f) VCS = parser.get("versioneer", "VCS") # mandatory def get(parser, name): if parser.has_option("versioneer", name): return parser.get("versioneer", name) return None cfg = VersioneerConfig() cfg.VCS = VCS cfg.style = get(parser, "style") or "" cfg.versionfile_source = get(parser, "versionfile_source") cfg.versionfile_build = get(parser, "versionfile_build") cfg.tag_prefix = get(parser, "tag_prefix") cfg.parentdir_prefix = get(parser, "parentdir_prefix") cfg.verbose = get(parser, "verbose") return cfg
Example #8
Source File: versioneer.py From recordlinkage with BSD 3-Clause "New" or "Revised" License | 6 votes |
def get_config_from_root(root): # This might raise EnvironmentError (if setup.cfg is missing), or # configparser.NoSectionError (if it lacks a [versioneer] section), or # configparser.NoOptionError (if it lacks "VCS="). See the docstring at # the top of versioneer.py for instructions on writing your setup.cfg . setup_cfg = os.path.join(root, "setup.cfg") parser = configparser.SafeConfigParser() with open(setup_cfg, "r") as f: parser.readfp(f) VCS = parser.get("versioneer", "VCS") # mandatory def get(parser, name): if parser.has_option("versioneer", name): return parser.get("versioneer", name) return None cfg = VersioneerConfig() cfg.VCS = VCS cfg.style = get(parser, "style") or "" cfg.versionfile_source = get(parser, "versionfile_source") cfg.versionfile_build = get(parser, "versionfile_build") cfg.tag_prefix = get(parser, "tag_prefix") cfg.parentdir_prefix = get(parser, "parentdir_prefix") cfg.verbose = get(parser, "verbose") return cfg
Example #9
Source File: session.py From odoorpc with GNU Lesser General Public License v3.0 | 6 votes |
def remove(name, rc_file='~/.odoorpcrc'): """Remove the session configuration identified by `name` from the `rc_file` file. >>> import odoorpc >>> odoorpc.session.remove('foo') # doctest: +SKIP .. doctest:: :hide: >>> import odoorpc >>> session = '%s_session' % DB >>> odoorpc.session.remove(session) :raise: `ValueError` (wrong session name) """ conf = ConfigParser() conf.read([os.path.expanduser(rc_file)]) if not conf.has_section(name): raise ValueError( "'{}' session does not exist in {}".format(name, rc_file) ) conf.remove_section(name) with open(os.path.expanduser(rc_file), 'wb') as file_: conf.write(file_)
Example #10
Source File: versioneer.py From wg-gesucht-crawler-cli with MIT License | 6 votes |
def get_config_from_root(root): # This might raise EnvironmentError (if setup.cfg is missing), or # configparser.NoSectionError (if it lacks a [versioneer] section), or # configparser.NoOptionError (if it lacks "VCS="). See the docstring at # the top of versioneer.py for instructions on writing your setup.cfg . setup_cfg = os.path.join(root, "setup.cfg") parser = configparser.SafeConfigParser() with open(setup_cfg, "r") as f: parser.readfp(f) VCS = parser.get("versioneer", "VCS") # mandatory def get(parser, name): if parser.has_option("versioneer", name): return parser.get("versioneer", name) return None cfg = VersioneerConfig() cfg.VCS = VCS cfg.style = get(parser, "style") or "" cfg.versionfile_source = get(parser, "versionfile_source") cfg.versionfile_build = get(parser, "versionfile_build") cfg.tag_prefix = get(parser, "tag_prefix") cfg.parentdir_prefix = get(parser, "parentdir_prefix") cfg.verbose = get(parser, "verbose") return cfg
Example #11
Source File: config.py From rucio with Apache License 2.0 | 6 votes |
def __init__(self): if sys.version_info < (3, 2): self.parser = ConfigParser.SafeConfigParser(os.environ) else: self.parser = ConfigParser.ConfigParser(defaults=os.environ) if 'RUCIO_CONFIG' in os.environ: self.configfile = os.environ['RUCIO_CONFIG'] else: configs = [os.path.join(confdir, 'rucio.cfg') for confdir in get_config_dirs()] self.configfile = next(iter(filter(os.path.exists, configs)), None) if self.configfile is None: raise RuntimeError('Could not load Rucio configuration file. ' 'Rucio looked in the following paths for a configuration file, in order:' '\n\t' + '\n\t'.join(configs)) if not self.parser.read(self.configfile) == [self.configfile]: raise RuntimeError('Could not load Rucio configuration file. ' 'Rucio tried loading the following configuration file:' '\n\t' + self.configfile)
Example #12
Source File: index.py From psychsim with MIT License | 6 votes |
def getWorld(scenario,session): # Load scenario try: filename = getScenarioFile(scenario,session) os.stat(filename) first = False except OSError: filename = getScenarioFile(scenario) first = True # Get game configuration config = SafeConfigParser() if __DEPLOYED__: config.read('scenarios/%s.cfg' % (scenario)) else: config.read('/home/david/PsychSim/psychsim/examples/%s.cfg' % (scenario)) return World(filename),config,first
Example #13
Source File: versioneer.py From aospy with Apache License 2.0 | 5 votes |
def get_config_from_root(root): """Read the project setup.cfg file to determine Versioneer config.""" # This might raise EnvironmentError (if setup.cfg is missing), or # configparser.NoSectionError (if it lacks a [versioneer] section), or # configparser.NoOptionError (if it lacks "VCS="). See the docstring at # the top of versioneer.py for instructions on writing your setup.cfg . setup_cfg = os.path.join(root, "setup.cfg") parser = configparser.SafeConfigParser() with open(setup_cfg, "r") as f: parser.readfp(f) VCS = parser.get("versioneer", "VCS") # mandatory def get(parser, name): if parser.has_option("versioneer", name): return parser.get("versioneer", name) return None cfg = VersioneerConfig() cfg.VCS = VCS cfg.style = get(parser, "style") or "" cfg.versionfile_source = get(parser, "versionfile_source") cfg.versionfile_build = get(parser, "versionfile_build") cfg.tag_prefix = get(parser, "tag_prefix") if cfg.tag_prefix in ("''", '""'): cfg.tag_prefix = "" cfg.parentdir_prefix = get(parser, "parentdir_prefix") cfg.verbose = get(parser, "verbose") return cfg
Example #14
Source File: versioneer.py From xrft with MIT License | 5 votes |
def get_config_from_root(root): """Read the project setup.cfg file to determine Versioneer config.""" # This might raise EnvironmentError (if setup.cfg is missing), or # configparser.NoSectionError (if it lacks a [versioneer] section), or # configparser.NoOptionError (if it lacks "VCS="). See the docstring at # the top of versioneer.py for instructions on writing your setup.cfg . setup_cfg = os.path.join(root, "setup.cfg") parser = configparser.SafeConfigParser() with open(setup_cfg, "r") as f: parser.readfp(f) VCS = parser.get("versioneer", "VCS") # mandatory def get(parser, name): if parser.has_option("versioneer", name): return parser.get("versioneer", name) return None cfg = VersioneerConfig() cfg.VCS = VCS cfg.style = get(parser, "style") or "" cfg.versionfile_source = get(parser, "versionfile_source") cfg.versionfile_build = get(parser, "versionfile_build") cfg.tag_prefix = get(parser, "tag_prefix") if cfg.tag_prefix in ("''", '""'): cfg.tag_prefix = "" cfg.parentdir_prefix = get(parser, "parentdir_prefix") cfg.verbose = get(parser, "verbose") return cfg
Example #15
Source File: configparserwrapper.py From CAMISIM with Apache License 2.0 | 5 votes |
def __init__(self, config_file, logfile=None, verbose=True): """ Wrapper for the SafeConfigParser class for easy use. @attention: config_file argument may be file path or stream. @param config_file: file handler or file path to a config file @type config_file: file | FileIO | StringIO @param logfile: file handler or file path to a log file @type logfile: file | FileIO | StringIO | None @param verbose: No stdout or stderr messages. Warnings and errors will be only logged to a file, if one is given @type verbose: bool @return: None @rtype: None """ assert isinstance(config_file, basestring) or self.is_stream(config_file) assert logfile is None or isinstance(logfile, basestring) or self.is_stream(logfile) super(ConfigParserWrapper, self).__init__(logfile=logfile, verbose=verbose) self._config = SafeConfigParser() if isinstance(config_file, basestring) and not os.path.isfile(config_file): self._logger.error("Config file does not exist: '{}'".format(config_file)) raise Exception("File does not exist") if isinstance(config_file, basestring): self._config.read(config_file) self._config_file_path = config_file elif self.is_stream(config_file): self._config.readfp(config_file) self._config_file_path = config_file.name else: self._logger.error("Invalid config file argument '{}'".format(config_file)) raise Exception("Unknown argument")
Example #16
Source File: versioneer.py From NiBetaSeries with MIT License | 5 votes |
def get_config_from_root(root): """Read the project setup.cfg file to determine Versioneer config.""" # This might raise EnvironmentError (if setup.cfg is missing), or # configparser.NoSectionError (if it lacks a [versioneer] section), or # configparser.NoOptionError (if it lacks "VCS="). See the docstring at # the top of versioneer.py for instructions on writing your setup.cfg . setup_cfg = os.path.join(root, "setup.cfg") parser = configparser.SafeConfigParser() with open(setup_cfg, "r") as f: parser.readfp(f) VCS = parser.get("versioneer", "VCS") # mandatory def get(parser, name): if parser.has_option("versioneer", name): return parser.get("versioneer", name) return None cfg = VersioneerConfig() cfg.VCS = VCS cfg.style = get(parser, "style") or "" cfg.versionfile_source = get(parser, "versionfile_source") cfg.versionfile_build = get(parser, "versionfile_build") cfg.tag_prefix = get(parser, "tag_prefix") if cfg.tag_prefix in ("''", '""'): cfg.tag_prefix = "" cfg.parentdir_prefix = get(parser, "parentdir_prefix") cfg.verbose = get(parser, "verbose") return cfg
Example #17
Source File: config.py From pgrepup with GNU General Public License v3.0 | 5 votes |
def create(): this.config = SafeConfigParser() return this.config
Example #18
Source File: config.py From pgrepup with GNU General Public License v3.0 | 5 votes |
def load(filename): this.config = SafeConfigParser() load_result = this.config.read(os.path.expanduser(filename)) if len(load_result) != 1: raise ConfigFileNotFound("The configuration file %s does not exist" % filename) this.filename = os.path.expanduser(filename)
Example #19
Source File: getmetrics_sysdig.py From InsightAgent with Apache License 2.0 | 5 votes |
def get_sysdig_config(): """Read and parse Sysdig config from config.ini""" if os.path.exists(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini"))): config_parser = ConfigParser.SafeConfigParser() config_parser.read(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini"))) try: sysdig_api_key = config_parser.get('sysdig', 'api_key') hostname = config_parser.get('sysdig', 'hostname') all_metrics = config_parser.get('sysdig', 'all_metrics').split(',') sysdig_http_proxy = config_parser.get('sysdig', 'sysdig_http_proxy') sysdig_https_proxy = config_parser.get('sysdig', 'sysdig_https_proxy') sysdig_metric_chunk_size= config_parser.get('sysdig', 'metric_chunk_size') sysdig_host_chunk_size=config_parser.get('sysdig', 'host_chunk_size') except ConfigParser.NoOptionError: logger.error( "Agent not correctly configured. Check config file.") sys.exit(1) if len(sysdig_api_key) == 0: logger.warning( "Agent not correctly configured(API KEY). Check config file.") exit() if len(hostname) == 0: logger.warning( "Agent not correctly configured. Check config file.") exit() sysdig_config = { "sysdig_api_key": sysdig_api_key, "hostname": hostname, "all_metrics": all_metrics, "httpProxy": sysdig_http_proxy, "httpsProxy": sysdig_https_proxy, "host_chunk_size":sysdig_host_chunk_size, "metric_chunk_size":sysdig_metric_chunk_size } else: logger.warning("No config file found. Exiting...") exit() return sysdig_config
Example #20
Source File: getmetrics_hadoop.py From InsightAgent with Apache License 2.0 | 5 votes |
def get_hadoop_config(): """Read and parse Hadoop config from config.ini""" if os.path.exists(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini"))): config_parser = ConfigParser.SafeConfigParser() config_parser.read(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini"))) try: name_nodes = config_parser.get('hadoop', 'name_nodes') data_nodes = config_parser.get('hadoop', 'data_nodes') yarn_nodes = config_parser.get('hadoop', 'yarn_nodes') except ConfigParser.NoOptionError: logger.error( "Agent not correctly configured. Check config file.") sys.exit(1) if len(name_nodes) != 0: name_nodes = name_nodes.split(",") else: name_nodes = ["http://127.0.0.1:50070"] if len(data_nodes) != 0: data_nodes = data_nodes.split(",") else: data_nodes = ["http://127.0.0.1:50075"] if len(yarn_nodes) != 0: yarn_nodes = yarn_nodes.split(",") else: yarn_nodes = ["http://127.0.0.1:8088"] hadoop_config = { "NAME_NODES": name_nodes, "DATA_NODES": data_nodes, "YARN_NODES": yarn_nodes } else: logger.warning("No config file found. Using defaults.") hadoop_config = { "NAME_NODES": ["http://127.0.0.1:50070"], "DATA_NODES": ["http://127.0.0.1:50075"], "YARN_NODES": ["http://127.0.0.1:8088"] } return hadoop_config
Example #21
Source File: getmetrics_opentsdb.py From InsightAgent with Apache License 2.0 | 5 votes |
def get_agent_config_vars(): if os.path.exists(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini"))): config_parser = ConfigParser.SafeConfigParser() config_parser.read(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini"))) try: user_name = config_parser.get('insightfinder', 'user_name') license_key = config_parser.get('insightfinder', 'license_key') project_name = config_parser.get('insightfinder', 'project_name') except ConfigParser.NoOptionError: logger.error( "Agent not correctly configured. Check config file.") sys.exit(1) if len(user_name) == 0: logger.warning( "Agent not correctly configured(user_name). Check config file.") sys.exit(1) if len(license_key) == 0: logger.warning( "Agent not correctly configured(license_key). Check config file.") sys.exit(1) if len(project_name) == 0: logger.warning( "Agent not correctly configured(project_name). Check config file.") sys.exit(1) config_vars = { "userName": user_name, "licenseKey": license_key, "projectName": project_name } return config_vars else: logger.error( "Agent not correctly configured. Check config file.") sys.exit(1)
Example #22
Source File: getmetrics_opentsdb.py From InsightAgent with Apache License 2.0 | 5 votes |
def get_opentsdb_config(): """Read and parse Open TSDB config from config.ini""" if os.path.exists(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini"))): config_parser = ConfigParser.SafeConfigParser() config_parser.read(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini"))) try: opentsdb_url = config_parser.get('opentsdb', 'opentsdb_server_url') opentsdb_token = config_parser.get('opentsdb', 'token') opentsdb_metrics = config_parser.get('opentsdb', 'metrics') except ConfigParser.NoOptionError: logger.error( "Agent not correctly configured. Check config file.") sys.exit(1) if len(opentsdb_url) == 0: logger.warning( "Agent not correctly configured(OPENTSDB_URL). Check config file. Using \"127.0.0.1:4242\" as default.") opentsdb_url = "http://127.0.0.1:4242" if len(opentsdb_metrics) != 0: opentsdb_metrics = opentsdb_metrics.split(",") else: opentsdb_metrics = [] opentsdb_config = { "OPENTSDB_URL": opentsdb_url, "OPENTSDB_METRICS": opentsdb_metrics, "OPENTSDB_TOKEN": opentsdb_token } else: logger.warning("No config file found. Using defaults.") opentsdb_config = { "OPENTSDB_URL": "http://127.0.0.1:4242", "OPENTSDB_METRICS": "", "OPENTSDB_TOKEN": "" } return opentsdb_config
Example #23
Source File: getmetrics_datadog.py From InsightAgent with Apache License 2.0 | 5 votes |
def get_datadog_config(): """Read and parse DataDog config from config.ini""" if os.path.exists(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini"))): config_parser = ConfigParser.SafeConfigParser() config_parser.read(os.path.abspath(os.path.join(__file__, os.pardir, "config.ini"))) try: datadog_app_key = config_parser.get('datadog', 'app_key') datadog_api_key = config_parser.get('datadog', 'api_key') datadog_http_proxy = config_parser.get('datadog', 'datadog_http_proxy') datadog_https_proxy = config_parser.get('datadog', 'datadog_https_proxy') except ConfigParser.NoOptionError: logger.error( "Agent not correctly configured. Check config file.") sys.exit(1) if len(datadog_app_key) == 0: logger.warning( "Agent not correctly configured(APP KEY). Check config file.") exit() if len(datadog_api_key) == 0: logger.warning( "Agent not correctly configured(API KEY). Check config file.") exit() datadog_config = { "DATADOG_APP_KEY": datadog_app_key, "DATADOG_API_KEY": datadog_api_key, "httpProxy": datadog_http_proxy, "httpsProxy": datadog_https_proxy } else: logger.warning("No config file found. Exiting...") exit() return datadog_config
Example #24
Source File: versioneer.py From QCElemental with BSD 3-Clause "New" or "Revised" License | 5 votes |
def get_config_from_root(root): """Read the project setup.cfg file to determine Versioneer config.""" # This might raise EnvironmentError (if setup.cfg is missing), or # configparser.NoSectionError (if it lacks a [versioneer] section), or # configparser.NoOptionError (if it lacks "VCS="). See the docstring at # the top of versioneer.py for instructions on writing your setup.cfg . setup_cfg = os.path.join(root, "setup.cfg") parser = configparser.SafeConfigParser() with open(setup_cfg, "r") as f: parser.readfp(f) VCS = parser.get("versioneer", "VCS") # mandatory def get(parser, name): if parser.has_option("versioneer", name): return parser.get("versioneer", name) return None cfg = VersioneerConfig() cfg.VCS = VCS cfg.style = get(parser, "style") or "" cfg.versionfile_source = get(parser, "versionfile_source") cfg.versionfile_build = get(parser, "versionfile_build") cfg.tag_prefix = get(parser, "tag_prefix") if cfg.tag_prefix in ("''", '""'): cfg.tag_prefix = "" cfg.parentdir_prefix = get(parser, "parentdir_prefix") cfg.verbose = get(parser, "verbose") return cfg
Example #25
Source File: versioneer.py From btle-sniffer with MIT License | 5 votes |
def get_config_from_root(root): """Read the project setup.cfg file to determine Versioneer config.""" # This might raise EnvironmentError (if setup.cfg is missing), or # configparser.NoSectionError (if it lacks a [versioneer] section), or # configparser.NoOptionError (if it lacks "VCS="). See the docstring at # the top of versioneer.py for instructions on writing your setup.cfg . setup_cfg = os.path.join(root, "setup.cfg") parser = configparser.SafeConfigParser() with open(setup_cfg, "r") as f: parser.readfp(f) VCS = parser.get("versioneer", "VCS") # mandatory def get(parser, name): if parser.has_option("versioneer", name): return parser.get("versioneer", name) return None cfg = VersioneerConfig() cfg.VCS = VCS cfg.style = get(parser, "style") or "" cfg.versionfile_source = get(parser, "versionfile_source") cfg.versionfile_build = get(parser, "versionfile_build") cfg.tag_prefix = get(parser, "tag_prefix") if cfg.tag_prefix in ("''", '""'): cfg.tag_prefix = "" cfg.parentdir_prefix = get(parser, "parentdir_prefix") cfg.verbose = get(parser, "verbose") return cfg
Example #26
Source File: versioneer.py From matchpy with MIT License | 5 votes |
def get_config_from_root(root): """Read the project setup.cfg file to determine Versioneer config.""" # This might raise EnvironmentError (if setup.cfg is missing), or # configparser.NoSectionError (if it lacks a [versioneer] section), or # configparser.NoOptionError (if it lacks "VCS="). See the docstring at # the top of versioneer.py for instructions on writing your setup.cfg . setup_cfg = os.path.join(root, "setup.cfg") parser = configparser.SafeConfigParser() with open(setup_cfg, "r") as f: parser.readfp(f) VCS = parser.get("versioneer", "VCS") # mandatory def get(parser, name): if parser.has_option("versioneer", name): return parser.get("versioneer", name) return None cfg = VersioneerConfig() cfg.VCS = VCS cfg.style = get(parser, "style") or "" cfg.versionfile_source = get(parser, "versionfile_source") cfg.versionfile_build = get(parser, "versionfile_build") cfg.tag_prefix = get(parser, "tag_prefix") if cfg.tag_prefix in ("''", '""'): cfg.tag_prefix = "" cfg.parentdir_prefix = get(parser, "parentdir_prefix") cfg.verbose = get(parser, "verbose") return cfg
Example #27
Source File: config.py From fusesoc with BSD 2-Clause "Simplified" License | 5 votes |
def add_library(self, library): from fusesoc.provider import get_provider if not hasattr(self, "_path"): raise RuntimeError("No FuseSoC config file found - can't add library") section_name = "library." + library.name config = CP() config.read(self._path) if section_name in config.sections(): logger.warning( "Not adding library. {} already exists in configuration file".format( library.name ) ) return config.add_section(section_name) config.set(section_name, "location", library.location) if library.sync_type: config.set(section_name, "sync-uri", library.sync_uri) config.set(section_name, "sync-type", library.sync_type) _auto_sync = "true" if library.auto_sync else "false" config.set(section_name, "auto-sync", _auto_sync) try: provider = get_provider(library.sync_type) except ImportError as e: raise RuntimeError("Invalid sync-type '{}'".format(library["sync-type"])) provider.init_library(library) with open(self._path, "w") as conf_file: config.write(conf_file)
Example #28
Source File: data.py From me-ica with GNU Lesser General Public License v2.1 | 5 votes |
def __init__(self, base_path, config_filename=None): ''' Initialize versioned datasource We assume that there is a configuration file with version information in datasource directory tree. The configuration file contains an entry like:: [DEFAULT] version = 0.3 The version should have at least a major and a minor version number in the form above. Parameters ---------- base_path : str path to prepend to all relative paths config_filaname : None or str relative path to configuration file containing version ''' Datasource.__init__(self, base_path) if config_filename is None: config_filename = 'config.ini' self.config = ConfigParser.SafeConfigParser() cfg_file = self.get_filename(config_filename) readfiles = self.config.read(cfg_file) if not readfiles: raise DataError('Could not read config file %s' % cfg_file) try: self.version = self.config.get('DEFAULT', 'version') except ConfigParser.Error: raise DataError('Could not get version from %s' % cfg_file) version_parts = self.version.split('.') self.major_version = int(version_parts[0]) self.minor_version = int(version_parts[1]) self.version_no = float('%d.%d' % (self.major_version, self.minor_version))
Example #29
Source File: versioneer.py From custom_inherit with MIT License | 5 votes |
def get_config_from_root(root): """Read the project setup.cfg file to determine Versioneer config.""" # This might raise EnvironmentError (if setup.cfg is missing), or # configparser.NoSectionError (if it lacks a [versioneer] section), or # configparser.NoOptionError (if it lacks "VCS="). See the docstring at # the top of versioneer.py for instructions on writing your setup.cfg . setup_cfg = os.path.join(root, "setup.cfg") parser = configparser.SafeConfigParser() with open(setup_cfg, "r") as f: parser.readfp(f) VCS = parser.get("versioneer", "VCS") # mandatory def get(parser, name): if parser.has_option("versioneer", name): return parser.get("versioneer", name) return None cfg = VersioneerConfig() cfg.VCS = VCS cfg.style = get(parser, "style") or "" cfg.versionfile_source = get(parser, "versionfile_source") cfg.versionfile_build = get(parser, "versionfile_build") cfg.tag_prefix = get(parser, "tag_prefix") if cfg.tag_prefix in ("''", '""'): cfg.tag_prefix = "" cfg.parentdir_prefix = get(parser, "parentdir_prefix") cfg.verbose = get(parser, "verbose") return cfg
Example #30
Source File: versioneer.py From OpenChem with MIT License | 5 votes |
def get_config_from_root(root): """Read the project setup.cfg file to determine Versioneer config.""" # This might raise EnvironmentError (if setup.cfg is missing), or # configparser.NoSectionError (if it lacks a [versioneer] section), or # configparser.NoOptionError (if it lacks "VCS="). See the docstring at # the top of versioneer.py for instructions on writing your setup.cfg . setup_cfg = os.path.join(root, "setup.cfg") parser = configparser.SafeConfigParser() with open(setup_cfg, "r") as f: parser.readfp(f) VCS = parser.get("versioneer", "VCS") # mandatory def get(parser, name): if parser.has_option("versioneer", name): return parser.get("versioneer", name) return None cfg = VersioneerConfig() cfg.VCS = VCS cfg.style = get(parser, "style") or "" cfg.versionfile_source = get(parser, "versionfile_source") cfg.versionfile_build = get(parser, "versionfile_build") cfg.tag_prefix = get(parser, "tag_prefix") if cfg.tag_prefix in ("''", '""'): cfg.tag_prefix = "" cfg.parentdir_prefix = get(parser, "parentdir_prefix") cfg.verbose = get(parser, "verbose") return cfg