def config_from_string(basedir, portnumfile, config_str, _valid_config=None, fpath=None): """ load and validate configuration from in-memory string """ if _valid_config is None: _valid_config = _common_valid_config() if isinstance(config_str, bytes): config_str = config_str.decode("utf-8") # load configuration from in-memory string parser = configutil.get_config_from_string(config_str) configutil.validate_config( "<string>" if fpath is None else fpath.path, parser, _valid_config, ) return _Config( parser, portnumfile, basedir, fpath, _valid_config, )
def config_from_string(basedir, portnumfile, config_str, _valid_config=None): """ load and validate configuration from in-memory string """ if _valid_config is None: _valid_config = _common_valid_config() if isinstance(config_str, bytes): config_str = config_str.decode("utf-8") # load configuration from in-memory string parser = configutil.get_config_from_string(config_str) fname = "<in-memory>" configutil.validate_config(fname, parser, _valid_config) return _Config(parser, portnumfile, basedir, fname)
def read_config(basedir, portnumfile, generated_files=[], _valid_config=None): """ Read and validate configuration. :param unicode basedir: directory where configuration data begins :param unicode portnumfile: filename fragment for "port number" files :param list generated_files: a list of automatically-generated configuration files. :param ValidConfiguration _valid_config: (internal use, optional) a structure defining valid configuration sections and keys :returns: :class:`allmydata.node._Config` instance """ basedir = abspath_expanduser_unicode(ensure_text(basedir)) if _valid_config is None: _valid_config = _common_valid_config() # complain if there's bad stuff in the config dir _error_about_old_config_files(basedir, generated_files) # canonicalize the portnum file portnumfile = os.path.join(basedir, portnumfile) # (try to) read the main config file config_fname = os.path.join(basedir, "tahoe.cfg") try: parser = configutil.get_config(config_fname) except EnvironmentError as e: if e.errno != errno.ENOENT: raise # The file is missing, just create empty ConfigParser. parser = configutil.get_config_from_string(u"") configutil.validate_config(config_fname, parser, _valid_config) # make sure we have a private configuration area fileutil.make_dirs(os.path.join(basedir, "private"), 0o700) return _Config(parser, portnumfile, basedir, config_fname)