Exemplo n.º 1
0
 def __init__(self, cfg=None):
     if cfg:
         self._cfg = ConfigParser()
         self._cfg.read(cfg)
     else:
         self._cfg = None
     self._session = None
     self._session_key = None
Exemplo n.º 2
0
def _setup_wrapper(filename, *args):
    config = ConfigParser()
    config.optionxform = str
    config.read(filename)
    try:
        setup.setup(config, *args)
    except OSError:
        print("Above 'No module named aup.setupdb' error can be ignored")
Exemplo n.º 3
0
 def __new__(cls):
     ctx, config = cls.ctx_and_config
     current_ctx = click.get_current_context(silent=True)
     if current_ctx != ctx:
         config = ConfigParser()
         config.read(cls.filenames)
         cls.ctx_and_config = (current_ctx, config)
     return config
Exemplo n.º 4
0
 def _read_config_file(self):
     # Read the virt-who-<id> config file)
     local_path = tempfile.mkstemp(suffix=self.config_file_name)[1]
     ssh.download_file(self.remote_path, local_path, hostname=self.server)
     parser = ConfigParser()
     with open(local_path) as local_fp:
         parser.read_file(local_fp)
     return parser
Exemplo n.º 5
0
def parse_color_map_from_file(f):
    color_map_config = ConfigParser()
    if isinstance(f, string_types):
        with open(f, 'r') as fp:
            color_map_config.read_file(fp)
    else:
        color_map_config.read_file(f)
    return parse_color_map_from_configparser(color_map_config)
Exemplo n.º 6
0
def set_config_file(filename):
    """
    Change the configuration file. 
    Use configuration file in non standard location.
    """
    global CONFIG_STORE
    CONFIG_STORE = ConfigParser()
    CONFIG_STORE.read(filename)
Exemplo n.º 7
0
 def __init__(self, host="127.0.0.1"):
     self._host = host
     config = ConfigParser()
     config.read(constants.get_config_file())
     if config.has_option('OpenMotics', 'http_port'):
         self._port = config.get('OpenMotics', 'http_port')
     else:
         self._port = 80
Exemplo n.º 8
0
 def _get_names_from_config(self, cp, section):
     config = ConfigParser()
     config.read(cp)
     if config.has_section(section):
         return [
             config.get(section, option)
             for option in config.options(section)
         ]
Exemplo n.º 9
0
 def __init__(self, filename):
     self.config_file = filename.strip()
     self.config = dict()
     self.parser = ConfigParser()
     self.section = u'app:main'
     defaults = {u'__file__': os.path.abspath(self.config_file)}
     self._update_defaults(defaults)
     self._create_config_object()
def parse_xml_mapping(xml_mapping_filename):
    with open(xml_mapping_filename, 'r') as f:
        config = ConfigParser()
        if six.PY3:
            config.read_file(f)  # pylint: disable=no-member
        else:
            config.read_file(f)
        return {k: dict(config.items(k)) for k in config.sections()}
Exemplo n.º 11
0
def reload_storage_policies():
    """
    Reload POLICIES from ``swift.conf``.
    """
    global _POLICIES
    if six.PY2:
        policy_conf = ConfigParser()
    else:
        # Python 3.2 disallows section or option duplicates by default
        # strict=False allows us to preserve the older behavior
        policy_conf = ConfigParser(strict=False)
    policy_conf.read(utils.SWIFT_CONF_FILE)
    try:
        _POLICIES = parse_storage_policies(policy_conf)
    except PolicyError as e:
        raise SystemExit('ERROR: Invalid Storage Policy Configuration '
                         'in %s (%s)' % (utils.SWIFT_CONF_FILE, e))
Exemplo n.º 12
0
 def __init__(self):
     """Grab the configuration (overridable for test purposes)"""
     # If there is a setup.cfg in the package, parse it
     if not os.path.exists(self.config_filename):
         self.config = None
         return
     self.config = ConfigParser()
     self.config.read(self.config_filename)
Exemplo n.º 13
0
    def _generate_appdata(self, destdir, prefix, activity_path):
        info = ConfigParser()
        info_path = os.path.join(destdir, os.path.relpath(activity_path, '/'),
                                 'activity', 'activity.info')
        info.read(info_path)

        required_fields = [
            'metadata_license', 'license', 'name', 'icon', 'description'
        ]
        for name in required_fields:
            if not info.has_option('Activity', name):
                print('[WARNING] missing AppStream metadata, '
                      'see `pydoc sugar3.bundle`')
                return

        # See https://www.freedesktop.org/software/appstream/docs/
        root = ET.Element('component', type='desktop')
        ET.SubElement(root, 'project_group').text = 'Sugar'
        ET.SubElement(root, 'translation', type='gettext').text = \
            self.config.bundle_id
        ET.SubElement(root, 'id').text = \
            self.config.bundle_id + '.activity.desktop'
        desc = ET.fromstring('<description>{}</description>'.format(
            info.get('Activity', 'description')))
        root.append(desc)

        copy_pairs = [('metadata_license', 'metadata_license'),
                      ('license', 'project_license'), ('summary', 'summary'),
                      ('name', 'name')]
        for key, ename in copy_pairs:
            ET.SubElement(root, ename).text = info.get('Activity', key)

        if info.has_option('Activity', 'screenshots'):
            screenshots = info.get('Activity', 'screenshots').split()
            ss_root = ET.SubElement(root, 'screenshots')
            for i, screenshot in enumerate(screenshots):
                e = ET.SubElement(ss_root, 'screenshot')
                if i == 0:
                    e.set('type', 'default')
                ET.SubElement(e, 'image').text = screenshot

        if info.has_option('Activity', 'url'):
            ET.SubElement(root, 'url', type='homepage').text = \
                info.get('Activity', 'url')
        if info.has_option('Activity', 'repository_url'):
            ET.SubElement(root, 'url', type='bugtracker').text = \
                info.get('Activity', 'repository_url')
        elif info.has_option('Activity', 'repository'):
            ET.SubElement(root, 'url', type='bugtracker').text = \
                info.get('Activity', 'repository')

        path = os.path.join(destdir, os.path.relpath(prefix, '/'), 'share',
                            'metainfo', self.config.bundle_id + '.appdata.xml')
        if not os.path.isdir(os.path.dirname(path)):
            os.makedirs(os.path.dirname(path))
        tree = ET.ElementTree(root)
        tree.write(path, encoding='UTF-8')
        print('Install %s' % (path))
Exemplo n.º 14
0
    def read_systemini(self):
        """read group info from system.ini
        this is part of the connection process
        """
        self.ftpconn.connect(**self.ftpargs)
        self.ftpconn.cwd(posixpath.join(self.ftphome, 'Config'))
        lines = self.ftpconn.getlines('system.ini')
        self.ftpconn.close()

        pvtgroups = []
        self.stages = OrderedDict()
        self.groups = OrderedDict()
        sconf = ConfigParser()
        sconf.readfp(StringIO('\n'.join(lines)))

        # read and populate lists of groups first
        for gtype, glist in sconf.items('GROUPS'):  # ].items():
            if len(glist) > 0:
                for gname in glist.split(','):
                    gname = gname.strip()
                    self.groups[gname] = OrderedDict()
                    self.groups[gname]['category'] = gtype.strip()
                    self.groups[gname]['positioners'] = []
                    if gtype.lower().startswith('multiple'):
                        pvtgroups.append(gname)

        for section in sconf.sections():
            if section in ('DEFAULT', 'GENERAL', 'GROUPS'):
                continue
            items = sconf.options(section)
            if section in self.groups:  # this is a Group Section!
                poslist = sconf.get(section, 'positionerinuse')
                posnames = [a.strip() for a in poslist.split(',')]
                self.groups[section]['positioners'] = posnames
            elif 'plugnumber' in items:  # this is a stage
                self.stages[section] = {
                    'stagetype': sconf.get(section, 'stagename')
                }

        if len(pvtgroups) == 1:
            self.set_trajectory_group(pvtgroups[0])

        for sname in self.stages:
            ret = self._xps.PositionerMaximumVelocityAndAccelerationGet(
                self._sid, sname)
            try:
                self.stages[sname]['max_velo'] = ret[1]
                self.stages[sname]['max_accel'] = ret[2] / 3.0
            except:
                print("could not set max velo/accel for %s" % sname)
            ret = self._xps.PositionerUserTravelLimitsGet(self._sid, sname)
            try:
                self.stages[sname]['low_limit'] = ret[1]
                self.stages[sname]['high_limit'] = ret[2]
            except:
                print("could not set limits for %s" % sname)

        return self.groups
Exemplo n.º 15
0
def setUpModule():
    # Backup local config file if it exists
    if os.path.exists(local_cfg):
        os.rename(local_cfg, local_cfg + '.bak')
        # Re-read the configs
        girder_worker.config = ConfigParser()
        _cfgs = ('worker.dist.cfg', 'worker.local.cfg')
        girder_worker.config.read(
            [os.path.join(girder_worker.PACKAGE_DIR, f) for f in _cfgs])
Exemplo n.º 16
0
def parse_config_file(file_path):
    config = ConfigParser()
    config.read(file_path)
    if 'batch_scoring' not in config.sections():
        #  We are return empty dict, because there is nothing in this file
        #  that related to arguments to batch scoring.
        return {}
    parsed_dict = dict(config.items('batch_scoring'))
    return config_validator(parsed_dict)
Exemplo n.º 17
0
def get_options_from_config(config_file):
    """Get configuration information from config like setup.cfg or tox.ini"""
    from six.moves.configparser import ConfigParser
    conf = ConfigParser()

    conf.read([config_file])
    if conf.has_section('changelog'):
        return dict(conf.items('changelog'))
    return {}
Exemplo n.º 18
0
def get_app(config='development.ini'):
    cfg = PROJECT.joinpath(config)
    parser = ConfigParser()
    parser.read(cfg)
    return glottolog3.main({
        '__file__': str(cfg),
        'here': str(PROJECT)
    }, **{'sqlalchemy.url':
          parser.get('app:main', 'sqlalchemy.url')})
Exemplo n.º 19
0
def get_configuration_dict(configuration=None, value_types=None):
    """
    Parse the configuration files

    Parameters
    ----------
    configuration : str or list, optional
        A configuration file or list of configuration files to parse,
        defaults to the deploy_default.conf file in the package and
        deploy.conf in the current working directory.

    value_types : dict, optional
        Dictionary containing classes to apply to specific items

    Returns
    -------
    dict
        Configuration dictionary
    """
    if not value_types:  # pragma: no cover
        value_types = config_types()
    if configuration is None or configuration is '':  # pragma: no cover
        configuration = [
            # Config file that is part of the package
            # PACKAGE_DEFAULT_CONFIG,

            # Any deploy.conf files in the current directory
            'deploy.conf'
        ]
    config = ConfigParser()

    # Set the config defaults
    try:
        config.read_string(config_defaults())
    except AttributeError:
        config.readfp(io.BytesIO(config_defaults()))

    logger.debug('Working with default dict: %r', config_defaults())
    config.read(configuration)
    result_dict = {}
    for section in config.sections():
        result_dict[section] = {}
        for key, val in config.items(section):
            result_dict[section][key] = str_format_env(val)

    config_update(result_dict)

    if 'locations' not in result_dict.keys():
        result_dict['locations'] = {}
    result_dict['locations']['package_scripts'] = package_scripts_directory()
    if not result_dict['global'].get('virtualenv_dir', None):
        result_dict['global']['virtualenv_dir'] = \
            default_virtualenv_directory()

    cast_types(result_dict)

    return result_dict
Exemplo n.º 20
0
def _parseINI(text):
    from six.moves import cStringIO
    from six.moves.configparser import ConfigParser
    parser = ConfigParser()
    try:
        parser.read_file(cStringIO(text))
    except AttributeError:  # Python 2
        parser.readfp(cStringIO(text))
    return parser
Exemplo n.º 21
0
def main():
    # Setup an argparser and parse the known commands to get the config file
    parser = argparse.ArgumentParser(add_help=False)
    parser.add_argument('-C',
                        '--config',
                        help='Specify a config file to use',
                        default='/etc/rpkg/rfpkg.conf')

    (args, other) = parser.parse_known_args()

    # Make sure we have a sane config file
    if not os.path.exists(args.config) and \
       not other[-1] in ['--help', '-h', 'help']:
        sys.stderr.write('Invalid config file %s\n' % args.config)
        sys.exit(1)

    # Setup a configuration object and read config file data
    config = ConfigParser()
    config.read(args.config)

    client = rfpkg.cli.rfpkgClient(config)
    client.do_imports(site='rfpkg')
    client.parse_cmdline()

    if not client.args.path:
        try:
            client.args.path = pyrpkg.utils.getcwd()
        except:
            print('Could not get current path, have you deleted it?')
            sys.exit(1)

    # setup the logger -- This logger will take things of INFO or DEBUG and
    # log it to stdout.  Anything above that (WARN, ERROR, CRITICAL) will go
    # to stderr.  Normal operation will show anything INFO and above.
    # Quiet hides INFO, while Verbose exposes DEBUG.  In all cases WARN or
    # higher are exposed (via stderr).
    log = pyrpkg.log
    client.setupLogging(log)

    if client.args.v:
        log.setLevel(logging.DEBUG)
    elif client.args.q:
        log.setLevel(logging.WARNING)
    else:
        log.setLevel(logging.INFO)

    # Run the necessary command
    try:
        sys.exit(client.args.command())
    except KeyboardInterrupt:
        pass
    except Exception as e:
        log.error('Could not execute %s: %s' %
                  (client.args.command.__name__, e))
        if client.args.v:
            raise
        sys.exit(1)
Exemplo n.º 22
0
def import_library(libfilepointer):
    """
    Import a units library, replacing any existing definitions.

    Parameters
    ----------
    libfilepointer : file
        new library file to work with

    Returns
    -------
    ConfigParser
        newly updated units library for the module
    """
    global _UNIT_LIB
    global _UNIT_CACHE
    _UNIT_CACHE = {}
    _UNIT_LIB = ConfigParser()
    _UNIT_LIB.optionxform = _do_nothing
    _UNIT_LIB.readfp(libfilepointer)
    required_base_types = ['length', 'mass', 'time', 'temperature', 'angle']
    _UNIT_LIB.base_names = list()
    # used to is_angle() and other base type checking
    _UNIT_LIB.base_types = dict()
    _UNIT_LIB.unit_table = dict()
    _UNIT_LIB.prefixes = dict()
    _UNIT_LIB.help = list()

    for prefix, factor in _UNIT_LIB.items('prefixes'):
        factor, comma, comment = factor.partition(',')
        _UNIT_LIB.prefixes[prefix] = float(factor)

    base_list = [0] * len(_UNIT_LIB.items('base_units'))

    for i, (unit_type, name) in enumerate(_UNIT_LIB.items('base_units')):
        _UNIT_LIB.base_types[unit_type] = i
        powers = list(base_list)
        powers[i] = 1
        # print '%20s'%unit_type, powers
        # cant use add_unit because no base units exist yet
        _new_unit(name, 1, powers)
        _UNIT_LIB.base_names.append(name)

    # test for required base types
    missing = [
        utype for utype in required_base_types
        if utype not in _UNIT_LIB.base_types
    ]
    if missing:
        raise ValueError('Not all required base type were present in the'
                         ' config file. missing: %s, at least %s required' %
                         (missing, required_base_types))

    # Explicit unitless 'unit'.
    _new_unit('unitless', 1, list(base_list))
    _update_library(_UNIT_LIB)
    return _UNIT_LIB
def read_test_config():
    """Reads the test_values config file."""
    config = ConfigParser()
    config_file = os.sep.join([os.path.dirname(__file__), 'test_values.conf'])
    config_readme = os.sep.join([os.path.dirname(__file__), 'README'])
    if not os.path.isfile(config_file):
        raise Exception('Integration test config file missing.  See setup instructions in {}'.format(config_readme))
    config.read(config_file)
    return config
Exemplo n.º 24
0
def get_ol(server):
    config = ConfigParser()
    config.read(os.path.expanduser('~/.olrc'))

    ol = olapi.OpenLibrary(server)
    username = config.get('account', 'username')
    password = config.get('account', 'password')
    ol.login(username, password)
    return ol
    def test_list_with_no_entries(self):
        name = self.make_empty_temp_file()
        to_config_file(name, "section.name", {"ports": []})

        self.assertTrue(os.path.isfile(name))

        config = ConfigParser()
        config.read(name)
        self.assertEqual("", config.get("section.name", "ports"))
Exemplo n.º 26
0
 def __init__(self):
     """Grab the configuration (overridable for test purposes)"""
     # If there is a setup.cfg in the package, parse it
     if not os.path.exists(self.config_filename):
         self.config = None
         return
     self.config = ConfigParser()
     with codecs.open(self.config_filename, 'r', 'utf8') as fp:
         self.config.readfp(fp)
 def handleApps(self, **kwargs):
     l10nbuilds = urlopen(
         'https://raw.githubusercontent.com/Pike/master-ball/'
         'master/l10n-master/l10nbuilds.ini')
     cp = ConfigParser()
     cp.readfp(l10nbuilds)
     for section in cp.sections():
         self.stdout.write(section + '\n')
         self.handleSection(section, dict(cp.items(section)))
Exemplo n.º 28
0
    def __init__(self):
        self.configparser = ConfigParser()

        if len(self.configparser.read(self.PYQUIL_CONFIG_PATH)) == 0:
            print("! WARNING:\n"
                  "!   There was an issue finding your pyQuil config file.\n"
                  "!   Have you run the pyquil-config-setup command yet?\n"
                  "! See the getting started guide at https://go.rigetti.com/getting-started",
                  file=sys.stderr)
Exemplo n.º 29
0
    def read_param_file(self):
        """Read the parameter file and populate the relevant dictionaries
        """
        self.out_values = []
        # read the file
        params = ConfigParser(allow_no_value=True)
        f = params.read(self.config_file)
        if not f:
            msgr.fatal(u"File <{}> not found".format(self.config_file))
        # populate dictionaries using loops instead of using update() method
        # in order to not add invalid key
        for k in self.raw_input_times:
            if params.has_option('time', k):
                self.raw_input_times[k] = params.get('time', k)
        for k in self.sim_param:
            if params.has_option('options', k):
                self.sim_param[k] = params.getfloat('options', k)
        for k in self.grass_params:
            if params.has_option('grass', k):
                self.grass_params[k] = params.get('grass', k)
        # check for deprecated input names
        if params.has_option('input', "drainage_capacity"):
            msgr.warning(u"'drainage_capacity' is deprecated. "
                         u"Use 'losses' instead.")
            self.input_map_names['losses'] = params.get(
                'input', "drainage_capacity")
        # search for valid inputs
        for k in self.input_map_names:
            if params.has_option('input', k):
                self.input_map_names[k] = params.get('input', k)

        # drainage parameters
        for k in self.drainage_params:
            if params.has_option('drainage', k):
                if k in ['swmm_inp', 'output', 'swmm_gage']:
                    self.drainage_params[k] = params.get('drainage', k)
                else:
                    self.drainage_params[k] = params.getfloat('drainage', k)
        # statistic file
        if params.has_option('statistics', 'stats_file'):
            self.stats_file = params.get('statistics', 'stats_file')
        else:
            self.stats_file = None
        # output maps
        if params.has_option('output', 'prefix'):
            self.out_prefix = params.get('output', 'prefix')
        if params.has_option('output', 'values'):
            out_values = params.get('output', 'values').split(',')
            self.out_values = [e.strip() for e in out_values]
            # check for deprecated values
            if 'drainage_cap' in self.out_values and 'losses' not in self.out_values:
                msgr.warning(u"'drainage_cap' is deprecated. "
                             u"Use 'losses' instead.")
                self.out_values.append('losses')
        self.generate_output_name()
        return self
Exemplo n.º 30
0
    def _read_pypirc(self):
        """Reads the .pypirc file."""
        rc = self._get_rc_file()
        if os.path.exists(rc):
            self.announce('Using PyPI login from %s' % rc)
            repository = self.repository or self.DEFAULT_REPOSITORY
            config = ConfigParser()
            config.read(rc)
            sections = config.sections()
            if 'distutils' in sections:
                # let's get the list of servers
                index_servers = config.get('distutils', 'index-servers')
                _servers = [
                    server.strip() for server in index_servers.split('\n')
                    if server.strip() != ''
                ]
                if _servers == []:
                    # nothing set, let's try to get the default pypi
                    if 'pypi' in sections:
                        _servers = ['pypi']
                    else:
                        # the file is not properly defined, returning
                        # an empty dict
                        return {}
                for server in _servers:
                    current = {'server': server}
                    current['username'] = config.get(server, 'username')

                    # optional params
                    for key, default in (('repository',
                                          self.DEFAULT_REPOSITORY),
                                         ('realm', self.DEFAULT_REALM),
                                         ('password', None)):
                        if config.has_option(server, key):
                            current[key] = config.get(server, key)
                        else:
                            current[key] = default
                    if (current['server'] == repository
                            or current['repository'] == repository):
                        return current
            elif 'server-login' in sections:
                # old format
                server = 'server-login'
                if config.has_option(server, 'repository'):
                    repository = config.get(server, 'repository')
                else:
                    repository = self.DEFAULT_REPOSITORY
                return {
                    'username': config.get(server, 'username'),
                    'password': config.get(server, 'password'),
                    'repository': repository,
                    'server': server,
                    'realm': self.DEFAULT_REALM
                }

        return {}