Ejemplo n.º 1
0
    def _ProcessUniversalTemplate(self, dist_dir):
        # An universal teplate contains both fleetspeak and legacy files.
        # If there is a legacy directory, then this is an universal template
        # Depending on the config option, copy only one set of the files into
        # the tree.

        if not os.path.exists(os.path.join(dist_dir, "legacy")):
            return

        if config.CONFIG.Get("Client.fleetspeak_enabled",
                             context=self.context):
            # Since there is fleetspeak/fleetspeak, rename the top-level
            # fleetspeak directory.
            shutil.move(os.path.join(dist_dir, "fleetspeak"),
                        os.path.join(dist_dir, "_fleetspeak"))
            utils.MergeDirectories(os.path.join(dist_dir, "_fleetspeak"),
                                   dist_dir)
        else:
            utils.MergeDirectories(os.path.join(dist_dir, "legacy"), dist_dir)
        self._RmTreeIfExists(os.path.join(dist_dir, "legacy"))
        self._RmTreeIfExists(os.path.join(dist_dir, "_fleetspeak"))
Ejemplo n.º 2
0
    def testMergeDirectories(self):
        stack = contextlib.ExitStack()
        self.addCleanup(stack.close)

        src_dir = stack.enter_context(utils.TempDirectory())
        dst_dir = stack.enter_context(utils.TempDirectory())

        def SrcPath(*components):
            return os.path.join(src_dir, *components)

        def DstPath(*components):
            return os.path.join(dst_dir, *components)

        def WriteFile(path, contents):
            utils.EnsureDirExists(os.path.dirname(path))
            with open(path, "w") as f:
                f.write(contents)

        def ReadFile(path):
            with open(path) as f:
                return f.read()

        WriteFile(SrcPath("a", "b", "c", "file1.txt"), "file1")
        WriteFile(SrcPath("a", "b", "c", "file2.txt"), "file2")
        WriteFile(SrcPath("file3.txt"), "file3")

        WriteFile(DstPath("a", "file4.txt"), "file4")
        WriteFile(DstPath("file5.txt"), "file5")

        utils.MergeDirectories(src_dir, dst_dir)

        self.assertEqual(ReadFile(DstPath("a", "b", "c", "file1.txt")),
                         "file1")
        self.assertEqual(ReadFile(DstPath("a", "b", "c", "file2.txt")),
                         "file2")
        self.assertEqual(ReadFile(DstPath("file3.txt")), "file3")
        self.assertEqual(ReadFile(DstPath("a", "file4.txt")), "file4")
        self.assertEqual(ReadFile(DstPath("file5.txt")), "file5")