def test_Packages_file_correct_content_with_some_deb_content(self):
     package1 = DummyFetchedPackage("foo", "1.1", no_content=True)
     package2 = DummyFetchedPackage("bar", "1.1")
     hwpack = HardwarePack(self.metadata)
     hwpack.add_packages([package1, package2])
     tf = self.get_tarfile(hwpack)
     self.assertThat(tf, HardwarePackHasFile("pkgs/Packages", content=get_packages_file([package2])))
 def test_one(self):
     observed = DummyFetchedPackage("foo", "1.1")
     packages_content = get_packages_file([observed])
     self.assertThat(
         packages_content,
         MatchesAsPackagesFile(
             MatchesPackage(observed)))
 def test_Packages_file_correct_content_with_some_deb_content(self):
     package1 = DummyFetchedPackage("foo", "1.1", no_content=True)
     package2 = DummyFetchedPackage("bar", "1.1")
     hwpack = HardwarePack(self.metadata)
     hwpack.add_packages([package1, package2])
     tf = self.get_tarfile(hwpack)
     self.assertThat(
         tf,
         HardwarePackHasFile("pkgs/Packages",
                             content=get_packages_file([package2])))
 def test_several(self):
     observed1 = DummyFetchedPackage("foo", "1.1")
     observed2 = DummyFetchedPackage("bar", "1.2")
     observed3 = DummyFetchedPackage("baz", "1.5")
     packages_content = get_packages_file(
         [observed1, observed2, observed3])
     parsed = parse_packages_file_content(packages_content)
     self.assertThat(parsed, MatchesSetwise(
         MatchesPackage(observed3),
         MatchesPackage(observed2),
         MatchesPackage(observed1)))
 def test_several(self):
     observed1 = DummyFetchedPackage("foo", "1.1")
     observed2 = DummyFetchedPackage("bar", "1.2")
     observed3 = DummyFetchedPackage("baz", "1.5")
     packages_content = get_packages_file([observed1, observed2, observed3])
     parsed = parse_packages_file_content(packages_content)
     self.assertThat(
         parsed,
         MatchesSetwise(MatchesPackage(observed3),
                        MatchesPackage(observed2),
                        MatchesPackage(observed1)))
示例#6
0
 def setUp(self):
     self.rootdir = tempfile.mkdtemp(prefix="hwpack-apt-source-")
     for package in self.packages:
         with open(os.path.join(self.rootdir, package.filename), 'wb') as f:
             f.write(package.content.read())
     with open(os.path.join(self.rootdir, "Packages"), 'wb') as f:
         f.write(get_packages_file(self.packages))
     if self.label is not None:
         subprocess.check_call(
             ['apt-ftparchive',
              '-oAPT::FTPArchive::Release::Label=%s' % self.label,
              'release',
              self.rootdir],
             stdout=open(os.path.join(self.rootdir, 'Release'), 'w'))
    def to_file(self, fileobj):
        """Write the hwpack to a file object.

        The full hardware pack will be written to the file object in
        gzip compressed tarball form as the spec requires.

        :param fileobj: the file object to write to.
        :type fileobj: a file-like object
        :return: None
        """
        kwargs = {}
        kwargs["default_uid"] = 1000
        kwargs["default_gid"] = 1000
        kwargs["default_uname"] = "user"
        kwargs["default_gname"] = "group"
        kwargs["default_mtime"] = time.time()
        with writeable_tarfile(fileobj, mode="w:gz", **kwargs) as tf:
            tf.create_file_from_string(
                self.FORMAT_FILENAME, "%s\n" % self.format)
            tf.create_file_from_string(
                self.METADATA_FILENAME, str(self.metadata))
            for fs_file_name, arc_file_name in self.files:
                tf.add(fs_file_name, arcname=arc_file_name)
            tf.create_dir(self.PACKAGES_DIRNAME)
            for package in self.packages:
                if package.content is not None:
                    tf.create_file_from_string(
                        self.PACKAGES_DIRNAME + "/" + package.filename,
                        package.content.read())
            tf.create_file_from_string(
                self.MANIFEST_FILENAME, self.manifest_text())
            tf.create_file_from_string(
                self.PACKAGES_FILENAME,
                get_packages_file(
                    [p for p in self.packages if p.content is not None]))
            tf.create_dir(self.SOURCES_LIST_DIRNAME)

            for source_name, source_info in self.sources.items():
                url_parsed = urlparse.urlsplit(source_info)

                # Don't output sources with passwords in them
                if not url_parsed.password:
                    tf.create_file_from_string(
                        (self.SOURCES_LIST_DIRNAME + "/" +
                         source_name + ".list"),
                        "deb " + source_info + "\n")
            # TODO: include sources keys etc.
            tf.create_dir(self.SOURCES_LIST_GPG_DIRNAME)
 def test_ignore_one_md5(self):
     # This is what I actually care about: being able to specify that a
     # packages file matches a set of packages, ignoring just a few
     # details on just one package.
     observed1 = DummyFetchedPackage("foo", "1.1")
     observed2 = DummyFetchedPackage("bar", "1.2")
     observed3 = DummyFetchedPackage("baz", "1.5")
     packages_content = get_packages_file(
         [observed1, observed2, observed3])
     oldmd5 = observed3.md5
     observed3._content = ''.join(reversed(observed3._content_str()))
     self.assertNotEqual(oldmd5, observed3.md5)
     self.assertThat(packages_content, MatchesAsPackagesFile(
         MatchesPackage(observed1),
         MatchesPackage(observed2),
         MatchesPackage(observed3).update(md5=None)))
 def test_ignore_one_md5(self):
     # This is what I actually care about: being able to specify that a
     # packages file matches a set of packages, ignoring just a few
     # details on just one package.
     observed1 = DummyFetchedPackage("foo", "1.1")
     observed2 = DummyFetchedPackage("bar", "1.2")
     observed3 = DummyFetchedPackage("baz", "1.5")
     packages_content = get_packages_file([observed1, observed2, observed3])
     oldmd5 = observed3.md5
     observed3._content = ''.join(reversed(observed3._content_str()))
     self.assertNotEqual(oldmd5, observed3.md5)
     self.assertThat(
         packages_content,
         MatchesAsPackagesFile(MatchesPackage(observed1),
                               MatchesPackage(observed2),
                               MatchesPackage(observed3).update(md5=None)))
 def test_one(self):
     observed = DummyFetchedPackage("foo", "1.1")
     packages_content = get_packages_file([observed])
     parsed = parse_packages_file_content(packages_content)
     self.assertThat(len(parsed), Equals(1))
     self.assertThat(parsed[0], MatchesPackage(observed))
 def test_one(self):
     observed = DummyFetchedPackage("foo", "1.1")
     packages_content = get_packages_file([observed])
     self.assertThat(packages_content,
                     MatchesAsPackagesFile(MatchesPackage(observed)))
 def test_one(self):
     observed = DummyFetchedPackage("foo", "1.1")
     packages_content = get_packages_file([observed])
     parsed = parse_packages_file_content(packages_content)
     self.assertThat(len(parsed), Equals(1))
     self.assertThat(parsed[0], MatchesPackage(observed))