def test_build(self): self.xar_builder.add_directory(self.src.path()) dst = xar_util.StagingDirectory() test_xar = os.path.join(dst.path(), "test.xar") test_root = os.path.join(dst.path(), "squashfs-root") self.xar_builder.build(test_xar, self.sqopts) self._unxar(test_xar, test_root) self.assertDirectoryEqual(self.src.path(), test_root) dst.delete()
def _run_partition_by_extension(self): """Performs the :func:`partition_by_extension` work once frozen.""" self._ensure_frozen() self._partition_dest = {} if self._partition is None: return for ext in self._partition: staging_dir = xar_util.StagingDirectory() uuid = xar_util.make_uuid() dest = xar_util.PartitionDestination(staging_dir, uuid) self._partition_dest["." + ext.lstrip(".")] = dest xar_util.partition_files(self._staging, self._partition_dest)
def setUp(self): self.xar_builder = xar_builder.XarBuilder() self.sqopts = xar_util.SquashfsOptions() self.sqopts.compression_algorithm = "gzip" self.src = xar_util.StagingDirectory() # A set of files for testing self.files = { "executable.sh": ("executable.sh", "#!echo executable", "w", 0o755), "lib.so": ("lib.so", b"binary source", "wb", 0o644), "source.txt": ("source.txt", "text source", "w", 0o644), "subdir/source.txt": ("subdir/source.txt", "subdir", "w", 0o644), } for filename, data, mode, permissions in self.files.values(): self.src.write(data, filename, mode, permissions) self.assertEqual( xar_test_helpers.mode(self.src.absolute(filename)), permissions)
def __init__(self, xar_exec=None, mount_root=None): """ Constructs a XarBuilder given the optional `xar_exec` path and `mount_root`. `xar_exec` is the executable that runs the xar and `mount_root` is where `xar_exec` will mount the squashfs filesystem. """ self._staging = xar_util.StagingDirectory() self._frozen = False self._mount_root = mount_root self._xar_exec = xar_exec if self._xar_exec is None: self._xar_exec = "/usr/bin/env xarexec_fuse" self._executable = None self._shebang = None self._priorities = None self._partition = None self._version = None self._sort_file = None self._partition_dest = {}
def test_partition_files(self): "Test the file partitioning functionality used for split XARs." srcdir = xar_util.StagingDirectory(self.make_test_skeleton()) dstdir = copy.deepcopy(srcdir) debuginfo_dir = xar_util.StagingDirectory() mp3_dir = xar_util.StagingDirectory() # Set up and execute the partitioning. print("Partitioning %s (normal) to %s (debuginfo) and %s (mp3)" % (dstdir.path(), debuginfo_dir.path(), mp3_dir.path())) uuid = xar_util.make_uuid() extension_map = { ".debuginfo": xar_util.PartitionDestination(debuginfo_dir, uuid), ".mp3": xar_util.PartitionDestination(mp3_dir, uuid), } xar_util.partition_files(dstdir, extension_map) # Every debuginfo file in dstdir should be a symlink; every # .txt file should be a real file. We should find the same # number of txt files as debuginfo symlinks. num_normal_files = 0 num_symlinks = 0 for dirname, _, filenames in os.walk(dstdir.path()): for filename in filenames: fn = os.path.join(dirname, filename) if fn.endswith((".debuginfo", ".mp3")): self.assertTrue(os.path.islink(fn)) link = os.readlink(fn) self.assertTrue( link.find("/%s/" % uuid) != -1, "%s symlink to %s contains /%s/" % (link, fn, uuid), ) num_symlinks += 1 else: self.assertTrue(os.path.isfile(fn), "%s is a file" % fn) num_normal_files += 1 # Two symlinks per normal file self.assertEquals(num_normal_files, 7) self.assertEquals(2 * num_normal_files, num_symlinks) # Make sure only normal files are in the debuginfo dir. for dirname, _, filenames in os.walk(debuginfo_dir.path()): for filename in filenames: fn = os.path.join(dirname, filename) if fn.endswith(".debuginfo"): self.assertTrue(os.path.isfile(fn)) else: self.fail("found non-debuginfo file in debug partition") # Same, but for mp3. for dirname, _, filenames in os.walk(mp3_dir.path()): for filename in filenames: fn = os.path.join(dirname, filename) if fn.endswith(".mp3"): self.assertTrue(os.path.isfile(fn)) else: self.fail("found non-mp3 file in mp3 partition") self.assertDirectoryEqual(srcdir.path(), dstdir.path(), check_contents=False) srcdir.delete() dstdir.delete() debuginfo_dir.delete() mp3_dir.delete()
def test_staging_deepcopy(self): original = xar_util.StagingDirectory(self.make_test_skeleton()) clone = copy.deepcopy(original) self.assertNotEqual(original.absolute(), clone.absolute()) self.assertDirectoryEqual(original.absolute(), clone.absolute())