def __init__(self): SafeConfigParser.__init__(self) self.eval_globals = None self.eval_locals = None
def __init__(self, *args, **kwargs): SafeConfigParser.__init__(self, *args, **kwargs) self.optionxform = str # keep upper case self.lock = RLock() for member in dir(self): if member.startswith("_") or member in ['Lock', 'Unlock']: continue method = getattr(self, member) if callable(method): def decorator(func): @wraps(func) def locker(*args, **kwargs): self.Lock() try: ret = func(*args, **kwargs) return ret finally: self.Unlock() return locker pass setattr(self, member, decorator(method)) self._setDefaults()
def __init__(self, name): """Read and parse the global and local configs. @param name: The name of the model directory. e.g. 'themeClassifier'. """ SafeConfigParser.__init__(self) # Make keys within a section case-sensitive, so that keys are not # forced to lowercase when added to a section. This is the solution # recommended in ConfigParser documentation, without need to subclass. self.optionxform = str # The model directory for this specific model. self.modelDir = os.path.join(APP_DIR, 'models', name) assert os.path.exists(self.modelDir), ( "Cannot find directory: `{name}`. Full path: {path}".format( name=name, path=self.modelDir)) # Create full paths to model conf files, for config parsing to work # properly. Only the first file needs to exist. confPaths = [ os.path.join(self.modelDir, x) for x in self.__class__.CONF_NAMES ] assert os.access( confPaths[0], os.R_OK), ("Cannot read config file: `{0}`. Full path: {1}".format( self.__class__.CONF_NAMES[0], confPaths[0])) self.read(confPaths)
def __init__(self, app_name, defaults={}, filename=None): SafeConfigParser.__init__(self) # First setup default values for apps specified # by the call to the contructor self.set_config_section(app_name, defaults) self.config_dir = config_dir = path.join(basedir.xdg_config_home, 'laditools') if not filename: filename = app_name + '.conf' self.config_filename = config_filename = path.join( config_dir, filename) if not exists(config_dir): mkdir(config_dir, 0o755) try: self.read(config_filename) except MissingSectionHeaderError: if yaml: if self._migrate_configuration() == 0: self.save() else: # new empty file pass # go on otherwise except: raise MalformedConfigError()
def __init__ (self, app_name, defaults = {}, filename = None): SafeConfigParser.__init__(self) # First setup default values for apps specified # by the call to the contructor self.set_config_section(app_name, defaults) self.config_dir = config_dir = path.join(basedir.xdg_config_home, 'laditools') if not filename: filename = app_name + '.conf' self.config_filename = config_filename = path.join(config_dir, filename) if not exists (config_dir): mkdir (config_dir, 0o755) try: self.read(config_filename) except MissingSectionHeaderError: if yaml: if self._migrate_configuration() == 0: self.save() else: # new empty file pass # go on otherwise except: raise MalformedConfigError()
def __init__(self, filename): """Create a new SecureConfigParser. String filename specifies the configuration file to write any changes to. """ SafeConfigParser.__init__(self) self.filename = filename return (None)
def __init__(self): if sys.version_info > (2, 6) and sys.version_info < (2, 7): # only for Python2.6 # - dict_type argument is supported py2.6 or later # - SafeConfigParser of py2.7 uses OrderedDict as default from ordereddict import OrderedDict SafeConfigParser.__init__(self, dict_type=OrderedDict) else: SafeConfigParser.__init__(self)
def __init__(self, conf_path=None): """ raise: Exception when config file not exist """ SafeConfigParser.__init__( self, allow_no_value=True, inline_comment_prefixes='#') # SafeConfigParser继承ConfigParser if conf_path: if not os.path.exists(conf_path): raise Exception('conf file: %s not exist' % conf_path) self.read(conf_path)
def __init__(self, config): SafeConfigParser.__init__(self) if not os.path.exists(os.path.dirname(config)): os.makedirs(os.path.dirname(config)) self.configfile = config try: self.read(self.configfile) except: # don't crash on a corrupted config file pass
def __init__(self, config): SafeConfigParser.__init__(self) if not os.path.exists(os.path.dirname(config)): os.makedirs(os.path.dirname(config)) # we always want this section, even on fresh installs self.add_section("general") # read the config self.configfile = config try: self.read(self.configfile) except: # don't crash on a corrupted config file pass
def __init__(self,path): # one config ought to be enough for everyone ConfigParser.__init__(self) if path is not None: self.read([path]) for s,kv in self.defaults.items(): # set default values into config if not self.has_section(s): self.add_section(s) for k, v in kv.items(): if not self.has_option(s,k): self.set(s,k,v)
def __init__(self, configfile=None): SafeConfigParser.__init__(self) self.__add_defaults() configfiles = [] # Add the filename for the config file in the modules # directory self.opengrid_libdir = os.path.dirname( os.path.abspath(inspect.getfile(inspect.currentframe()))) configfiles.append(os.path.join(self.opengrid_libdir, 'opengrid.cfg')) # Add the filename for the config file in the 'current' directory configfiles.append('opengrid.cfg') # Add the filename for the config file passed in if configfile: configfiles.append(configfile) self.read(configfiles)
def __init__(self, initialiser): """ Create a new parameter set from a file or string. """ SafeConfigParser.__init__(self) try: if os.path.exists(initialiser): self.read(initialiser) self.source_file = initialiser else: input = StringIO(str(initialiser)) # configparser has some problems with unicode. Using str() is a crude, and probably partial fix. input.seek(0) self.readfp(input) except MissingSectionHeaderError: raise SyntaxError("Initialiser contains no section headers")
def __init__(self, config): SafeConfigParser.__init__(self) from utils import safe_makedirs safe_makedirs(os.path.dirname(config)) # we always want this section, even on fresh installs self.add_section("general") # read the config self.configfile = config try: self.read(self.configfile) except Exception as e: # don't crash on a corrupted config file LOG.warn("Could not read the config file '%s': %s", self.configfile, e) pass
def __init__(self, configfile=None): SafeConfigParser.__init__(self) self.__add_defaults() configfiles = [] # Add the filename for the config file in the modules # directory self.opengrid_libdir = os.path.dirname(os.path.abspath( inspect.getfile(inspect.currentframe()))) configfiles.append(os.path.join(self.opengrid_libdir, 'opengrid.cfg')) # Add the filename for the config file in the 'current' directory configfiles.append('opengrid.cfg') # Add the filename for the config file passed in if configfile: configfiles.append(configfile) self.read(configfiles)
def __init__(self, cqs_home=None): if cqs_home is None: cqs_home = os.path.join(os.path.expanduser("~"),'.cassandra-quickstart') self.__cqs_home = cqs_home self.__cfg_path = os.path.join(cqs_home, 'config') if self.__cfg_path in self.__instances.keys(): raise ValueError("Config already open for {cqs_home}. Use Config.open() instead.".format(cfg_path=self.__cqs_home)) SafeConfigParser.__init__(self) self.read(self.__cfg_path) for s in self.default_sections: self.add_section(s) self.__instances[self.__cqs_home] = self
def __init__(self, request): # Note that SafeConfigParser if not a new class so we have to # explicitly call the __init__ method SafeConfigParser.__init__(self) try: host = request.session['host'] username = request.session['username'] user_conf = os.path.join(USERCONFDIR, '%s@%s.conf' % (username, host)) if not os.path.isfile(user_conf): # Touch the user conf file open(user_conf, 'w').close() server_conf = os.path.join(SERVERCONFDIR, '%s.conf' % host) config_files = [ FACTORYCONF, DEFAULTCONF, user_conf, server_conf, SYSTEMCONF ] except KeyError: config_files = [FACTORYCONF, DEFAULTCONF] self.read(config_files)
def __init__(self, configfilename=None): CP.__init__(self) filename = os.environ.get( 'PYPS_CONFIG', os.path.join(os.path.expanduser("~"), ".pyps")) if configfilename is not None: filename = configfilename if not os.path.isfile(filename): raise Exception( "No valid pyps config found ($PYPS_CONFIG: %s, %s: %s, configfilename: %s)" % ('PYPS_CONFIG' in os.environ, os.path.join(os.path.expanduser("~"), ".pyps"), os.path.isfile(os.path.join(os.path.expanduser("~"), ".pyps")), configfilename)) self.filename = filename self.read(filename)
def __init__(self): """Read and parse the global and local configs.""" SafeConfigParser.__init__(self) appDir = APP_DIR confDir = os.path.join(appDir, 'etc') # Create absolute paths to files for config parsing to work properly # when running as daemon. Only the first file needs to exist. confPaths = [ os.path.join(confDir, x) for x in self.__class__.CONF_NAMES ] assert os.access(confPaths[0], os.R_OK), ('Cannot read config file: `{0}`.'.format( confPaths[0])) self.read(confPaths) # Set the value of the config object on app start. Any references to # `%(appDir)s` in app conf strings will be interpolated with this # value. self.set('DEFAULT', 'appDir', appDir)
def __init__(self, filenames=None): """Initialization reads settings from config files and env. variables. Parameters ---------- filenames : list of filenames """ SafeConfigParser.__init__(self) # store additional config file names if filenames is not None: self.__cfg_filenames = filenames else: self.__cfg_filenames = [] # set critical defaults for sec, vars in ConfigManager._DEFAULTS.items(): self.add_section(sec) for key, value in vars.items(): self.set(sec, key, value) # now get the setting self.reload()
def __init__(self): """Initialise instance of AppConf class. Read config files in three locations, expecting the first versioned file to always be present and the two optional files to either override the default values or be ignored silently if they are missing. """ SafeConfigParser.__init__(self) # Path to the top-level pathfinder directory in the repo. self.appDir = os.path.abspath(os.path.join(os.path.dirname(__file__), os.path.pardir)) etcConfNames = ('app.conf', 'app.local.conf') confPaths = [os.path.join(self.appDir, 'etc', c) for c in etcConfNames] userConfigPath = os.path.join( os.path.expanduser('~'), '.config', 'pathfinder.conf' ) confPaths.append(userConfigPath) self.read(confPaths)
def __init__(self, filename, *args, **kwargs): SafeConfigParser.__init__(self, *args, **kwargs) self.read(filename)
def __init__(self): SafeConfigParser.__init__(self)
def __init__(self,*args,**kargs): SafeConfigParser.__init__(self,*args,**kargs) self._interpolation = ExtendedInterpolation() self.optionxform = str
def __init__(self): SafeConfigParser.__init__(self) self.localeval = None
def __init__(self): SafeConfigParser.__init__(self) self._load_config()
def __init__(self, defaults = None): SafeConfigParser.__init__(self, defaults)
def __init__(self, Parent): SafeConfigParser.__init__(self) self.Parent = Parent self.confFile = "/etc/torrent-leecher.conf" self.lockFile = "/var/run/daemons/torrent-leecher" self.loadConfigs()
def __init__(self, **kwargs): # Must call this __init__ manually :( ConfigParserOldStyle.__init__(self, **kwargs) super(ConfigParser, self).__init__(**kwargs)
def __init__(self, configFile = None): ObservableSubject.__init__(self) SafeConfigParser.__init__(self) self._configFile = configFile if self._configFile is not None: self.load()
def __init__(self, master=None): SafeConfigParser.__init__(self, master) self.read('config.ini')
def __init__(self, defaults, allow_no_value=False): SafeConfigParser.__init__(self) # apparently self._defaults is used by the default implementation. self._cfp_defaults = defaults self._allow_no_value = allow_no_value
def __init__(self): SafeConfigParser.__init__(self) self.envvarpattern = re.compile('\$(\w+)')
def __init__(self, module, *args, **kwargs): self.module = module self.path = path.join(config_dir, self.module) # PY2 old style class can't use super() SafeConfigParser.__init__(self, *args, **kwargs) self.read(self.path)