def parse_locators(file): """Parses locators configuration file and returns dictionary of locators. Arguments: file = locators file object (opened with open() method) Return: Dictionary of parsed locators.""" # parse file parser = RawConfigParser() parser.readfp(file) # get sections from file sections = parser.sections() # prepare locators dictionary locators = {} # don't add sections name # when only one section exists if len(sections) is 1: section = sections[0] for name in parser.options(section): locators[name] = parser.get(section, name) # add section name as a key # when more than one section exists else: for section in sections: locators[section] = {} for name in parser.options(section): locators[section][name] = parser.get(section, name) # return dictionary of parsed locators return locators
def parse_locators(file): """Parses locators configuration file and returns dictionary of locators. Arguments: file = locators file object (opened with open() method) Return: Dictionary of parsed locators.""" # parse file parser = RawConfigParser() parser.readfp(file) # get sections from file sections = parser.sections() # prepare locators dictionary locators = {} # don't add sections name # when only one section exists if len(sections) is 1: section = sections[0] for name in parser.options(section): locators[name] = parser.get(section, name) # add section name as a key # when more than one section exists else: for section in sections: locators[section] = {} for name in parser.options(section): locators[section][name] = parser.get(section, name) # return dictionary of parsed locators return locators
def loadMeta(self): "Loads the 'meta' - variables that change with the server (worlds, admins, etc.)" config = ConfigParser() config.read("data/server.meta") specs = ConfigParser() specs.read("data/spectators.meta") # Read in the worlds if config.has_section("worlds"): for name in config.options("worlds"): self.worlds[name] = None if name is "main": self.main_loaded = True else: self.worlds["main"] = None if not self.main_loaded: self.worlds["main"] = None # Read in the admins if config.has_section("admins"): for name in config.options("admins"): self.admins.add(name) # Read in the mods if config.has_section("mods"): for name in config.options("mods"): self.mods.add(name) if config.has_section("advbuilders"): for name in config.options("advbuilders"): self.advbuilders.add(name) # Read in the directors if config.has_section("directors"): for name in config.options("directors"): self.directors.add(name) if config.has_section("silenced"): for name in config.options("silenced"): self.silenced.add(name) # Read in the spectators if specs.has_section("spectators"): for name in specs.options("spectators"): self.spectators.add(name) # Read in the bans if config.has_section("banned"): for name in config.options("banned"): self.banned[name] = config.get("banned", name) # Read in the ipbans if config.has_section("ipbanned"): for ip in config.options("ipbanned"): self.ipbanned[ip] = config.get("ipbanned", ip) # Read in the ipspecs if specs.has_section("ipspecced"): for ip in specs.options("ipspecced"): self.ipbanned[ip] = config.get("ipspecced", ip)
def read_config(self, contents): """ Constructs a configuration object from config contents :param contents: Raw .ini contents """ parser = RawConfigParser() parser.readfp(StringIO(contents)) self.nodes = [] self._extra_globals = {} for key in parser.options('global'): if key == 'plugins': self._plugins = [plugin.strip() for plugin in parser.get('global', 'plugins').split(',')] elif key == 'cluster_id': self.cluster_id = parser.get('global', 'cluster_id') elif key == 'cluster': pass # Ignore these else: self._extra_globals[key] = parser.get('global', key) for node in parser.get('global', 'cluster').split(','): node = node.strip() self.nodes.append(ArakoonNodeConfig(name=node, ip=parser.get(node, 'ip'), client_port=parser.get(node, 'client_port'), messaging_port=parser.get(node, 'messaging_port'), log_sinks=parser.get(node, 'log_sinks'), crash_log_sinks=parser.get(node, 'crash_log_sinks'), home=parser.get(node, 'home'), tlog_dir=parser.get(node, 'tlog_dir')))
class Users: """Parses users.conf file and gets all users' information. Provides tests with users property and get_user() method.""" def __init__(self): # initiate empty dictionary of users self._users = {} # parse users file self._settings = RawConfigParser() file = open('framework/users/users.cfg') self._settings.readfp(file) # parse sections of users file for section in self._settings.sections(): # transform section to lower-case for readability role = section.lower() self._users[role] = {} # parse options in sections for option in self._settings.options(section): # transform option to lower-case for readability info = option.lower() # write to users dictionary self._users[role][info] = self._settings.get(section, option) @property def users(self): """Returns dictionary of users keyed by users.conf section name.""" return self._users def get_user(self, role): """Returns dictionary of user's information by user's role.""" return self._users[role]
class ParamStore(object): def __init__(self, root_dir, file_name): if not os.path.isdir(root_dir): os.makedirs(root_dir) self._path = os.path.join(root_dir, file_name) self._dirty = False # open config file self._config = RawConfigParser() self._config.read(self._path) def __del__(self): self.flush() def flush(self): if not self._dirty: return self._dirty = False of = open(self._path, "w") self._config.write(of) of.close() def get(self, section, option, default=None): """Get a parameter value and return a string. If default is specified and section or option are not defined in the file, they are created and set to default, which is then the return value. """ if not self._config.has_option(section, option): if default is not None: self.set(section, option, default) return default return self._config.get(section, option) def get_datetime(self, section, option, default=None): result = self.get(section, option, default) if result: return safestrptime(result) return result def set(self, section, option, value): """Set option in section to string value.""" if not self._config.has_section(section): self._config.add_section(section) elif self._config.has_option(section, option) and self._config.get(section, option) == value: return self._config.set(section, option, value) self._dirty = True def unset(self, section, option): """Remove option from section.""" if not self._config.has_section(section): return if self._config.has_option(section, option): self._config.remove_option(section, option) self._dirty = True if not self._config.options(section): self._config.remove_section(section) self._dirty = True
def read_config(self, contents): """ Constructs a configuration object from config contents :param contents: Raw .ini contents """ parser = RawConfigParser() parser.readfp(StringIO(contents)) self.nodes = [] self._extra_globals = {} for key in parser.options('global'): if key == 'plugins': self._plugins = [ plugin.strip() for plugin in parser.get('global', 'plugins').split(',') ] elif key == 'cluster_id': self.cluster_id = parser.get('global', 'cluster_id') elif key == 'cluster': pass # Ignore these else: self._extra_globals[key] = parser.get('global', key) for node in parser.get('global', 'cluster').split(','): node = node.strip() self.nodes.append( ArakoonNodeConfig( name=node, ip=parser.get(node, 'ip'), client_port=parser.get(node, 'client_port'), messaging_port=parser.get(node, 'messaging_port'), log_sinks=parser.get(node, 'log_sinks'), crash_log_sinks=parser.get(node, 'crash_log_sinks'), home=parser.get(node, 'home'), tlog_dir=parser.get(node, 'tlog_dir')))
def __init__(self, filename): with open(filename) as cfg: cp = RawConfigParser() cp.readfp(cfg) for sect in cp.sections(): for opt in cp.options(sect): self.__dict__[sect + '_' + opt] = cp.get(sect, opt)
def load_settings(config_file_path): """ This function creates the RawConfigParser object that parses settings from the config file. It then takes those settings and creates a dict of the options which can then be made into attributes. :param config_file_path: the file path of the config file :return config_settings: a dict with all parsed settings from the file """ config_settings = {} config = RawConfigParser() config.read(config_file_path) section_list = ['ZNC CONFIGURATION OPTIONS', 'WEB REGISTRATION CONSOLE OPTIONS', 'IRC CLIENT OPTIONS', ] for section in section_list: options_list = config.options(section) for option in options_list: config_settings[option] = config.get(section, option) return config_settings
def get_conf(args): '''Read a configuration file, add configuration from cmdline args.''' config_filename = args.inifile if not os.path.isfile(config_filename): logging.error("Configuration file not found: %s", config_filename) sys.exit(1) parser = RawConfigParser() parser.read(config_filename) conf = {} # create a dictionary for each section for section in parser.sections(): conf[section] = {} for key in parser.options(section): # Currently, all configuration options will be numeric. # greedy_parse() converts each to a float or an int, if it can. conf[section][key] = greedy_parse(parser.get(section, key)) # setup a 'general' section of the configuration # (mostly for the record in the -setup.txt file) conf['general'] = {} conf['general']['notes'] = args.notes conf['general']['inifile'] = args.inifile conf['general']['boxname'] = get_boxname() return conf
def load_config(self): """ Reads a configuration from reality """ contents = EtcdConfiguration.get(ArakoonClusterConfig.ETCD_CONFIG_KEY.format(self.cluster_id), raw=True) parser = RawConfigParser() parser.readfp(StringIO(contents)) self.nodes = [] self._extra_globals = {} for key in parser.options('global'): if key == 'plugins': self._plugins = [plugin.strip() for plugin in parser.get('global', 'plugins').split(',')] elif key in ['cluster_id', 'cluster']: pass # Ignore these else: self._extra_globals[key] = parser.get('global', key) for node in parser.get('global', 'cluster').split(','): node = node.strip() self.nodes.append(ArakoonNodeConfig(name=node, ip=parser.get(node, 'ip'), client_port=parser.get(node, 'client_port'), messaging_port=parser.get(node, 'messaging_port'), log_sinks=parser.get(node, 'log_sinks'), crash_log_sinks=parser.get(node, 'crash_log_sinks'), home=parser.get(node, 'home'), tlog_dir=parser.get(node, 'tlog_dir')))
def loadConfig(self, config=K2_DEFAULT_CONFIG): ''' Load settings from a .ini-style configuration file. If the configuration file to use is not provided, then the default L{K2_DEFAULT_CONFIG} will be used instead. @param config: The path to an .ini-style configuration file. @type config: String @raise K2FinalizeError: Thrown if the L{K2Settings} instance has already been finalized. ''' if (self.finalized): raise K2FinalizeError('Can not load new configuration, ' \ + 'settings finalized') self.logger.info('Loading configuration from path ' + config) self.configPath = config # Read in our configuration parser = RawConfigParser() parser.read(self.configPath) self.logger.debug('ConfigParser complete') # Each section is a module name; the options in the section are # settings to be copied into __unusedSettings, and then processed for section in parser.sections(): if (section not in self.__unusedSettings): self.__unusedSettings[section] = {} for setting in parser.options(section): self.__unusedSettings[section][setting] = parser.get(section, \ setting) self.processUnused(section)
def __init__(self, filename): with open(filename) as cfg: cp = RawConfigParser() cp.readfp(cfg) for sect in cp.sections(): for opt in cp.options(sect): self.__dict__[sect + '_' + opt] = cp.get(sect, opt)
def init_config(config_file, _reactor, group): '''initialize configuration configuration file should be in the form: [transports] ipN=host:port serN=COMX ''' cp = RawConfigParser() cp.read(config_file) if cp.has_option('global','debug'): global_config.loop_interval = 5.0 global_config.debug = True if cp.has_option('global','smtphost'): global_config.smtphost = cp.get('global','smtphost') if cp.has_option('global','smtpfrom'): global_config.smtpfrom = cp.get('global','smtpfrom') if cp.has_option('global','smtpto'): tos = [x.strip() for x in cp.get('global','smtpto').split(',')] global_config.smtpto = tos section = 'transports' for op in cp.options(section): value = cp.get(section, op) if op.startswith('ip'): ip, port = value.split(':') _reactor.connectTCP(ip, int(port), group.factory()) elif op.startswith('ser'): serialport.SerialPort(group.protocol(),value,_reactor)
def load_config(self, ip=None): """ Reads a configuration from reality """ if self.filesystem is False: contents = Configuration.get(self.config_path, raw=True) else: client = self._load_client(ip) contents = client.file_read(self.config_path) parser = RawConfigParser() parser.readfp(StringIO(contents)) self.nodes = [] self._extra_globals = {} for key in parser.options('global'): if key == 'plugins': self._plugins = [plugin.strip() for plugin in parser.get('global', 'plugins').split(',')] elif key == 'cluster_id': self.cluster_id = parser.get('global', 'cluster_id') elif key == 'cluster': pass # Ignore these else: self._extra_globals[key] = parser.get('global', key) for node in parser.get('global', 'cluster').split(','): node = node.strip() self.nodes.append(ArakoonNodeConfig(name=node, ip=parser.get(node, 'ip'), client_port=parser.get(node, 'client_port'), messaging_port=parser.get(node, 'messaging_port'), log_sinks=parser.get(node, 'log_sinks'), crash_log_sinks=parser.get(node, 'crash_log_sinks'), home=parser.get(node, 'home'), tlog_dir=parser.get(node, 'tlog_dir')))
def parser_to_dict(self, filename): parser = RawConfigParser() parser.readfp(open(filename, "r")) dict_ = {} options = parser.options("LIB") for option in options: dict_[option] = parser.get("LIB", option) return dict_
def read_config_file(self): """Read in the configuration file and store it in self.config. """ self.acquire_lock() self.config = Configuration() self.config_source = Configuration() self.config_file = self.find_config_file() if self.config_file and self.config_file.exists(): config = RawConfigParser(self.config) config.read(str(self.config_file)) # Iterate over the config file options and write them into self.config for section in config.sections(): for option in config.options(section): value = config.get(section, option) # Coerce values into useful datatypes if value.lower() in ['1', 'yes', 'true', 'on']: value = True elif value.lower() in ['0', 'no', 'false', 'off']: value = False elif value.lower() in ['none']: continue elif value.replace('.', '').isdigit(): if '.' in value: value = Decimal(value) else: value = int(value) self.config[section][option] = value self.config_source[section][option] = 'config_file' self.release_lock()
def load_from_file(self): """ Load from ONE config file, the file path is explained in class docstring """ file_path = (self.config_path or self._file_path_from_env() or self._file_path_from_home() or self._file_path_from_local()) if not file_path: return {} config = RawConfigParser() try: config.read(file_path) config_dict = {} for option in config.options("sqreen"): config_dict[option.upper()] = config.get("sqreen", option) return config_dict except ConfigError: LOGGER.debug("Error parsing config file %s", file_path) return {}
def loadConfig(self, config=K2_DEFAULT_CONFIG): ''' Load settings from a .ini-style configuration file. If the configuration file to use is not provided, then the default L{K2_DEFAULT_CONFIG} will be used instead. @param config: The path to an .ini-style configuration file. @type config: String @raise K2FinalizeError: Thrown if the L{K2Settings} instance has already been finalized. ''' if (self.finalized): raise K2FinalizeError('Can not load new configuration, ' \ + 'settings finalized') self.logger.info('Loading configuration from path ' + config) self.configPath = config # Read in our configuration parser = RawConfigParser() parser.read(self.configPath) self.logger.debug('ConfigParser complete') # Each section is a module name; the options in the section are # settings to be copied into __unusedSettings, and then processed for section in parser.sections(): if (section not in self.__unusedSettings): self.__unusedSettings[section] = {} for setting in parser.options(section): self.__unusedSettings[section][setting] = parser.get(section, \ setting) self.processUnused(section)
def parser_to_dict(self, filename): parser = RawConfigParser() parser.readfp(open(filename, "r")) dict_ = {} options = parser.options("LIB") for option in options: dict_[option] = parser.get("LIB", option) return dict_
def __init__(self, filename, mixer): from ConfigParser import RawConfigParser config = RawConfigParser() config.read(filename) self.play_intro = config.getboolean('Main', 'play_intro') if mixer: self.mixer = config.getboolean('Main', 'mixer') else: self.mixer = False self.music = GetDataPath(config.get('Main', 'music')) self.music = os.path.expanduser(self.music) width = config.getint('Defaults', 'width') height = config.getint('Defaults', 'height') self.subsettings = {} sections = config.sections() for defaults in ('Main', 'Defaults'): sections.remove(defaults) for sec in sections: op_dict = {} for op in config.options(sec): op_dict[op] = config.get(sec, op) if op in ('width', 'height'): op_dict[op] = eval(op_dict[op]) for op in ('width', 'height'): if op not in op_dict or op_dict[op] == 0: op_dict[op] = locals()[op] self.subsettings[sec] = op_dict
def configure(self, settings=None): """Parses arg `settings` or settings file if None passed and sets class attributes accordingly """ config = ConfigParser() # using str instead of optionxform not to .lower() options config.optionxform = str if settings is not None: for section in settings: config.add_section(section) for key, value in settings[section].items(): config.set(section, key, str(value)) else: settings_path = os.path.join(get_project_root(), SETTINGS_FILE_NAME) config.read(settings_path) for section in config.sections(): # legacy format. use following after dropping py2 support: # for key, value in config[section].items(): # setattr(getattr(self, section), key, value) for key in config.options(section): setattr(getattr(self, section), key, config.get(section, key)) self._configure_logging() self._configure_thirdparty_logging() self.configured = True
def __init__(self, filename=config_file): self._filename = filename _parser = RawConfigParser() if self.read(_parser): for section in _parser.sections(): for option in _parser.options(section): self._values['__'.join((section, option))] = _parser.get(section, option)
def main(): import os from optparse import OptionParser from ConfigParser import RawConfigParser from sqlalchemy import create_engine from buildapi.lib.mq import JobRequestConsumer, JobRequestDonePublisher parser = OptionParser() parser.set_defaults( configfile='selfserve-agent.ini', wait=False, verbosity=log.INFO ) parser.add_option("-w", "--wait", dest="wait", action="store_true") parser.add_option("-v", dest="verbosity", action="store_const", const=log.DEBUG, help="be verbose") parser.add_option("-q", dest="verbosity", action="store_const", const=log.WARN, help="be quiet") parser.add_option("-f", "--config-file", dest="configfile") options, args = parser.parse_args() if not os.path.exists(options.configfile): parser.error("Config file %s does not exist" % options.configfile) log.basicConfig(format='%(asctime)s %(message)s', level=options.verbosity) config = RawConfigParser( {'port': 5672, 'ssl': 'false', 'vhost': '/', }) config.read([options.configfile]) amqp_config = {} for option in config.options('mq'): amqp_config['mq.%s' % option] = config.get('mq', option) agent = BuildAPIAgent( db=create_engine(config.get('db', 'url'), pool_recycle=60), masters_url=config.get('masters', 'masters-url'), buildbot=config.get('masters', 'buildbot'), sendchange_master=config.get('masters', 'sendchange-master'), publisher=JobRequestDonePublisher(amqp_config), branches_url=config.get('branches', 'url'), clobberer_url=config.get('clobberer', 'url'), clobberer_auth=config.get('clobberer', 'auth'), ) consumer = JobRequestConsumer(amqp_config) consumer.register_callback(agent.receive_message) if options.wait: try: consumer.run() except KeyboardInterrupt: # Let this go without a fuss pass else: consumer.run_until_idle()
def parse_package_metadata(): """ Read the 'metadata' section of 'setup.cfg' to calculate the package metadata (at least those parts that can be configured staticly). """ try: from ConfigParser import RawConfigParser except ImportError: from configparser import RawConfigParser cfg = RawConfigParser() with open('setup.cfg') as fp: cfg.readfp(fp) cfg.optionxform = lambda x: x metadata = {} for opt in cfg.options('metadata'): val = cfg.get('metadata', opt) if opt in ('classifiers',): metadata[opt] = [x for x in val.splitlines() if x] elif opt in ('long_description',): metadata[opt] = val[1:] elif opt in ('packages', 'namespace_packages', 'platforms', 'keywords'): metadata[opt] = [x.strip() for x in val.split(',')] elif opt in ['zip-safe']: metadata['zip_safe'] = int(val) else: metadata[opt] = val metadata['version'] = package_version() return metadata
def read_config_file(self, config_file): """Read in the configuration file and return Configuration objects for it and the config_source. """ config = Configuration() config_source = Configuration() if config_file.exists(): raw_config = RawConfigParser() raw_config.read(str(config_file)) # Iterate over the config file options and write them into config for section in raw_config.sections(): for option in raw_config.options(section): value = raw_config.get(section, option) # Coerce values into useful datatypes if value.lower() in ['1', 'yes', 'true', 'on']: value = True elif value.lower() in ['0', 'no', 'false', 'off']: value = False elif value.lower() in ['none']: continue elif value.replace('.', '').isdigit(): if '.' in value: value = Decimal(value) else: value = int(value) config[section][option] = value config_source[section][option] = 'config_file' return config, config_source
def load_config(self): """ Reads a configuration from reality """ contents = EtcdConfiguration.get(ArakoonClusterConfig.ETCD_CONFIG_KEY.format(self.cluster_id), raw=True) parser = RawConfigParser() parser.readfp(StringIO(contents)) self.nodes = [] self._extra_globals = {} for key in parser.options('global'): if key == 'plugins': self._plugins = [plugin.strip() for plugin in parser.get('global', 'plugins').split(',')] elif key in ['cluster_id', 'cluster']: pass # Ignore these else: self._extra_globals[key] = parser.get('global', key) for node in parser.get('global', 'cluster').split(','): node = node.strip() self.nodes.append(ArakoonNodeConfig(name=node, ip=parser.get(node, 'ip'), client_port=parser.get(node, 'client_port'), messaging_port=parser.get(node, 'messaging_port'), log_dir=parser.get(node, 'log_dir'), home=parser.get(node, 'home'), tlog_dir=parser.get(node, 'tlog_dir')))
def main(): import os from optparse import OptionParser from ConfigParser import RawConfigParser from sqlalchemy import create_engine from buildapi.lib.mq import JobRequestConsumer, JobRequestDonePublisher parser = OptionParser() parser.set_defaults( configfile='selfserve-agent.ini', wait=False, verbosity=log.INFO ) parser.add_option("-w", "--wait", dest="wait", action="store_true") parser.add_option("-v", dest="verbosity", action="store_const", const=log.DEBUG, help="be verbose") parser.add_option("-q", dest="verbosity", action="store_const", const=log.WARN, help="be quiet") parser.add_option("-f", "--config-file", dest="configfile") options, args = parser.parse_args() if not os.path.exists(options.configfile): parser.error("Config file %s does not exist" % options.configfile) log.basicConfig(format='%(asctime)s %(message)s', level=options.verbosity) config = RawConfigParser( {'port': 5672, 'ssl': 'false', 'vhost': '/', }) config.read([options.configfile]) amqp_config = {} for option in config.options('mq'): amqp_config['mq.%s' % option] = config.get('mq', option) agent = BuildAPIAgent( db=create_engine(config.get('db', 'url'), pool_recycle=60), masters_url=config.get('masters', 'masters-url'), buildbot=config.get('masters', 'buildbot'), sendchange_master=config.get('masters', 'sendchange-master'), publisher=JobRequestDonePublisher(amqp_config), branches_url=config.get('branches', 'url'), clobberer_url=config.get('clobberer', 'url'), ) consumer = JobRequestConsumer(amqp_config) consumer.register_callback(agent.receive_message) if options.wait: try: consumer.run() except KeyboardInterrupt: # Let this go without a fuss pass else: consumer.run_until_idle()
class ConfigStore(object): def __init__(self, name): self.config = RawConfigParser() self.file_opts = {} if sys.version_info[0] >= 3: self.file_opts['encoding'] = 'utf-8' if hasattr(appdirs, 'user_config_dir'): data_dir = appdirs.user_config_dir('photini') else: data_dir = appdirs.user_data_dir('photini') if not os.path.isdir(data_dir): os.makedirs(data_dir, mode=0700) self.file_name = os.path.join(data_dir, '%s.ini' % name) if name == 'editor': for old_file_name in (os.path.expanduser('~/photini.ini'), os.path.join(data_dir, 'photini.ini')): if os.path.exists(old_file_name): self.config.read(old_file_name, **self.file_opts) self.save() os.unlink(old_file_name) self.config.read(self.file_name, **self.file_opts) self.timer = QtCore.QTimer() self.timer.setSingleShot(True) self.timer.setInterval(3000) self.timer.timeout.connect(self.save) self.has_section = self.config.has_section def get(self, section, option, default=None): if self.config.has_option(section, option): result = self.config.get(section, option) if sys.version_info[0] < 3: return result.decode('utf-8') return result if default is not None: self.set(section, option, default) return default def set(self, section, option, value): if not self.config.has_section(section): self.config.add_section(section) if (self.config.has_option(section, option) and self.config.get(section, option) == value): return if sys.version_info[0] < 3: value = value.encode('utf-8') self.config.set(section, option, value) self.timer.start() def remove_section(self, section): if not self.config.has_section(section): return for option in self.config.options(section): self.config.remove_option(section, option) self.config.remove_section(section) self.timer.start() def save(self): self.config.write(open(self.file_name, 'w', **self.file_opts)) os.chmod(self.file_name, 0600)
def load(self): obj = self.obj p = RawConfigParser() try: p.read([self.file]) except MissingSectionHeaderError: # Oops, probably the old file format. self._loadv1() return lvPairs = [] metadata = {} dictDigesters = { "str": lambda x: x, "no": lambda x: x, "int": int, "float": float, "yes": lambda x: x == "True", "bool": lambda x: x == "True" } for sect in p.sections(): opts = p.options(sect) if sect == "_GLOBALS": for lab in opts: val = p.get(sect, lab) lvPairs.append((lab, val)) elif sect.startswith("_METADATA "): attrName = sect[10:] localMdata = {} for lab in opts: val = p.get(sect, lab) # Let's record the type. Let's allow # strings, booleans, ints, floats. # For backward compatibility, "no" # means string, "yes" means boolean # when we read. toks = val.split(None, 1) if len(toks) == 2: localMdata[lab] = (dictDigesters[toks[0]], toks[1]) metadata[attrName] = localMdata else: # Construct a dictionary. d = {} for lab in opts: d[lab] = p.get(sect, lab) lvPairs.append((sect, d)) for lab, val in lvPairs: if metadata.has_key(lab): for k, (digester, trueK) in metadata[lab].items(): v = val[k] del val[k] val[trueK] = digester(v) if self.attrDict.has_key(lab): attrName, readF, writeF = self.attrDict[lab] if readF is not None: readObj = readF(obj, val) else: readObj = val if readObj is not None: setattr(obj, attrName, readObj)
def parse_config_files(self, filenames=None): if filenames is None: filenames = self.find_config_files() log.debug("Distribution.parse_config_files():") parser = RawConfigParser() for filename in filenames: log.debug(" reading %s" % filename) parser.read(filename) if os.path.split(filename)[-1] == 'setup.cfg': self._read_metadata(parser) for section in parser.sections(): options = parser.options(section) opt_dict = self.dist.get_option_dict(section) for opt in options: if opt != '__name__': val = parser.get(section, opt) opt = opt.replace('-', '_') # XXX this is not used ... # Hooks use a suffix system to prevent being overriden # by a config file processed later (i.e. a hook set in # the user config file cannot be replaced by a hook # set in a project config file, unless they have the # same suffix). if (opt.startswith("pre_hook.") or opt.startswith("post_hook.")): hook_type, alias = opt.split(".") hook_dict = opt_dict.setdefault(hook_type, (filename, {}))[1] hook_dict[alias] = val else: opt_dict[opt] = (filename, val) # Make the RawConfigParser forget everything (so we retain # the original filenames that options come from) parser.__init__() # If there was a "global" section in the config file, use it # to set Distribution options. if 'global' in self.dist.command_options: for (opt, (src, val)) in self.dist.command_options['global'].items(): alias = self.dist.negative_opt.get(opt) try: if alias: setattr(self.dist, alias, not strtobool(val)) elif opt in ('verbose', 'dry_run'): # ugh! setattr(self.dist, opt, strtobool(val)) else: setattr(self.dist, opt, val) except ValueError, msg: raise DistutilsOptionError(msg)
class AUSConfig(object): required_options = {"logging": ["logfile"], "database": ["dburi"]} # Originally, this was done with getattr(logging, level), but it seems bad # to look up, and possibly return, arbitrary keys from a config file so it # was replaced with this simple mapping. loglevels = {"DEBUG": logging.DEBUG, "INFO": logging.INFO, "WARNING": logging.WARNING, "ERROR": logging.ERROR, "CRITICAL": logging.CRITICAL} def __init__(self, filename): self.cfg = RawConfigParser() self.cfg.read(filename) def validate(self): errors = [] for section, options in self.required_options.items(): if not self.cfg.has_section(section): errors.append("Missing section '%s'" % section) for opt in options: if not self.cfg.has_option(section, opt): errors.append("Missing option '%s' from section '%s'" % (opt, section)) return errors def getLogfile(self): return self.cfg.get("logging", "logfile") def getLogLevel(self): try: return self.loglevels[self.cfg.get("logging", "level")] # NoOptionError is raised when we can't find the level in the config. # KeyError is raised when we can't find it in the mapping. except (NoOptionError, KeyError): return logging.WARNING def getDburi(self): return self.cfg.get("database", "dburi") def getDomainWhitelist(self): # the config should have a format like this # domain_whitelist = download.mozilla.org:Firefox|Fennec|Thunderbird, ftp.mozilla.org:SystemAddons try: whitelist_config = dict() pref = self.cfg.get("site-specific", "domain_whitelist").split(", ") for domain_pref in pref: domain, products = domain_pref.split(":") products = products.split("|") whitelist_config[domain] = tuple(products) return whitelist_config except (NoSectionError, NoOptionError): return dict() def getCaches(self): caches = {} if self.cfg.has_section("caches"): for cache_name in self.cfg.options("caches"): size, timeout = self.cfg.get("caches", cache_name).split(",") caches[cache_name] = (int(size), int(timeout)) return caches
def read_config(self, path): config = RawConfigParser() config.optionxform = lambda s: s config.read(path) return self.update( (x, dict( (y, config.get(x, y)) for y in config.options(x))) for x in config.sections())
class AUSConfig(object): required_options = {"logging": ["logfile"], "database": ["dburi"]} # Originally, this was done with getattr(logging, level), but it seems bad # to look up, and possibly return, arbitrary keys from a config file so it # was replaced with this simple mapping. loglevels = { "DEBUG": logging.DEBUG, "INFO": logging.INFO, "WARNING": logging.WARNING, "ERROR": logging.ERROR, "CRITICAL": logging.CRITICAL, } def __init__(self, filename): self.cfg = RawConfigParser() self.cfg.read(filename) def validate(self): errors = [] for section, options in self.required_options.items(): if not self.cfg.has_section(section): errors.append("Missing section '%s'" % section) for opt in options: if not self.cfg.has_option(section, opt): errors.append("Missing option '%s' from section '%s'" % (opt, section)) return errors def getLogfile(self): return self.cfg.get("logging", "logfile") def getLogLevel(self): try: return self.loglevels[self.cfg.get("logging", "level")] # NoOptionError is raised when we can't find the level in the config. # KeyError is raised when we can't find it in the mapping. except (NoOptionError, KeyError): return logging.WARNING def getDburi(self): return self.cfg.get("database", "dburi") def getDomainWhitelist(self): try: return tuple(a.strip() for a in self.cfg.get("site-specific", "domain_whitelist").split(",")) except (NoSectionError, NoOptionError): return tuple() def getCaches(self): caches = {} if self.cfg.has_section("caches"): for cache_name in self.cfg.options("caches"): size, timeout = self.cfg.get("caches", cache_name).split(",") caches[cache_name] = (int(size), int(timeout)) return caches
def go(self): options = self.get_options() if options.config is not None: logger.info('Reading configuration from %s' % options.config) logger.warn('Other options from command line will be ignored. ') parser = RawConfigParser() parser.read(options.config) sections = parser.sections() logger.info('sections: %s' % sections) s = 'app:main' if not s in sections: msg = 'Could not find section "%s": available are %s.' % ( s, format_list(sections)) msg += '\n file %s' % options.config raise Exception(msg) # XXX settings = dict((k, parser.get(s, k)) for k in parser.options(s)) prefix = 'mcdp_web.' mcdp_web_settings = get_only_prefixed(settings, prefix, delete=True) # mcdp_web_settings = {} # for k,v in list(settings.items()): # if k.startswith(prefix): # mcdp_web_settings[k[len(prefix):]] = v # del settings[k] options = parse_mcdpweb_params_from_dict(mcdp_web_settings) logger.debug('Using these options: %s' % options) else: logger.info('No configuration .ini specified (use --config).') settings = {} wa = WebApp(options, settings=settings) # Write warning messages now wa.get_authomatic_config() msg = """Welcome to PyMCDP! To access the interface, open your browser at the address http://localhost:%s/ Use Chrome, Firefox, or Opera - Internet Explorer is not supported. """ % options.port logger.info(msg) if options.delete_cache: pass # XXX: warning deprecated # logger.info('Deleting cache...') # wa._refresh_library(None) wa.serve(port=options.port)
def walkOnStorageDirectory(self, **kwargs): """Walk on storage directory""" # Get all paths to walk on paths = [] root_path = os.path.abspath(self.storage_path) for root, dirs, files in os.walk(root_path): if dirs: # We have reached last level continue paths.append(root) items = [] for path in paths: # Get config files cfg_path = os.path.join(path, self.cfg_filename) if not os.path.exists(cfg_path): continue # Update file config = RawConfigParser() # Read file fd = open(cfg_path, 'r') try: config.readfp(fd) finally: fd.close() obj_path = path[(len(root_path) + 1):] if sys.platform == 'win32': obj_path = obj_path.replace('\\', '/') names = config.options(self.cfg_filename_section) # Get filenames for name in names: filename = config.get(self.cfg_filename_section, name) file_path = os.path.join(path, filename) modified = os.path.getmtime(file_path) size = os.path.getsize(file_path) # Store item item = {} item['path'] = obj_path item['name'] = name item['fs_path'] = file_path item['modified'] = DateTime(modified) item['size'] = size items.append(item) return items
class _Configuration(object): def __init__(self): self.conf_dir = os.path.expanduser("~/.bullstock") self.user_conf = os.path.join(self.conf_dir, "config.ini") if not os.path.exists(self.conf_dir): os.mkdir(self.conf_dir) self.config = RawConfigParser() read = self.config.read([self.user_conf, GLOBAL_CONFIG]) if not read: default = StringIO(INITIAL_CONFIG) self.config.readfp(default) default.close() def _get_section(self, type_, name): if type_: section = "%s:%s" % (type_, name) else: section = name ret = {} if not self.config.has_section(section): return ret c = self.config methods = (c.getint, c.getfloat, c.getboolean, c.get) for option in self.config.options(section): for method in methods: try: ret[option] = method(section, option) break except ValueError: pass return ret def set(self, section, option, value): self.config.set(section, option, value) self.save() def save(self): f = open(self.user_conf, "w") self.config.write(f) f.close() def plugin(self, plugin): return self._get_section(plugin.plugin_type, plugin.name) @property def global_conf(self): return self._get_section("", "GLOBAL")
def load(config_files): global config config = {} cp = RawConfigParser() cp.read(config_files) for section in cp.sections(): if config.get(section, None) == None: config[section] = {} for option in cp.options(section): config[section][option] = cp.get(section, option) #.strip()
def walkOnStorageDirectory(self, **kwargs): """Walk on storage directory""" # Get all paths to walk on paths = [] root_path = os.path.abspath(self.storage_path) for root, dirs, files in os.walk(root_path): if dirs: # We have reached last level continue paths.append(root) items = [] for path in paths: # Get config files cfg_path = os.path.join(path, self.cfg_filename) if not os.path.exists(cfg_path): continue # Update file config = RawConfigParser() # Read file fd = open(cfg_path, 'r') try: config.readfp(fd) finally: fd.close() obj_path = path[(len(root_path) + 1):] if sys.platform == 'win32': obj_path = obj_path.replace('\\', '/') names = config.options(self.cfg_filename_section) # Get filenames for name in names: filename = config.get(self.cfg_filename_section, name) file_path = os.path.join(path, filename) modified = os.path.getmtime(file_path) size = os.path.getsize(file_path) # Store item item = {} item['path'] = obj_path item['name'] = name item['fs_path'] = file_path item['modified'] = DateTime(modified) item['size'] = size items.append(item) return items
def load(config_files): global config config = {} cp = RawConfigParser() cp.read(config_files) for section in cp.sections(): if config.get(section, None) == None: config[section] = {} for option in cp.options(section): config[section][option] = cp.get(section, option) #.strip()
def loadValues(self): '''Read values of options from file.''' config = RawConfigParser() config.read(self.filename) sections = config.sections() for section in sections: if self.hasSection(section): options = config.options(section) for option in options: if self.hasOption(section, option): self.setValue(section, option, config.get(section, option))
def parse_package_metadata(): """ Read the 'metadata' section of 'setup.cfg' to calculate the package metadata (at least those parts that can be configured staticly). """ try: from ConfigParser import RawConfigParser except ImportError: from configparser import RawConfigParser cfg = RawConfigParser() cfg.optionxform = lambda x: x if sys.version_info.major == 2: with open('setup.cfg') as fp: cfg.readfp(fp) else: with open('setup.cfg') as fp: cfg.read_file(fp) metadata = {} for opt in cfg.options('x-metadata'): val = cfg.get('x-metadata', opt) if opt in ('classifiers',): metadata[opt] = [x for x in val.splitlines() if x] elif opt in ('long_description',): # In python 2.7 empty lines in the long description are handled incorrectly, # therefore setup.cfg uses '$' at the start of empty lines. Remove that # character from the description val = val[1:] val = val.replace('$', '') metadata[opt] = val # Add links to interesting location to the long_description metadata[opt] += "\n\nProject links\n" metadata[opt] += "-------------\n" metadata[opt] += "\n" metadata[opt] += "* `Documentation <https://pyobjc.readthedocs.io/en/latest/>`_\n\n" metadata[opt] += "* `Issue Tracker <https://bitbucket.org/ronaldoussoren/pyobjc/issues?status=new&status=open>`_\n\n" metadata[opt] += "* `Repository <https://bitbucket.org/ronaldoussoren/pyobjc/>`_\n\n" elif opt in ('packages', 'namespace_packages', 'platforms', 'keywords'): metadata[opt] = [x.strip() for x in val.split(',')] elif opt in ['zip-safe']: metadata['zip_safe'] = int(val) else: metadata[opt] = val metadata['version'] = package_version() return metadata
def options(self, section): """Returns a section's options. :param section: the name of the section whose options are to be returned :type section: string :rtype: list of strings :returns: a list of strings representing the names of the options """ return RCP.options(self, section)
def load_from_file(self, path): """ Load the INI file into the instance. path -- a string of path to the INI file. """ schema = self.schema # Set up the default values. if schema is not None: for sect, sect_obj in schema.items(): for opt, val in sect_obj.items(): # This call is to convert the value to # the type specified. We do this to # prevent the programmer from specifying # inconsistent type with the value in the # schema. self.set(*_convert(schema, sect, opt, val[1])) # Parse the INI file. parser = RawConfigParser() parser.read(path) sections = parser.sections() for section in sections: # If application has supplied a schema, # and it does not has such a section, we skip # it. No error raised. if schema is not None and \ not schema.has_key(section): continue options = parser.options(section) for option in options: # If application has supplied a schema, # we know the section is valid since it pass the # previus test, but if the option is not included # in the section, we skip it. No error raised. if schema is not None and \ (option not in schema[section]): continue # If there is a schema, then we convert the # option to its type stated in the schema, # otherwise we just leave it as string. if schema is not None: self.set(*_convert(schema, section, option, parser.get(section, option))) else: self.set(section, option, parser.get(section, option))
def load_values(self): """Read values of options from file.""" config = RawConfigParser() config.read(self.filename) sections = config.sections() for section in sections: if self.has_section(section): options = config.options(section) for option in options: if self.has_option(section, option): self.set_value(section, option, config.get(section, option))
def load_values(self): """Read values of options from file.""" config = RawConfigParser() config.read(self.filename) sections = config.sections() for section in sections: if self.has_section(section): options = config.options(section) for option in options: if self.has_option(section, option): self.set_value( section, option, config.get(section, option))
def parse_package_metadata(): """ Read the 'metadata' section of 'setup.cfg' to calculate the package metadata (at least those parts that can be configured staticly). """ try: from ConfigParser import RawConfigParser except ImportError: from configparser import RawConfigParser cfg = RawConfigParser() cfg.optionxform = lambda x: x with open("setup.cfg") as fp: cfg.read_file(fp) metadata = {} for opt in cfg.options("x-metadata"): val = cfg.get("x-metadata", opt) if opt in ("classifiers", ): metadata[opt] = [x for x in val.splitlines() if x] elif opt in ("long_description", ): # In python 2.7 empty lines in the long description are handled incorrectly, # therefore setup.cfg uses '$' at the start of empty lines. Remove that # character from the description val = val[1:] val = val.replace("$", "") metadata[opt] = val # Add links to interesting location to the long_description metadata[opt] += "\n\nProject links\n" metadata[opt] += "-------------\n" metadata[opt] += "\n" metadata[ opt] += "* `Documentation <https://pyobjc.readthedocs.io/en/latest/>`_\n\n" metadata[ opt] += "* `Issue Tracker <https://github.com/ronaldoussoren/pyobjc/issues>`_\n\n" metadata[ opt] += "* `Repository <https://github.com/ronaldoussoren/pyobjc/>`_\n\n" elif opt in ("packages", "namespace_packages", "platforms", "keywords"): metadata[opt] = [x.strip() for x in val.split(",")] elif opt in ["zip-safe"]: metadata["zip_safe"] = int(val) else: metadata[opt] = val metadata["version"] = package_version() return metadata
def commandRestore(self, parts, fromloc, overriderank): "/restore worldname number - Op\nRestore world to indicated number." if len(parts) < 2: self.client.sendServerMessage("Please specify at least a world ID!") else: world_id = parts[1].lower() world_dir = ("worlds/%s/" % world_id) if not self.client.isModPlus(): # ensure user has proper rank in the target world (the check to run this command only counts the world they're currently in) canRestore = False config = ConfigParser() config.read(world_dir+"world.meta") # this still has an issue: it won't pick up recent rank changes that haven't been flushed to the file yet. but it's good enough in geneal. if config.has_section("owner"): print config.get("owner", "owner") if config.get("owner", "owner").lower() == self.client.username.lower(): canRestore = True if config.has_section("ops"): for op in config.options("ops"): print op if op.lower() == self.client.username.lower(): canRestore = True if not canRestore: self.client.sendServerMessage("You are not allowed to restore that world!") return if len(parts) < 3: try: backups = os.listdir(world_dir+"backup/") except: self.client.sendServerMessage("Syntax: /restore worldname number") return backups.sort(lambda x, y: int(x) - int(y)) backup_number = str(int(backups[-1])) else: backup_number = parts[2] if not os.path.exists(world_dir+"backup/%s/" % backup_number): self.client.sendServerMessage("Backup %s does not exist." % backup_number) else: if not os.path.exists(world_dir+"blocks.gz.new"): shutil.copy(world_dir+"backup/%s/blocks.gz" % backup_number, world_dir) try: shutil.copy(world_dir+"backup/%s/world.meta" % backup_number, world_dir) os.remove(world_dir+"blocks.db") # remove blocktracker data since it's no longer valid except: pass else: reactor.callLater(1, self.commandRestore(self, parts, fromloc, overriderank)) default_name = self.client.factory.default_name self.client.factory.unloadWorld("worlds/%s" % world_id, world_id) self.client.sendServerMessage("%s has been restored to %s and booted." % (world_id, backup_number)) if world_id in self.client.factory.worlds: for client in self.client.factory.worlds[world_id].clients: client.changeToWorld(world_id)
def _read_configuration_file(self, path): """Try to read and parse `path` as a configuration file. If the configurations were illegal (checked with `self._validate_options`), raises `IllegalConfiguration`. Returns (options, should_inherit). """ parser = RawConfigParser() options = None should_inherit = True if parser.read(path) and self._get_section_name(parser): option_list = dict([(o.dest, o.type or o.action) for o in self._parser.option_list]) # First, read the default values new_options, _ = self._parse_args([]) # Second, parse the configuration section_name = self._get_section_name(parser) for opt in parser.options(section_name): if opt == 'inherit': should_inherit = parser.getboolean(section_name, opt) continue if opt.replace('_', '-') not in self.CONFIG_FILE_OPTIONS: log.warning("Unknown option '{}' ignored".format(opt)) continue normalized_opt = opt.replace('-', '_') opt_type = option_list[normalized_opt] if opt_type in ('int', 'count'): value = parser.getint(section_name, opt) elif opt_type == 'string': value = parser.get(section_name, opt) else: assert opt_type in ('store_true', 'store_false') value = parser.getboolean(section_name, opt) setattr(new_options, normalized_opt, value) # Third, fix the set-options options = self._fix_set_options(new_options) if options is not None: if not self._validate_options(options): raise IllegalConfiguration('in file: {}'.format(path)) return options, should_inherit
def _read_configuration_file(self, path): """Try to read and parse `path` as a configuration file. If the configurations were illegal (checked with `self._validate_options`), raises `IllegalConfiguration`. Returns (options, should_inherit). """ parser = RawConfigParser() options = None should_inherit = True if parser.read(path) and self._get_section_name(parser): option_list = dict([(o.dest, o.type or o.action) for o in self._parser.option_list]) # First, read the default values new_options, _ = self._parse_args([]) # Second, parse the configuration section_name = self._get_section_name(parser) for opt in parser.options(section_name): if opt == 'inherit': should_inherit = parser.getboolean(section_name, opt) continue if opt.replace('_', '-') not in self.CONFIG_FILE_OPTIONS: log.warning("Unknown option '{}' ignored".format(opt)) continue normalized_opt = opt.replace('-', '_') opt_type = option_list[normalized_opt] if opt_type in ('int', 'count'): value = parser.getint(section_name, opt) elif opt_type == 'string': value = parser.get(section_name, opt) else: assert opt_type in ('store_true', 'store_false') value = parser.getboolean(section_name, opt) setattr(new_options, normalized_opt, value) # Third, fix the set-options options = self._fix_set_options(new_options) if options is not None: if not self._validate_options(options): raise IllegalConfiguration('in file: {}'.format(path)) return options, should_inherit
def _get_config_from_file(self, filename, section): """Return, as a dictionary, all the available configuration inside the sprite configuration file on this sprite path.""" def clean(value): return {'true': True, 'false': False}.get(value.lower(), value) config = RawConfigParser() config.read(os.path.join(self.config_path, filename)) try: keys = config.options(section) except NoSectionError: return {} return dict([[k, clean(config.get(section, k))] for k in keys])
def read_config(self): """Parse the configuration file and determine the runtime configuration. """ self.acquire_lock() self.config_file = self.find_config_file() if self.config_file and os.path.exists(self.config_file): config = RawConfigParser(self.config) config.read(self.config_file) # Iterate over the config file options and write them into self.config for section in config.sections(): for option in config.options(section): value = config.get(section, option) # Coerce values into useful datatypes if value.lower() in ['1', 'yes', 'true', 'on']: value = True elif value.lower() in ['0', 'no', 'false', 'none', 'off']: value = False elif value.replace('.', '').isdigit(): if '.' in value: value = Decimal(value) else: value = int(value) self.config[section][option] = value # Fold the CLI args into self.config for argument in vars(self.args): if argument in ('subparsers', 'entrypoint'): continue if '_' in argument: section, option = argument.split('_', 1) else: section = self._entrypoint.__name__ option = argument if option not in self.arg_only: if hasattr(self.args_passed, argument): arg_value = getattr(self.args, argument) if arg_value: self.config[section][option] = arg_value else: if option not in self.config[section]: self.config[section][option] = getattr( self.args, argument) self.release_lock()
def read_config_file(location=None): """ 初始化配置管理 """ cfg = ConfigParser() if location: cfg.read(location) else: local_dir = os.path.dirname(os.path.realpath(__file__)) cfg.read(os.path.join(local_dir, 'config.cfg')) global CONFIG for section in cfg.sections(): CONFIG[section] = {} for option in cfg.options(section): CONFIG[section][option] = cfg.get(section, option) return CONFIG
def load_data(fn): """Load meeting data from INI-style data file.""" parser = RawConfigParser() parser.read(fn) data = {} for section in ('general', 'meeting'): if parser.has_section(section): data.update( dict( (k, decode(v, 'utf-8')) for k, v in parser.items(section))) data['date'] = datetime.strptime(data['date'], '%Y-%m-%d %H:%M') data['agenda'] = [ decode(parser.get('agenda', o), 'utf-8').split(';') for o in sorted(parser.options('agenda')) ] return data
def load(self, paths=()): config_parser = RawConfigParser() loaded = config_parser.read(self.write_path) loaded += config_parser.read(paths) if config_parser.has_option("Internal", "version"): version = config_parser.get("Internal", "version") elif loaded: version = "0.3" else: version = CONFIG_VERSION if SW.Version(version) < SW.Version(CONFIG_VERSION): self.upgrade(config_parser, SW.Version(version)) for section_name in config_parser.sections(): if section_name not in self.sections: dprint(WARNING, "Skipping unknown section '%s'" % section_name) continue section = self.sections[section_name] for option in config_parser.options(section_name): if option not in section.items: dprint( WARNING, "Skipping unknown item '%s.%s'" % (section_name, option)) continue if option in section.lazy_items: section.lazy_items.remove(option) type_reader = { str: config_parser.get, bool: config_parser.getboolean, int: config_parser.getint, float: config_parser.getfloat, "pickle": lambda x, y: pickle.loads(config_parser.get(x, y)) }[section.item_types[option]] section[option] = type_reader(section_name, option) self["Internal"]["version"] = CONFIG_VERSION
def get_options(args, opt_parser): config = RawConfigParser() parent = tail = os.path.abspath(os.path.commonprefix(args)) config_found = False while tail and not config_found: log.info(tail) for fn in PROJECT_CONFIG: full_path = os.path.join(parent, fn) if config.read(full_path): log.info('local configuration: in %s.', full_path) config_found = True break parent, tail = os.path.split(parent) new_options = None if config.has_section('pep257'): option_list = dict([(o.dest, o.type or o.action) for o in opt_parser.option_list]) # First, read the default values new_options, _ = opt_parser.parse_args([]) # Second, parse the configuration pep257_section = 'pep257' for opt in config.options(pep257_section): if opt.replace('_', '-') not in opt_parser.config_options: log.warning("Unknown option '{}' ignored".format(opt)) continue normalized_opt = opt.replace('-', '_') opt_type = option_list[normalized_opt] if opt_type in ('int', 'count'): value = config.getint(pep257_section, opt) elif opt_type == 'string': value = config.get(pep257_section, opt) else: assert opt_type in ('store_true', 'store_false') value = config.getboolean(pep257_section, opt) setattr(new_options, normalized_opt, value) # Third, overwrite with the command-line options options, _ = opt_parser.parse_args(values=new_options) log.debug("options: %s", options) return options
def _confglobs(self): """get a list of patterns that match text files from the svn config """ config = RawConfigParser() config.optionxform = lambda x: x # stock parser is case-insensitive config.read(os.path.expanduser('~/.subversion/config')) if not config.has_section('auto-props'): print 'your subversion config file has no auto-props section' sys.exit(1) autoprops = config.options('auto-props') globs = Set() for pattern in autoprops: if 'svn:eol-style' in config.get('auto-props', pattern): globs.add(pattern) globs = list(globs) globs.sort() return globs