How to use the configparser.RawConfigParser function in configparser

To help you get started, we’ve selected a few configparser examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github olivierhagolle / Start_maja / test / View on Github external
def modify_folders_file(root, new_file, **kwargs):
    Modify the template test_folders file with the given arguments
    :param root: The path to the existing template file
    :param new_file: The new file path
    :param kwargs: The arguments to modify inside the file
    :return: The full path to the new file
        import configparser as cfg
    except ImportError:
        import ConfigParser as cfg

    assert os.path.isfile(root)
    cfg_parser = cfg.RawConfigParser()
    for arg in kwargs:
        cfg_parser.set("PATH", arg, kwargs[arg])

    with open(new_file, 'w') as f:
    return new_file
github muckamuck / stackility / stackility / View on Github external
def read_config_info(ini_file):
    Read the INI file

        ini_file - path to the file

        A dictionary of stuff from the INI file

        1 - if problems are encountered
        config = RawConfigParser()
        config.optionxform = lambda option: option
        the_stuff = {}
        for section in config.sections():
            the_stuff[section] = {}
            for option in config.options(section):
                the_stuff[section][option] = config.get(section, option)

        return the_stuff
    except Exception as wtf:
        logging.error('Exception caught in read_config_info(): {}'.format(wtf))
        return sys.exit(1)
github mozilla / version-control-tools / hgserver / pash / View on Github external
def get_user_repo_config(repo_dir):
    """Obtain a ConfigParser for a repository.

    If the hgrc file doesn't exist, it will be created automatically.
    user = os.getenv('USER')
    path = '%s/.hg/hgrc' % repo_dir
    if not os.path.isfile(path):
        run_command('touch %s' % path)
        run_command('chown %s:scm_level_1 %s' % (user, path))

    config = RawConfigParser()
    if not
        sys.stderr.write('Could not read the hgrc file for this repo\n')
        sys.stderr.write('Please file a Developer Services :: bug\n')

    return path, config
github rafaelcapucho / scrapy-eagle / scrapy_eagle / dashboard / View on Github external
def setup_configuration(config_file=None):

    global _config

    _config = configparser.RawConfigParser()

    globals()['_config'] = _config

    return _config
github plastex / plastex / plasTeX / View on Github external
def loadINIPackage(self, inifile):
        Load INI file containing macro definitions

        inifile -- filename of INI formatted file

        ini = configparser.RawConfigParser()
        if not isinstance(inifile, (list, tuple)):
            inifile = [inifile]
        for f in inifile:
            macros = {}
            for section in ini.sections():
                try: baseclass = self[section]
                except KeyError:
                    log.warning('Could not find macro %s' % section)
                for name in ini.options(section):
                    value = ini.get(section, name)
                    m = re.match(r'^str\(\s*(?:(\'|\")(?P.+)(?:\1)|(?P\d+))\s*\)$', value)
                    if m:
                        data = m.groupdict()
                        if data['number'] is not None:
github HASecuritySolutions / VulnWhisperer / vulnwhisp / base / View on Github external
def __init__(self, config_in=None):
        self.config_in = config_in
        self.config = cp.RawConfigParser()
        self.logger = logging.getLogger('vwConfig')
github kupferlauncher / kupfer / kupfer / core / View on Github external
def _read_config(self, read_config=True):
        Read cascading config files
        default -> then config
        (in all XDG_CONFIG_DIRS)
        parser = configparser.RawConfigParser()

        def fill_parser(parser, defaults):
            for secname, section in defaults.items():
                if not parser.has_section(secname):
                for key, default in section.items():
                    if isinstance(default, (tuple, list)):
                        default = self.sep.join(default)
                    elif isinstance(default, int):
                        default = str(default)
                    parser.set(secname, key, default)

        # Set up defaults
        confmap = copy.deepcopy(self.defaults)
        fill_parser(parser, confmap)
github freeipa / freeipa / ipaserver / install / View on Github external
def get_immutable_keys(cls):
        """Get set of immutable keys

        Immutable keys are calculated from 'ipaca_default' config file
        and known keys that are defined in code.
        if cls._immutable_keys is None:
            immutable = set()
            cfg = RawConfigParser()
            with open(cls.ipaca_default) as f:
            for section in cls.subsystems:
                for k, _v in cfg.items(section, raw=True):
                    if k.startswith('pki_'):
            cls._immutable_keys = frozenset(immutable)
        return cls._immutable_keys
github Eelviny / nxt-python / nxt / View on Github external
def make_config(confpath=None):
    conf = configparser.RawConfigParser()
    if not confpath: confpath = os.path.expanduser('~/.nxt-python')
    print("Welcome to the nxt-python config file generator!")
    print("This function creates an example file which find_one_brick uses to find a brick.")
        if os.path.exists(confpath): input("File already exists at %s. Press Enter to overwrite or Ctrl+C to abort." % confpath)
    except KeyboardInterrupt:
        print("Not writing file.")
    conf.set('Brick', 'name', 'MyNXT')
    conf.set('Brick', 'host', '54:32:59:92:F9:39')
    conf.set('Brick', 'strict', 0)
    conf.set('Brick', 'method', 'usb=True, bluetooth=False')
    conf.write(open(confpath, 'w'))
    print("The file has been written at %s" % confpath)
    print("The file contains less-than-sane default values to get you started.")
github anhstudios / swganh / data / sql / View on Github external
def rebuildCfg(oldCfg=None):
        Rebuilds the configuration file from user inputs.
        Optional Parameters:
            oldCfg - if defined values will be inserted into this dict instead of returned.
            the new configuration dictionary.
    cfgParse = RawConfigParser()
    cfgParse['DEFAULT'] = defaults

    cfg = {}

    #Get user inputs
    cfg['username'] = input(I18N['USERNAME_PROMPT_MSG'])
    cfg['password'] = input(I18N['PASSWORD_PROMPT_MSG'])
    cfg['host'] = input(I18N['HOST_PROMPT_MSG'])
    cfg['pause'] = input(I18N['PAUSE_PROMPT_MSG'])
    cfg['clear'] = input(I18N['CLEAR_PROMPT_MSG'])

    #Set the default if the user chose to input nothing
    for k,v in defaults.items():
        if cfg[k] == '':
            cfg[k] = v