def read_test(self): conf = AnacondaConfiguration() with tempfile.NamedTemporaryFile("w") as f: conf.read(f.name) self.assertEqual(len(conf.get_sources()), 1) self.assertEqual(conf.get_sources()[0], f.name)
def read_test(self): conf = AnacondaConfiguration() with tempfile.NamedTemporaryFile("w") as f: conf.read(f.name) self.assertEqual(len(conf.get_sources()), 1) self.assertEqual(conf.get_sources()[0], f.name)
def test_read(self): conf = AnacondaConfiguration() with tempfile.NamedTemporaryFile("w") as f: conf.read(f.name) assert len(conf.get_sources()) == 1 assert conf.get_sources()[0] == f.name
def init(log_filename=None, log_stream=sys.stderr): """Do initial configuration of an Anaconda DBus module. This method should be imported and called from __main__.py of every Anaconda DBus module before any other import. :param log_filename: a file for logging or None :param log_stream: a stream for logging or None """ import faulthandler faulthandler.enable() import logging handlers = [] if log_stream: handlers.append(logging.StreamHandler(log_stream)) if log_filename: handlers.append(logging.FileHandler(log_filename)) logging.basicConfig(level=logging.DEBUG, handlers=handlers) import locale from pyanaconda.core.constants import DEFAULT_LANG locale.setlocale(locale.LC_ALL, DEFAULT_LANG) from pyanaconda.core.configuration.anaconda import conf from pyanaconda.anaconda_loggers import get_module_logger log = get_module_logger(__name__) log.debug("The configuration is loaded from: %s", conf.get_sources())
def _write_temporary_config(self): """Create the temporary config file.""" dirname = os.path.dirname(ANACONDA_CONFIG_TMP) if not os.path.exists(dirname): os.makedirs(dirname) log.info("Writing a temporary configuration loaded from: %s", conf.get_sources()) conf.write(ANACONDA_CONFIG_TMP)
def init(): """Do initial configuration of an Anaconda DBus module. This method should be imported and called from __main__.py of every Anaconda DBus module before any other import. """ import logging logging.basicConfig(level=logging.DEBUG) import locale from pyanaconda.core.constants import DEFAULT_LANG locale.setlocale(locale.LC_ALL, DEFAULT_LANG) from pyanaconda.core.configuration.anaconda import conf from pyanaconda.anaconda_loggers import get_module_logger log = get_module_logger(__name__) log.debug("The configuration is loaded from: %s", conf.get_sources())
def set_from_files_test(self): conf = AnacondaConfiguration.from_defaults() paths = [] with tempfile.TemporaryDirectory() as d: # Add nonexistent file. nonexistent = os.path.join(d, "nonexistent") paths.append(nonexistent) # Add empty directory. empty_dir = os.path.join(d, "empty") os.mkdir(empty_dir) paths.append(empty_dir) # Add existing file. existing = os.path.join(d, "a.conf") paths.append(existing) with open(existing, mode="w") as f: f.write("") # Add non-empty directory. conf_dir = os.path.join(d, "conf.d") os.mkdir(conf_dir) paths.append(conf_dir) for name in ["b.conf", "c.conf", "d"]: with open(os.path.join(conf_dir, name), mode="w") as f: f.write("") # Check the paths. self.assertEqual( [os.path.relpath(path, d) for path in paths], ["nonexistent", "empty", "a.conf", "conf.d"] ) conf._sources = [] conf.set_from_files(paths) # Check the loaded files. self.assertEqual( [os.path.relpath(path, d) for path in conf.get_sources()], ["a.conf", "conf.d/b.conf", "conf.d/c.conf"] )
def default_source_test(self): conf = AnacondaConfiguration.from_defaults() sources = conf.get_sources() self.assertEqual(len(sources), 1) self.assertEqual(sources[0], os.environ.get("ANACONDA_CONFIG_TMP"))
def source_test(self): conf = AnacondaConfiguration() sources = conf.get_sources() self.assertEqual(sources, [])
def _check_configuration_sources(self, conf, file_names): """Check the loaded configuration sources.""" file_paths = [os.path.join(CONFIG_DIR, path) for path in file_names] self.assertEqual(file_paths, conf.get_sources())
def default_source_test(self): conf = AnacondaConfiguration.from_defaults() sources = conf.get_sources() self.assertEqual(len(sources), 1) self.assertEqual(sources[0], os.environ.get("ANACONDA_CONFIG_TMP"))
def source_test(self): conf = AnacondaConfiguration() sources = conf.get_sources() self.assertEqual(sources, [])
def test_default_source(self): conf = AnacondaConfiguration.from_defaults() sources = conf.get_sources() assert len(sources) == 1 assert sources[0] == os.environ.get("ANACONDA_CONFIG_TMP")
def test_source(self): conf = AnacondaConfiguration() sources = conf.get_sources() assert sources == []