def __init__(self, name, default=None, **kw): """Initialization. :param name: Basename for the config file (suffix .ini will be appended). :param default: Default content of the config file. """ self.name = name self.default = default config_dir = kw.pop("config_dir", None) or text_type(DIR) RawConfigParser.__init__(self, kw, allow_no_value=True) if self.default: if PY3: fp = io.StringIO(self.default) else: fp = io.BytesIO(self.default.encode("utf8")) self.readfp(fp) cfg_path = os.path.join(config_dir, name + ".ini") if os.path.exists(cfg_path): assert os.path.isfile(cfg_path) self.read(cfg_path) else: if not os.path.exists(config_dir): try: os.mkdir(config_dir) except OSError: # pragma: no cover # this happens when run on travis-ci, by a system user. pass if os.path.exists(config_dir): with open(cfg_path, "w") as fp: self.write(fp) self.path = Path(cfg_path)
def __init__(self, name, default=None, **kw): """Initialization. :param name: Basename for the config file (suffix .ini will be appended). :param default: Default content of the config file. """ self.name = name self.default = default config_dir = Path(kw.pop('config_dir', None) or DIR) RawConfigParser.__init__(self, kw, allow_no_value=True) if self.default: if PY3: fp = io.StringIO(self.default) else: fp = io.BytesIO(self.default.encode('utf8')) self.readfp(fp) cfg_path = config_dir.joinpath(name + '.ini') if cfg_path.exists(): assert cfg_path.is_file() self.read(cfg_path.as_posix()) else: if not config_dir.exists(): try: config_dir.mkdir() except OSError: # pragma: no cover # this happens when run on travis-ci, by a system user. pass if config_dir.exists(): with open(cfg_path.as_posix(), 'w') as fp: self.write(fp) self.path = cfg_path
def __init__(self, **kw): cfg_path = kw.pop('cfg', None) \ or os.path.join(APP_DIRS.user_config_dir, 'config.ini') cfg_path = os.path.abspath(cfg_path) RawConfigParser.__init__(self) if os.path.exists(cfg_path): assert os.path.isfile(cfg_path) self.read(cfg_path) else: self.add_section('service') for opt in 'url user password'.split(): self.set('service', opt, kw.get(opt, '') or '') self.add_section('logging') self.set('logging', 'level', 'INFO') config_dir = os.path.dirname(cfg_path) if not os.path.exists(config_dir): try: os.makedirs(config_dir) except OSError: # pragma: no cover # this happens when run on travis-ci, by a system user. pass if os.path.exists(config_dir): with open(cfg_path, 'w') as fp: self.write(fp) level = self.get('logging', 'level', default=None) if level: logging.basicConfig(level=getattr(logging, level))
def __init__(self): RawConfigParser.__init__(self) # Set defaults self.add_section('ldap') self.add_section('presence') self.set('ldap', 'server', 'ldap://pan.suse.de') self.set('ldap', 'base', 'o=Novell') self.set('presence', 'servers', 'present.suse.de,bolzano.suse.de/nosend')
def __init__(self, path=None, stream_log_level=None): RawConfigParser.__init__(self) self._clients = {} self.path = path or os.getenv('HDFSCLI_CONFIG', self.default_path) if stream_log_level: stream_handler = lg.StreamHandler() stream_handler.setLevel(stream_log_level) fmt = '%(levelname)s\t%(message)s' stream_handler.setFormatter(lg.Formatter(fmt)) lg.getLogger().addHandler(stream_handler) if osp.exists(self.path): try: self.read(self.path) except ParsingError: raise HdfsError('Invalid configuration file %r.', self.path) else: self._autoload() _logger.info('Instantiated configuration from %r.', self.path) else: _logger.info('Instantiated empty configuration.')
def __init__(self, **kw): config_dir = kw.pop('config_dir', None) or APP_DIRS.user_config_dir RawConfigParser.__init__(self, kw) config_file = kw.pop('config_file', 'config.ini') cfg_path = os.path.join(config_dir, config_file) if os.path.exists(cfg_path): assert os.path.isfile(cfg_path) self.read(cfg_path) else: if not os.path.exists(config_dir): try: os.makedirs(config_dir) except OSError: # pragma: no cover # this happens when run on travis-ci, by a system user. pass if os.path.exists(config_dir): with open(cfg_path, 'w') as fp: self.write(fp) level = self.get('logging', 'level', default=None) if level: logging.basicConfig(level=getattr(logging, level))
def __init__(self, **kw): config_dir = kw.pop('config_dir', None) or APP_DIRS.user_config_dir RawConfigParser.__init__(self, kw) cfg_path = os.path.join(config_dir, 'config.ini') if os.path.exists(cfg_path): assert os.path.isfile(cfg_path) self.read(cfg_path) else: if not os.path.exists(config_dir): try: os.makedirs(config_dir) except OSError: # pragma: no cover # this happens when run on travis-ci, by a system user. pass if os.path.exists(config_dir): with open(cfg_path, 'w') as fp: self.write(fp) level = self.get('logging', 'level', default=None) if level: logging.basicConfig(level=getattr(logging, level))
def __init__(self, **kw): config_dir = kw.pop('config_dir', None) or APP_DIRS.user_config_dir RawConfigParser.__init__(self, kw) cfg_path = os.path.join(config_dir, 'config.ini') if os.path.exists(cfg_path): assert os.path.isfile(cfg_path) self.read(cfg_path) else: if not os.path.exists(config_dir): try: os.makedirs(config_dir) except OSError: # pragma: no cover # this happens when run on travis-ci, by a system user. pass if os.path.exists(config_dir): with open(cfg_path, 'w') as fp: self.write(fp) print("New blanck configuration file generated at %s, please edit to to suit your needs.\ documentation at: %s"%(cfg_path,'http://pyimeji.readthedocs.org/en/latest/tutorial.html')) level = self.get('logging', 'level', default=None) if level: logging.basicConfig(level=getattr(logging, level))
def __init__(self, *args, **kwargs): RawConfigParser.__init__(self, *args, **kwargs) self.filename = None self.callback = None self.lock = RLock()