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: versioneer.py    From wg-gesucht-crawler-cli with MIT License 6 votes vote down vote up
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 #2
Source File: getmessages_mariadb.py    From InsightAgent with Apache License 2.0 6 votes vote down vote up
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 #3
Source File: insightagent-boilerplate.py    From InsightAgent with Apache License 2.0 6 votes vote down vote up
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: versioneer.py    From recordlinkage with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #5
Source File: versioneer.py    From landmarkerio-server with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
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 #6
Source File: getmessages_file_replay.py    From InsightAgent with Apache License 2.0 6 votes vote down vote up
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 #7
Source File: getlogs_servicenow.py    From InsightAgent with Apache License 2.0 6 votes vote down vote up
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 #8
Source File: index.py    From psychsim with MIT License 6 votes vote down vote up
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 #9
Source File: config.py    From rucio with Apache License 2.0 6 votes vote down vote up
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 #10
Source File: setup.py    From PyOptiX with MIT License 6 votes vote down vote up
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 #11
Source File: session.py    From odoorpc with GNU Lesser General Public License v3.0 6 votes vote down vote up
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 #12
Source File: configparserwrapper.py    From CAMISIM with Apache License 2.0 6 votes vote down vote up
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 #13
Source File: validator.py    From ovirt-ansible-disaster-recovery with Apache License 2.0 5 votes vote down vote up
def _set_dr_conf_variables(self, conf_file):
        _SECTION = 'validate_vars'
        _VAR_FILE = 'var_file'

        # Get default location of the yml var file.
        settings = SafeConfigParser()
        settings.read(conf_file)
        if _SECTION not in settings.sections():
            settings.add_section(_SECTION)
        if not settings.has_option(_SECTION, _VAR_FILE):
            settings.set(_SECTION, _VAR_FILE, '')
        var_file = settings.get(_SECTION, _VAR_FILE,
                                vars=DefaultOption(settings,
                                                   _SECTION,
                                                   site=self.def_var_file))

        # If no default location exists, get the location from the user.
        while not var_file:
            var_file = input("%s%sVar file is not initialized. "
                             "Please provide the location of the var file "
                             "(%s):%s " % (WARN,
                                           PREFIX,
                                           self.def_var_file,
                                           END) or self.def_var_file)

        self.var_file = var_file 
Example #14
Source File: validator.py    From ovirt-ansible-disaster-recovery with Apache License 2.0 5 votes vote down vote up
def _set_dr_conf_variables(self, conf_file):
        _SECTION = 'validate_vars'
        _VAR_FILE = 'var_file'

        # Get default location of the yml var file.
        settings = SafeConfigParser()
        settings.read(conf_file)
        if _SECTION not in settings.sections():
            settings.add_section(_SECTION)
        if not settings.has_option(_SECTION, _VAR_FILE):
            settings.set(_SECTION, _VAR_FILE, '')
        var_file = settings.get(_SECTION, _VAR_FILE,
                                vars=DefaultOption(settings,
                                                   _SECTION,
                                                   site=self.def_var_file))

        # If no default location exists, get the location from the user.
        while not var_file:
            var_file = input("%s%sVar file is not initialized. "
                             "Please provide the location of the var file "
                             "(%s):%s " % (WARN,
                                           PREFIX,
                                           self.def_var_file,
                                           END) or self.def_var_file)

        self.var_file = var_file 
Example #15
Source File: validator.py    From ovirt-ansible-disaster-recovery with Apache License 2.0 5 votes vote down vote up
def _set_dr_conf_variables(self, conf_file):
        _SECTION = 'validate_vars'
        _VAR_FILE = 'var_file'

        # Get default location of the yml var file.
        settings = SafeConfigParser()
        settings.read(conf_file)
        if _SECTION not in settings.sections():
            settings.add_section(_SECTION)
        if not settings.has_option(_SECTION, _VAR_FILE):
            settings.set(_SECTION, _VAR_FILE, '')
        var_file = settings.get(_SECTION, _VAR_FILE,
                                vars=DefaultOption(settings,
                                                   _SECTION,
                                                   site=self.def_var_file))

        # If no default location exists, get the location from the user.
        while not var_file:
            var_file = input("%s%sVar file is not initialized. "
                             "Please provide the location of the var file "
                             "(%s):%s " % (WARN,
                                           PREFIX,
                                           self.def_var_file,
                                           END) or self.def_var_file)

        self.var_file = var_file 
Example #16
Source File: validator.py    From ovirt-ansible-disaster-recovery with Apache License 2.0 5 votes vote down vote up
def _set_dr_conf_variables(self, conf_file):
        _SECTION = 'validate_vars'
        _VAR_FILE = 'var_file'

        # Get default location of the yml var file.
        settings = SafeConfigParser()
        settings.read(conf_file)
        if _SECTION not in settings.sections():
            settings.add_section(_SECTION)
        if not settings.has_option(_SECTION, _VAR_FILE):
            settings.set(_SECTION, _VAR_FILE, '')
        var_file = settings.get(_SECTION, _VAR_FILE,
                                vars=DefaultOption(settings,
                                                   _SECTION,
                                                   site=self.def_var_file))

        # If no default location exists, get the location from the user.
        while not var_file:
            var_file = input("%s%sVar file is not initialized. "
                             "Please provide the location of the var file "
                             "(%s):%s " % (WARN,
                                           PREFIX,
                                           self.def_var_file,
                                           END) or self.def_var_file)

        self.var_file = var_file 
Example #17
Source File: validator.py    From ovirt-ansible-disaster-recovery with Apache License 2.0 5 votes vote down vote up
def _set_dr_conf_variables(self, conf_file):
        _SECTION = 'validate_vars'
        _VAR_FILE = 'var_file'

        # Get default location of the yml var file.
        settings = SafeConfigParser()
        settings.read(conf_file)
        if _SECTION not in settings.sections():
            settings.add_section(_SECTION)
        if not settings.has_option(_SECTION, _VAR_FILE):
            settings.set(_SECTION, _VAR_FILE, '')
        var_file = settings.get(_SECTION, _VAR_FILE,
                                vars=DefaultOption(settings,
                                                   _SECTION,
                                                   site=self.def_var_file))

        # If no default location exists, get the location from the user.
        while not var_file:
            var_file = input("%s%sVar file is not initialized. "
                             "Please provide the location of the var file "
                             "(%s):%s " % (WARN,
                                           PREFIX,
                                           self.def_var_file,
                                           END) or self.def_var_file)

        self.var_file = var_file 
Example #18
Source File: validator.py    From ovirt-ansible-disaster-recovery with Apache License 2.0 5 votes vote down vote up
def _set_dr_conf_variables(self, conf_file):
        _SECTION = 'validate_vars'
        _VAR_FILE = 'var_file'

        # Get default location of the yml var file.
        settings = SafeConfigParser()
        settings.read(conf_file)
        if _SECTION not in settings.sections():
            settings.add_section(_SECTION)
        if not settings.has_option(_SECTION, _VAR_FILE):
            settings.set(_SECTION, _VAR_FILE, '')
        var_file = settings.get(_SECTION, _VAR_FILE,
                                vars=DefaultOption(settings,
                                                   _SECTION,
                                                   site=self.def_var_file))

        # If no default location exists, get the location from the user.
        while not var_file:
            var_file = input("%s%sVar file is not initialized. "
                             "Please provide the location of the var file "
                             "(%s):%s " % (WARN,
                                           PREFIX,
                                           self.def_var_file,
                                           END) or self.def_var_file)

        self.var_file = var_file 
Example #19
Source File: validator.py    From ovirt-ansible-disaster-recovery with Apache License 2.0 5 votes vote down vote up
def _set_dr_conf_variables(self, conf_file):
        _SECTION = 'validate_vars'
        _VAR_FILE = 'var_file'

        # Get default location of the yml var file.
        settings = SafeConfigParser()
        settings.read(conf_file)
        if _SECTION not in settings.sections():
            settings.add_section(_SECTION)
        if not settings.has_option(_SECTION, _VAR_FILE):
            settings.set(_SECTION, _VAR_FILE, '')
        var_file = settings.get(_SECTION, _VAR_FILE,
                                vars=DefaultOption(settings,
                                                   _SECTION,
                                                   site=self.def_var_file))

        # If no default location exists, get the location from the user.
        while not var_file:
            var_file = input("%s%sVar file is not initialized. "
                             "Please provide the location of the var file "
                             "(%s):%s " % (WARN,
                                           PREFIX,
                                           self.def_var_file,
                                           END) or self.def_var_file)

        self.var_file = var_file 
Example #20
Source File: validator.py    From ovirt-ansible-disaster-recovery with Apache License 2.0 5 votes vote down vote up
def _set_dr_conf_variables(self, conf_file):
        _SECTION = 'validate_vars'
        _VAR_FILE = 'var_file'

        # Get default location of the yml var file.
        settings = SafeConfigParser()
        settings.read(conf_file)
        if _SECTION not in settings.sections():
            settings.add_section(_SECTION)
        if not settings.has_option(_SECTION, _VAR_FILE):
            settings.set(_SECTION, _VAR_FILE, '')
        var_file = settings.get(_SECTION, _VAR_FILE,
                                vars=DefaultOption(settings,
                                                   _SECTION,
                                                   site=self.def_var_file))

        # If no default location exists, get the location from the user.
        while not var_file:
            var_file = input("%s%sVar file is not initialized. "
                             "Please provide the location of the var file "
                             "(%s):%s " % (WARN,
                                           PREFIX,
                                           self.def_var_file,
                                           END) or self.def_var_file)

        self.var_file = var_file 
Example #21
Source File: validator.py    From ovirt-ansible-disaster-recovery with Apache License 2.0 5 votes vote down vote up
def _set_dr_conf_variables(self, conf_file):
        _SECTION = 'validate_vars'
        _VAR_FILE = 'var_file'

        # Get default location of the yml var file.
        settings = SafeConfigParser()
        settings.read(conf_file)
        if _SECTION not in settings.sections():
            settings.add_section(_SECTION)
        if not settings.has_option(_SECTION, _VAR_FILE):
            settings.set(_SECTION, _VAR_FILE, '')
        var_file = settings.get(_SECTION, _VAR_FILE,
                                vars=DefaultOption(settings,
                                                   _SECTION,
                                                   site=self.def_var_file))

        # If no default location exists, get the location from the user.
        while not var_file:
            var_file = input("%s%sVar file is not initialized. "
                             "Please provide the location of the var file "
                             "(%s):%s " % (WARN,
                                           PREFIX,
                                           self.def_var_file,
                                           END) or self.def_var_file)

        self.var_file = var_file 
Example #22
Source File: validator.py    From ovirt-ansible-disaster-recovery with Apache License 2.0 5 votes vote down vote up
def _set_dr_conf_variables(self, conf_file):
        _SECTION = 'validate_vars'
        _VAR_FILE = 'var_file'

        # Get default location of the yml var file.
        settings = SafeConfigParser()
        settings.read(conf_file)
        if _SECTION not in settings.sections():
            settings.add_section(_SECTION)
        if not settings.has_option(_SECTION, _VAR_FILE):
            settings.set(_SECTION, _VAR_FILE, '')
        var_file = settings.get(_SECTION, _VAR_FILE,
                                vars=DefaultOption(settings,
                                                   _SECTION,
                                                   site=self.def_var_file))

        # If no default location exists, get the location from the user.
        while not var_file:
            var_file = input("%s%sVar file is not initialized. "
                             "Please provide the location of the var file "
                             "(%s):%s " % (WARN,
                                           PREFIX,
                                           self.def_var_file,
                                           END) or self.def_var_file)

        self.var_file = var_file 
Example #23
Source File: validator.py    From ovirt-ansible-disaster-recovery with Apache License 2.0 5 votes vote down vote up
def _set_dr_conf_variables(self, conf_file):
        _SECTION = 'validate_vars'
        _VAR_FILE = 'var_file'

        # Get default location of the yml var file.
        settings = SafeConfigParser()
        settings.read(conf_file)
        if _SECTION not in settings.sections():
            settings.add_section(_SECTION)
        if not settings.has_option(_SECTION, _VAR_FILE):
            settings.set(_SECTION, _VAR_FILE, '')
        var_file = settings.get(_SECTION, _VAR_FILE,
                                vars=DefaultOption(settings,
                                                   _SECTION,
                                                   site=self.def_var_file))

        # If no default location exists, get the location from the user.
        while not var_file:
            var_file = input("%s%sVar file is not initialized. "
                             "Please provide the location of the var file "
                             "(%s):%s " % (WARN,
                                           PREFIX,
                                           self.def_var_file,
                                           END) or self.def_var_file)

        self.var_file = var_file 
Example #24
Source File: validator.py    From ovirt-ansible-disaster-recovery with Apache License 2.0 5 votes vote down vote up
def _set_dr_conf_variables(self, conf_file):
        _SECTION = 'validate_vars'
        _VAR_FILE = 'var_file'

        # Get default location of the yml var file.
        settings = SafeConfigParser()
        settings.read(conf_file)
        if _SECTION not in settings.sections():
            settings.add_section(_SECTION)
        if not settings.has_option(_SECTION, _VAR_FILE):
            settings.set(_SECTION, _VAR_FILE, '')
        var_file = settings.get(_SECTION, _VAR_FILE,
                                vars=DefaultOption(settings,
                                                   _SECTION,
                                                   site=self.def_var_file))

        # If no default location exists, get the location from the user.
        while not var_file:
            var_file = input("%s%sVar file is not initialized. "
                             "Please provide the location of the var file "
                             "(%s):%s " % (WARN,
                                           PREFIX,
                                           self.def_var_file,
                                           END) or self.def_var_file)

        self.var_file = var_file 
Example #25
Source File: validator.py    From ovirt-ansible-disaster-recovery with Apache License 2.0 5 votes vote down vote up
def _set_dr_conf_variables(self, conf_file):
        _SECTION = 'validate_vars'
        _VAR_FILE = 'var_file'

        # Get default location of the yml var file.
        settings = SafeConfigParser()
        settings.read(conf_file)
        if _SECTION not in settings.sections():
            settings.add_section(_SECTION)
        if not settings.has_option(_SECTION, _VAR_FILE):
            settings.set(_SECTION, _VAR_FILE, '')
        var_file = settings.get(_SECTION, _VAR_FILE,
                                vars=DefaultOption(settings,
                                                   _SECTION,
                                                   site=self.def_var_file))

        # If no default location exists, get the location from the user.
        while not var_file:
            var_file = input("%s%sVar file is not initialized. "
                             "Please provide the location of the var file "
                             "(%s):%s " % (WARN,
                                           PREFIX,
                                           self.def_var_file,
                                           END) or self.def_var_file)

        self.var_file = var_file 
Example #26
Source File: versioneer.py    From pygraphistry with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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: versioneer.py    From pybids with MIT License 5 votes vote down vote up
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 #28
Source File: versioneer.py    From tedana with GNU Lesser General Public License v2.1 5 votes vote down vote up
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 #29
Source File: versioneer.py    From vpython-jupyter with MIT License 5 votes vote down vote up
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 filesystem_spec with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
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