def test_decompress_file(self):
        # Non exist file
        self.assertRaises(IOError, cr.decompress_file, self.nofile, None,
                          cr.BZ2)

        tmpfile_gz_comp = os.path.join(self.tmpdir, "gzipedfile.gz")
        shutil.copy(FILE_TEXT_GZ, tmpfile_gz_comp)
        tmpfile_gz_comp_ns = os.path.join(self.tmpdir, "gzipedfile_no_suffix")
        shutil.copy(FILE_TEXT_GZ, tmpfile_gz_comp_ns)

        # Decompression - use the same name without suffix
        dest = os.path.join(self.tmpdir, "gzipedfile")
        cr.decompress_file(tmpfile_gz_comp, None, cr.GZ)
        self.assertTrue(os.path.isfile(dest))

        # Decompression - use the specific name
        dest = os.path.join(self.tmpdir, "decompressed.file")
        cr.decompress_file(tmpfile_gz_comp, dest, cr.GZ)
        self.assertTrue(os.path.isfile(dest))

        # Decompression - bad suffix by default
        dest = os.path.join(self.tmpdir, "gzipedfile_no_suffix.decompressed")
        cr.decompress_file(tmpfile_gz_comp_ns, None, cr.GZ)
        self.assertTrue(os.path.isfile(dest))

        # Decompression - with stat
        stat = cr.ContentStat(cr.SHA256)
        dest = os.path.join(self.tmpdir, "gzipedfile")
        cr.decompress_file(tmpfile_gz_comp, None, cr.AUTO_DETECT_COMPRESSION,
                           stat)
        self.assertTrue(os.path.isfile(dest))
        self.assertEqual(stat.checksum, FILE_TEXT_SHA256SUM)
        self.assertEqual(stat.checksum_type, cr.SHA256)
        self.assertEqual(stat.size, 910)
Beispiel #2
0
    def test_decompress_file(self):
        # Non exist file
        self.assertRaises(IOError, cr.decompress_file,
                          self.nofile, None, cr.BZ2)

        tmpfile_gz_comp = os.path.join(self.tmpdir, "gzipedfile.gz")
        shutil.copy(FILE_TEXT_GZ, tmpfile_gz_comp)
        tmpfile_gz_comp_ns = os.path.join(self.tmpdir, "gzipedfile_no_suffix")
        shutil.copy(FILE_TEXT_GZ, tmpfile_gz_comp_ns)

        # Decompression - use the same name without suffix
        dest = os.path.join(self.tmpdir, "gzipedfile")
        cr.decompress_file(tmpfile_gz_comp, None, cr.GZ)
        self.assertTrue(os.path.isfile(dest))

        # Decompression - use the specific name
        dest = os.path.join(self.tmpdir, "decompressed.file")
        cr.decompress_file(tmpfile_gz_comp, dest, cr.GZ)
        self.assertTrue(os.path.isfile(dest))

        # Decompression - bad suffix by default
        dest = os.path.join(self.tmpdir, "gzipedfile_no_suffix.decompressed")
        cr.decompress_file(tmpfile_gz_comp_ns, None, cr.GZ)
        self.assertTrue(os.path.isfile(dest))

        # Decompression - with stat
        stat = cr.ContentStat(cr.SHA256)
        dest = os.path.join(self.tmpdir, "gzipedfile")
        cr.decompress_file(tmpfile_gz_comp, None, cr.AUTO_DETECT_COMPRESSION, stat)
        self.assertTrue(os.path.isfile(dest))
        self.assertEqual(stat.checksum, FILE_TEXT_SHA256SUM)
        self.assertEqual(stat.checksum_type, cr.SHA256)
        self.assertEqual(stat.size, 910L)
Beispiel #3
0
    def load(self, fn):
        """
        Load metadata from a xml file.

        :param fn: Path to a file
        :type fn: str
        """
        _, tmp_path = tempfile.mkstemp()
        cr.decompress_file(fn, tmp_path, cr.AUTO_DETECT_COMPRESSION)
        dom = xml.dom.minidom.parse(tmp_path)
        os.remove(tmp_path)
        try:
            self._parse_dom(dom)
        except DeltaRepoParseError as err:
            msg = "Cannot parse {0}: {1}".format(fn, err)
            raise DeltaRepoParseError(msg)
Beispiel #4
0
    def load(self, fn):
        """
        Load metadata from a xml file.

        :param fn: Path to a file
        :type fn: str
        """
        _, tmp_path = tempfile.mkstemp()
        cr.decompress_file(fn, tmp_path, cr.AUTO_DETECT_COMPRESSION)
        dom = xml.dom.minidom.parse(tmp_path)
        os.remove(tmp_path)
        try:
            self._parse_dom(dom)
        except DeltaRepoParseError as err:
            msg = "Cannot parse {0}: {1}".format(fn, err)
            raise DeltaRepoParseError(msg)
Beispiel #5
0
    def apply_use_original(self, md, decompress=False):
        """Reversal function for the gen_use_original"""
        md.new_fn = os.path.join(md.out_dir, os.path.basename(md.delta_fn))

        if decompress:
            md.new_fn = md.new_fn.rsplit('.', 1)[0]
            cr.decompress_file(md.delta_fn, md.new_fn, cr.AUTO_DETECT_COMPRESSION)
        else:
            shutil.copy2(md.delta_fn, md.new_fn)

        # Prepare repomd record of xml file
        rec = cr.RepomdRecord(md.metadata_type, md.new_fn)
        rec.fill(md.checksum_type)
        if self.globalbundle.unique_md_filenames:
            rec.rename_file()
            md.new_fn = rec.location_real

        return rec
Beispiel #6
0
    def apply_use_original(self, md, decompress=False):
        """Reversal function for the gen_use_original"""
        md.new_fn = os.path.join(md.out_dir, os.path.basename(md.delta_fn))

        if decompress:
            md.new_fn = md.new_fn.rsplit('.', 1)[0]
            cr.decompress_file(md.delta_fn, md.new_fn,
                               cr.AUTO_DETECT_COMPRESSION)
        else:
            shutil.copy2(md.delta_fn, md.new_fn)

        # Prepare repomd record of xml file
        rec = cr.RepomdRecord(md.metadata_type, md.new_fn)
        rec.fill(md.checksum_type)
        if self.globalbundle.unique_md_filenames:
            rec.rename_file()
            md.new_fn = rec.location_real

        return rec
Beispiel #7
0
    def load(self, fn, pedantic=True):
        """Load metadata from a file.

        :param fn: Path to a file
        :type fn: str
        :param pedantic: Raise exception if there is an invalid record
                         (a record that doesn't contain all mandatory info)
                         (enabled by default)
        :type pedantic: bool
        :returns: Self to enable chaining (dr = DeltaRepos().load())
        :rtype: DeltaRepos
        """
        _, tmp_path = tempfile.mkstemp(prefix="tmp-deltarepos-xml-file-")
        cr.decompress_file(fn, tmp_path, cr.AUTO_DETECT_COMPRESSION)
        document = xml.dom.minidom.parse(tmp_path)
        os.remove(tmp_path)
        try:
            self._from_xml_document(document, pedantic=pedantic)
        except DeltaRepoError as err:
            raise DeltaRepoParseError("Cannot parse {0}: {1}".format(fn, err))
        return self
Beispiel #8
0
    def load(self, fn, pedantic=True):
        """Load metadata from a file.

        :param fn: Path to a file
        :type fn: str
        :param pedantic: Raise exception if there is an invalid record
                         (a record that doesn't contain all mandatory info)
                         (enabled by default)
        :type pedantic: bool
        :returns: Self to enable chaining (dr = DeltaRepos().load())
        :rtype: DeltaRepos
        """
        _, tmp_path = tempfile.mkstemp(prefix="tmp-deltarepos-xml-file-")
        cr.decompress_file(fn, tmp_path, cr.AUTO_DETECT_COMPRESSION)
        document = xml.dom.minidom.parse(tmp_path)
        os.remove(tmp_path)
        try:
            self._from_xml_document(document, pedantic=pedantic)
        except DeltaRepoError as err:
            raise DeltaRepoParseError("Cannot parse {0}: {1}".format(fn, err))
        return self