Exemplo n.º 1
0
    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)
Exemplo n.º 2
0
    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
Exemplo n.º 4
0
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())
Exemplo n.º 5
0
    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)
Exemplo n.º 6
0
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())
Exemplo n.º 7
0
    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"]
            )
Exemplo n.º 8
0
 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"))
Exemplo n.º 9
0
 def source_test(self):
     conf = AnacondaConfiguration()
     sources = conf.get_sources()
     self.assertEqual(sources, [])
Exemplo n.º 10
0
 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())
Exemplo n.º 11
0
 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"))
Exemplo n.º 12
0
 def source_test(self):
     conf = AnacondaConfiguration()
     sources = conf.get_sources()
     self.assertEqual(sources, [])
Exemplo n.º 13
0
 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")
Exemplo n.º 14
0
 def test_source(self):
     conf = AnacondaConfiguration()
     sources = conf.get_sources()
     assert sources == []