Python six.moves.configparser.RawConfigParser() Examples

The following are 30 code examples of six.moves.configparser.RawConfigParser(). 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 six.moves.configparser , or try the search function .
Example #1
Source File: settings.py    From rtv with MIT License 6 votes vote down vote up
def _load_configuration():
    """Attempt to load settings from various praw.ini files."""
    config = configparser.RawConfigParser()
    module_dir = os.path.dirname(sys.modules[__name__].__file__)
    if 'APPDATA' in os.environ:  # Windows
        os_config_path = os.environ['APPDATA']
    elif 'XDG_CONFIG_HOME' in os.environ:  # Modern Linux
        os_config_path = os.environ['XDG_CONFIG_HOME']
    elif 'HOME' in os.environ:  # Legacy Linux
        os_config_path = os.path.join(os.environ['HOME'], '.config')
    else:
        os_config_path = None
    locations = [os.path.join(module_dir, 'praw.ini'), 'praw.ini']
    if os_config_path is not None:
        locations.insert(1, os.path.join(os_config_path, 'praw.ini'))
    if not config.read(locations):
        raise Exception('Could not find config file in any of: {0}'
                        .format(locations))
    return config 
Example #2
Source File: test_config.py    From DLRN with Apache License 2.0 6 votes vote down vote up
def test_detect_dirs(self):
        self.config = configparser.RawConfigParser()
        self.config.read("samples/projects.ini.detect")
        config = ConfigOptions(self.config)
        self.assertEqual(
            config.datadir,
            os.path.realpath(os.path.join(
                             os.path.dirname(os.path.abspath(__file__)),
                             "../../data")))
        self.assertEqual(
            config.templatedir,
            os.path.realpath(os.path.join(
                             os.path.dirname(os.path.abspath(__file__)),
                             "../templates")))
        self.assertEqual(
            config.scriptsdir,
            os.path.realpath(os.path.join(
                             os.path.dirname(os.path.abspath(__file__)),
                             "../../scripts"))) 
Example #3
Source File: test_repositories.py    From DLRN with Apache License 2.0 6 votes vote down vote up
def test_clone_fallback_var(self, sh_mock):
        config = configparser.RawConfigParser()
        config.read("projects.ini")
        config.set('DEFAULT', 'fallback_to_master', '1')
        config.set('DEFAULT', 'nonfallback_branches', '^foo-')
        self.config = ConfigOptions(config)
        with mock.patch.object(sh.Command, '__call__') as new_mock:
            new_mock.side_effect = _aux_sh
            result = repositories.refreshrepo('url', 'path', branch='bar')
            self.assertEqual(result, ['master', 'None'])
            expected = [mock.call('url', 'path'),
                        mock.call('origin'),
                        mock.call('-f', 'bar'),
                        mock.call('master'),
                        mock.call('--hard', 'origin/master'),
                        mock.call('--pretty=format:%H %ct', '-1', '.')]
            self.assertEqual(new_mock.call_args_list, expected) 
Example #4
Source File: test_repositories.py    From DLRN with Apache License 2.0 6 votes vote down vote up
def test_clone_no_fallback(self, sh_mock):
        config = configparser.RawConfigParser()
        config.read("projects.ini")
        config.set('DEFAULT', 'fallback_to_master', '0')
        self.config = ConfigOptions(config)
        # We need to redefine the mock object again, to use a side effect
        # that will fail in the git checkout call. A bit convoluted, but
        # it works
        with mock.patch.object(sh.Command, '__call__') as new_mock:
            new_mock.side_effect = _aux_sh
            self.assertRaises(sh.ErrorReturnCode_1, repositories.refreshrepo,
                              'url', 'path', branch='branch')
            expected = [mock.call('url', 'path'),
                        mock.call('origin'),
                        mock.call('-f', 'branch')]
            self.assertEqual(new_mock.call_args_list, expected) 
Example #5
Source File: test_build.py    From DLRN with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(TestBuild, self).setUp()
        self.configfile = configparser.RawConfigParser()
        self.configfile.read("projects.ini")
        self.configfile.set('DEFAULT', 'datadir', tempfile.mkdtemp())
        self.configfile.set('DEFAULT', 'scriptsdir', tempfile.mkdtemp())
        self.configfile.set('DEFAULT', 'baseurl', "file://%s" %
                            self.configfile.get('DEFAULT', 'datadir'))
        self.config = ConfigOptions(self.configfile)
        shutil.copyfile(os.path.join("scripts", "centos.cfg"),
                        os.path.join(self.config.scriptsdir, "centos.cfg"))
        with open(os.path.join(self.config.datadir,
                  "delorean-deps.repo"), "w") as fp:
            fp.write("[test]\nname=test\nenabled=0\n")
        self.db_fd, filepath = tempfile.mkstemp()
        self.session = db.getSession("sqlite:///%s" % filepath)
        utils.loadYAML(self.session, './dlrn/tests/samples/commits_1.yaml') 
Example #6
Source File: test_shell.py    From DLRN with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(TestProcessBuildResult, self).setUp()
        config = configparser.RawConfigParser()
        config.read("projects.ini")
        config.set('DEFAULT', 'datadir', tempfile.mkdtemp())
        config.set('DEFAULT', 'scriptsdir', tempfile.mkdtemp())
        config.set('DEFAULT', 'baseurl', "file://%s" % config.get('DEFAULT',
                                                                  'datadir'))
        self.config = ConfigOptions(config)
        self.commit = db.Commit(dt_commit=123, project_name='foo', type="rpm",
                                commit_hash='1c67b1ab8c6fe273d4e175a14f0df5'
                                            'd3cbbd0edf',
                                repo_dir='/home/dlrn/data/foo',
                                distro_hash='c31d1b18eb5ab5aed6721fc4fad06c9'
                                            'bd242490f',
                                dt_distro=123,
                                distgit_dir='/home/dlrn/data/foo_distro',
                                commit_branch='master', dt_build=1441245153)
        self.db_fd, filepath = tempfile.mkstemp()
        self.session = mocked_session("sqlite:///%s" % filepath)
        self.packages = [{'upstream': 'https://github.com/openstack/foo',
                          'name': 'foo', 'maintainers': 'test@test.com'},
                         {'upstream': 'https://github.com/openstack/test',
                          'name': 'test', 'maintainers': 'test@test.com'}] 
Example #7
Source File: test_notifications.py    From DLRN with Apache License 2.0 6 votes vote down vote up
def setUp(self):
        super(TestNotifications, self).setUp()
        config = configparser.RawConfigParser()
        config.read("projects.ini")
        config.set('DEFAULT', 'datadir', tempfile.mkdtemp())
        config.set('DEFAULT', 'scriptsdir', tempfile.mkdtemp())
        config.set('DEFAULT', 'baseurl', "file://%s" % config.get('DEFAULT',
                                                                  'datadir'))

        self.config = ConfigOptions(config)
        self.commit = db.Commit(dt_commit=123, project_name='foo',
                                commit_hash='1c67b1ab8c6fe273d4e175a14f0df5'
                                            'd3cbbd0edf',
                                repo_dir='/home/dlrn/data/foo',
                                distro_hash='c31d1b18eb5ab5aed6721fc4fad06c9'
                                            'bd242490f',
                                dt_distro=123,
                                distgit_dir='/home/dlrn/data/foo_distro',
                                commit_branch='master', dt_build=1441245153)
        self.packages = [{'upstream': 'https://github.com/openstack/foo',
                          'name': 'foo', 'maintainers': ['test@test.com'],
                          'master-distgit':
                          'https://github.com/rdo-packages/foo-distgit.git'}] 
Example #8
Source File: settings.py    From ttrv with MIT License 6 votes vote down vote up
def _load_configuration():
    """Attempt to load settings from various praw.ini files."""
    config = configparser.RawConfigParser()
    module_dir = os.path.dirname(sys.modules[__name__].__file__)
    if 'APPDATA' in os.environ:  # Windows
        os_config_path = os.environ['APPDATA']
    elif 'XDG_CONFIG_HOME' in os.environ:  # Modern Linux
        os_config_path = os.environ['XDG_CONFIG_HOME']
    elif 'HOME' in os.environ:  # Legacy Linux
        os_config_path = os.path.join(os.environ['HOME'], '.config')
    else:
        os_config_path = None
    locations = [os.path.join(module_dir, 'praw.ini'), 'praw.ini']
    if os_config_path is not None:
        locations.insert(1, os.path.join(os_config_path, 'praw.ini'))
    if not config.read(locations):
        raise Exception('Could not find config file in any of: {0}'
                        .format(locations))
    return config 
Example #9
Source File: configuration.py    From PCR-GLOBWB_model with GNU General Public License v3.0 6 votes vote down vote up
def parse_configuration_file(self, modelFileName):

        config = ConfigParser()
        config.optionxform = str
        config.read(modelFileName)

        # all sections provided in the configuration/ini file
        self.allSections = config.sections()

        # read all sections 
        for sec in self.allSections:
            vars(self)[sec] = {}                               # example: to instantiate self.globalOptions 
            options = config.options(sec)                      # example: logFileDir
            for opt in options:
                val = config.get(sec, opt)                     # value defined in every option 
                self.__getattribute__(sec)[opt] = val          # example: self.globalOptions['logFileDir'] = val 
Example #10
Source File: configuration_for_modflow.py    From PCR-GLOBWB_model with GNU General Public License v3.0 6 votes vote down vote up
def parse_configuration_file(self, modelFileName):

        config = ConfigParser()
        config.optionxform = str
        config.read(modelFileName)

        # all sections provided in the configuration/ini file
        self.allSections  = config.sections()
        
        # read all sections 
        for sec in self.allSections:
            vars(self)[sec] = {}                               # example: to instantiate self.globalOptions 
            options = config.options(sec)                      # example: logFileDir
            for opt in options:
                val = config.get(sec, opt)                     # value defined in every option 
                self.__getattribute__(sec)[opt] = val          # example: self.globalOptions['logFileDir'] = val 
Example #11
Source File: storlet_handler.py    From storlets with Apache License 2.0 6 votes vote down vote up
def filter_factory(global_conf, **local_conf):
    conf = global_conf.copy()
    conf.update(local_conf)

    module_name = conf.get('storlet_gateway_module', 'stub')
    gateway_class = load_gateway(module_name)
    conf['gateway_module'] = gateway_class

    configParser = ConfigParser.RawConfigParser()
    configParser.read(conf.get('storlet_gateway_conf',
                               '/etc/swift/storlet_stub_gateway.conf'))
    gateway_conf = dict(configParser.items("DEFAULT"))

    # TODO(eranr): Add supported storlets languages and
    #  supported storlet API version
    containers = get_container_names(conf)
    swift_info = {'storlet_container': containers['storlet'],
                  'storlet_dependency': containers['dependency'],
                  'storlet_gateway_class': gateway_class.__name__}
    register_swift_info('storlet_handler', False, **swift_info)

    def storlet_handler_filter(app):
        return StorletHandlerMiddleware(app, conf, gateway_conf)
    return storlet_handler_filter 
Example #12
Source File: ec2.py    From doodad with GNU General Public License v3.0 6 votes vote down vote up
def __init__(self, aws_key=None, aws_secret=None, 
            from_env=False, 
            from_config=False,
            config_filename='~/.aws/credentials',
            env_secret_key='AWS_ACCESS_SECRET',
            env_key='AWS_ACCESS_KEY'):
        self.key = aws_key
        self.secret = aws_secret
        self.from_env=from_env
        if from_env:
            self.key = os.environ.get(env_key)
            self.secret = os.environ.get(env_secret_key)
        if from_config:
            with open(os.path.expanduser(config_filename)) as f:
                sample_config = f.read()
            config = configparser.RawConfigParser(allow_no_value=True)
            config.read_string(sample_config)
            self.key = config.get('default', 'aws_access_key_id')
            self.secret = config.get('default', 'aws_secret_access_key') 
Example #13
Source File: validators.py    From infrared with Apache License 2.0 6 votes vote down vote up
def validate_from_file(cls, yaml_file=None):
        config = configparser.RawConfigParser()
        config.read(yaml_file)
        config_dict = cls._convert_config_to_dict(config)

        for section, option_details in cls.ANSIBLE_CONFIG_OPTIONS.items():
            for opt_name, opt_params in option_details.items():
                try:
                    config_value = config_dict[section][opt_name]
                    cls._validate_config_option(yaml_file,
                                                opt_name,
                                                opt_params['type'],
                                                opt_params['comparison'],
                                                opt_params['expected_value'],
                                                config_value,
                                                opt_params['critical'])
                except KeyError:
                    cls._handle_missing_value(yaml_file, section, opt_name,
                                              opt_params['expected_value'],
                                              opt_params['critical']) 
Example #14
Source File: tests.py    From python-rotate-backups with MIT License 5 votes vote down vote up
def test_filename_patterns(self):
        """Test support for filename patterns in configuration files."""
        with TemporaryDirectory(prefix='rotate-backups-', suffix='-test-suite') as root:
            for subdirectory in 'laptop', 'vps':
                os.makedirs(os.path.join(root, subdirectory))
            config_file = os.path.join(root, 'rotate-backups.ini')
            parser = configparser.RawConfigParser()
            pattern = os.path.join(root, '*')
            parser.add_section(pattern)
            parser.set(pattern, 'daily', '7')
            parser.set(pattern, 'weekly', '4')
            parser.set(pattern, 'monthly', 'always')
            with open(config_file, 'w') as handle:
                parser.write(handle)
            # Check that the configured rotation scheme is applied.
            default_scheme = dict(monthly='always')
            program = RotateBackups(config_file=config_file, rotation_scheme=default_scheme)
            program.load_config_file(os.path.join(root, 'laptop'))
            assert program.rotation_scheme != default_scheme
            # Check that the available locations are matched.
            available_locations = [
                location for location, rotation_scheme, options
                in load_config_file(config_file)
            ]
            assert len(available_locations) == 2
            assert any(location.directory == os.path.join(root, 'laptop') for location in available_locations)
            assert any(location.directory == os.path.join(root, 'vps') for location in available_locations) 
Example #15
Source File: test_config.py    From DLRN with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestConfigOptions, self).setUp()
        self.config = configparser.RawConfigParser()
        self.config.read("projects.ini") 
Example #16
Source File: test_driver_koji.py    From DLRN with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestDriverKoji, self).setUp()
        config = configparser.RawConfigParser()
        config.read("projects.ini")
        config.set("DEFAULT", "build_driver",
                   "dlrn.drivers.kojidriver.KojiBuildDriver")
        self.config = ConfigOptions(config)
        self.config.koji_krb_principal = 'test@example.com'
        self.config.koji_krb_keytab = '/home/test/test.keytab'
        self.config.koji_scratch_build = True
        self.config.koji_build_target = 'build-target'
        self.temp_dir = tempfile.mkdtemp()
        self.config.datadir = self.temp_dir
        # Create fake build log
        with open("%s/kojibuild.log" % self.temp_dir, 'a') as fp:
            fp.write("Created task: 1234")
        # In the rhpkg case, we need to create a full dir structure
        self.rhpkg_extra_dir = "%s/repos/12/34/1234567890abcdef_12345678_1"\
                               % self.temp_dir
        os.makedirs(self.rhpkg_extra_dir)
        with open("%s/rhpkgbuild.log"
                  % self.rhpkg_extra_dir, 'a') as fp:
            fp.write("Created task: 5678")
        # Create a fake rhpkg binary
        with open("%s/rhpkg" % self.temp_dir, 'a') as fp:
            fp.write("true")
        os.chmod("%s/rhpkg" % self.temp_dir,
                 stat.S_IREAD | stat.S_IWRITE | stat.S_IEXEC)
        os.environ['PATH'] = self.temp_dir + ':' + os.environ['PATH'] 
Example #17
Source File: test_driver_local.py    From DLRN with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestDriverLocal, self).setUp()
        config = configparser.RawConfigParser()
        config.read("projects.ini")
        config.set("DEFAULT", "pkginfo_driver",
                   "dlrn.drivers.local.LocalDriver")
        self.config = ConfigOptions(config)
        self.config.datadir = tempfile.mkdtemp()
        self.base_dir = tempfile.mkdtemp() 
Example #18
Source File: utils.py    From spandex with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
def load_config(config_filename=None):
    """Returns a configparser object.

    Configuration is loaded from these filenames, in increasing precedence:

      - ~/.spandex/user.cfg
      - SPANDEX_CFG environment variable
      - config_filename argument, if provided

    If a file cannot be opened, it will be ignored. If none of the filenames
    can be opened, the configparser object will be empty.

    """
    # Build list of configuration filenames.
    config_filenames = [os.path.expanduser('~/.spandex/user.cfg')]
    config_filename_env = os.environ.get('SPANDEX_CFG')
    if config_filename_env:
        config_filenames.append(config_filename_env)
    if config_filename:
        config_filenames.append(config_filename)

    # Load configuration using configparser.
    logger.debug("Loading configuration from %s" % config_filenames)
    config = configparser.RawConfigParser()
    config.read(config_filenames)
    return config 
Example #19
Source File: test_driver_mock.py    From DLRN with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestDriverMock, self).setUp()
        config = configparser.RawConfigParser()
        config.read("projects.ini")
        config.set("DEFAULT", "build_driver",
                   "dlrn.drivers.mockdriver.MockBuildDriver")
        self.config = ConfigOptions(config)
        self.temp_dir = tempfile.mkdtemp() 
Example #20
Source File: test_driver_mock.py    From DLRN with Apache License 2.0 5 votes vote down vote up
def test_driver_config(self, ld_mock, env_mock, rc_mock):
        cp = configparser.RawConfigParser()
        cp.read("projects.ini")
        cp.set("DEFAULT", "build_driver",
               "dlrn.drivers.mockdriver.MockBuildDriver")
        # default is True, test override
        cp.set('mockbuild_driver', 'install_after_build', '0')
        config = ConfigOptions(cp)
        self.assertEqual(False, config.install_after_build) 
Example #21
Source File: package_index.py    From PhonePi_SampleServer with MIT License 5 votes vote down vote up
def __init__(self):
        """
        Load from ~/.pypirc
        """
        defaults = dict.fromkeys(['username', 'password', 'repository'], '')
        configparser.RawConfigParser.__init__(self, defaults)

        rc = os.path.join(os.path.expanduser('~'), '.pypirc')
        if os.path.exists(rc):
            self.read(rc) 
Example #22
Source File: test_driver_rdoinfo.py    From DLRN with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestDriverRdoInfo, self).setUp()
        config = configparser.RawConfigParser()
        config.read("projects.ini")
        config.set("DEFAULT", "pkginfo_driver",
                   "dlrn.drivers.rdoinfo.RdoInfoDriver")
        self.temp_dir = tempfile.mkdtemp()
        self.config = ConfigOptions(config)
        self.config.datadir = self.temp_dir 
Example #23
Source File: config.py    From nnabla with Apache License 2.0 5 votes vote down vote up
def _get_nnabla_config():
    config_files = []
    config_files.append(join(dirname(abspath(__file__)), 'nnabla.conf'))
    if os.name == 'posix':
        config_files.append('/etc/nnabla.conf')
        config_files.append(abspath(join(expanduser('~'), '.nnabla')))
        config_files.append(abspath(join(os.getcwd(), 'nnabla.conf')))
    elif os.name == 'nt':
        from win32com.shell import shell, shellcon
        config_files.append(abspath(join(shell.SHGetFolderPath(
            0, shellcon.CSIDL_COMMON_APPDATA, None, 0), 'NNabla', 'nnabla.ini')))
        config_files.append(abspath(join(shell.SHGetFolderPath(
            0, shellcon.CSIDL_APPDATA, None, 0), 'NNabla', 'nnabla.ini')))
    config_files.append(abspath(join(os.getcwd(), 'nnabla.conf')))

    if "NNABLA_CONFIG_FILE_PATH" in os.environ:
        conf = os.environ["NNABLA_CONFIG_FILE_PATH"]
        if os.path.exists(conf):
            config_files.append(conf)

    config = configparser.RawConfigParser()
    for filename in config_files:
        # print(' Checking {}'.format(filename))
        if exists(filename):
            # print(' Read from {}'.format(filename))
            config.read(filename)
    return config 
Example #24
Source File: configuration.py    From airflow-scheduler-failover-controller with Apache License 2.0 5 votes vote down vote up
def __init__(self, airflow_home_dir=None, airflow_config_file_path=None):
        if airflow_home_dir is None:
            airflow_home_dir = DEFAULT_AIRFLOW_HOME_DIR
        if airflow_config_file_path is None:
            airflow_config_file_path = airflow_home_dir + "/airflow.cfg"
        self.airflow_home_dir = airflow_home_dir
        self.airflow_config_file_path = airflow_config_file_path

        if not os.path.isfile(airflow_config_file_path):
            print ("Cannot find Airflow Configuration file at '" + str(airflow_config_file_path) + "'!!!")
            sys.exit(1)

        self.conf = configparser.RawConfigParser()
        self.conf.read(airflow_config_file_path) 
Example #25
Source File: version.py    From masakari with Apache License 2.0 5 votes vote down vote up
def _load_config():
    # Don't load in global context, since we can't assume
    # these modules are accessible when distutils uses
    # this module
    from six.moves import configparser

    from oslo_config import cfg

    from oslo_log import log as logging

    global loaded, MASAKARI_VENDOR, MASAKARI_PRODUCT, MASAKARI_PACKAGE
    if loaded:
        return

    loaded = True

    cfgfile = cfg.CONF.find_file("release")
    if cfgfile is None:
        return

    try:
        cfg = configparser.RawConfigParser()
        cfg.read(cfgfile)

        if cfg.has_option("Masakari", "vendor"):
            MASAKARI_VENDOR = cfg.get("Masakari", "vendor")

        if cfg.has_option("Masakari", "product"):
            MASAKARI_PRODUCT = cfg.get("Masakari", "product")

        if cfg.has_option("Masakari", "package"):
            MASAKARI_PACKAGE = cfg.get("Masakari", "package")
    except Exception as ex:
        LOG = logging.getLogger(__name__)
        LOG.error("Failed to load %(cfgfile)s: %(ex)s",
                  {'cfgfile': cfgfile, 'ex': ex}) 
Example #26
Source File: setopt.py    From PhonePi_SampleServer with MIT License 5 votes vote down vote up
def edit_config(filename, settings, dry_run=False):
    """Edit a configuration file to include `settings`

    `settings` is a dictionary of dictionaries or ``None`` values, keyed by
    command/section name.  A ``None`` value means to delete the entire section,
    while a dictionary lists settings to be changed or deleted in that section.
    A setting of ``None`` means to delete that setting.
    """
    log.debug("Reading configuration from %s", filename)
    opts = configparser.RawConfigParser()
    opts.read([filename])
    for section, options in settings.items():
        if options is None:
            log.info("Deleting section [%s] from %s", section, filename)
            opts.remove_section(section)
        else:
            if not opts.has_section(section):
                log.debug("Adding new section [%s] to %s", section, filename)
                opts.add_section(section)
            for option, value in options.items():
                if value is None:
                    log.debug(
                        "Deleting %s.%s from %s",
                        section, option, filename
                    )
                    opts.remove_option(section, option)
                    if not opts.options(section):
                        log.info("Deleting empty [%s] section from %s",
                                 section, filename)
                        opts.remove_section(section)
                else:
                    log.debug(
                        "Setting %s.%s to %r in %s",
                        section, option, value, filename
                    )
                    opts.set(section, option, value)

    log.info("Writing %s", filename)
    if not dry_run:
        with open(filename, 'w') as f:
            opts.write(f) 
Example #27
Source File: easy_install.py    From PhonePi_SampleServer with MIT License 5 votes vote down vote up
def extract_wininst_cfg(dist_filename):
    """Extract configuration data from a bdist_wininst .exe

    Returns a configparser.RawConfigParser, or None
    """
    f = open(dist_filename, 'rb')
    try:
        endrec = zipfile._EndRecData(f)
        if endrec is None:
            return None

        prepended = (endrec[9] - endrec[5]) - endrec[6]
        if prepended < 12:  # no wininst data here
            return None
        f.seek(prepended - 12)

        tag, cfglen, bmlen = struct.unpack("<iii", f.read(12))
        if tag not in (0x1234567A, 0x1234567B):
            return None  # not a valid tag

        f.seek(prepended - (12 + cfglen))
        init = {'version': '', 'target_version': ''}
        cfg = configparser.RawConfigParser(init)
        try:
            part = f.read(cfglen)
            # Read up to the first null byte.
            config = part.split(b'\0', 1)[0]
            # Now the config is in bytes, but for RawConfigParser, it should
            #  be text, so decode it.
            config = config.decode(sys.getfilesystemencoding())
            cfg.readfp(six.StringIO(config))
        except configparser.Error:
            return None
        if not cfg.has_section('metadata') or not cfg.has_section('Setup'):
            return None
        return cfg

    finally:
        f.close() 
Example #28
Source File: configuration.py    From storj-python-sdk with MIT License 5 votes vote down vote up
def read_config():
    """Reads configuration storj client configuration.

    Mac OS X (POSIX):
        ~/.foo-bar
    Unix (POSIX):
        ~/.foo-bar
    Win XP (not roaming):
        ``C:\Documents and Settings\<user>\Application Data\storj``
    Win 7 (not roaming):
        ``C:\\Users\<user>\AppData\Local\storj``

    Returns:
        (tuple[str, str]): storj account credentials (email, password).
    """

    # OSX: /Users/<username>/.storj
    cfg = os.path.join(
        click.get_app_dir(
            APP_NAME,
            force_posix=True),
        'storj.ini')

    parser = RawConfigParser()
    parser.read([cfg])

    return parser.get(APP_NAME, CFG_EMAIL), parser.get(APP_NAME, CFG_PASSWORD) 
Example #29
Source File: test_driver_downstream.py    From DLRN with Apache License 2.0 5 votes vote down vote up
def setUp(self):
        super(TestDriverDownstream, self).setUp()
        config = configparser.RawConfigParser()
        config.read("projects.ini")
        config.set("DEFAULT", "pkginfo_driver",
                   "dlrn.drivers.downstream.DownstreamInfoDriver")
        self.temp_dir = tempfile.mkdtemp()
        self.config = ConfigOptions(config)
        self.config.versions_url = \
            'https://trunk.rdoproject.org/centos7-master/current/versions.csv'
        self.config.downstream_distro_branch = 'testbranch'
        self.config.downstream_distgit_base = 'git://git.example.com/rpms'
        self.config.datadir = self.temp_dir
        self.config.use_upstream_spec = False 
Example #30
Source File: package_index.py    From Safejumper-for-Desktop with GNU General Public License v2.0 5 votes vote down vote up
def __init__(self):
        """
        Load from ~/.pypirc
        """
        defaults = dict.fromkeys(['username', 'password', 'repository'], '')
        configparser.RawConfigParser.__init__(self, defaults)

        rc = os.path.join(os.path.expanduser('~'), '.pypirc')
        if os.path.exists(rc):
            self.read(rc)