def _new_metadata(self, metadata_type): """Return Metadata Object for the metadata_type""" metadata = Metadata(metadata_type) metadata.checksum_type = self.checksum_type metadata.compression_type = DEFAULT_COMPRESSION_TYPE # Set output directory metadata.out_dir = self.new_repodata_path # Properties related to the first (old) repository old_rec = self.old_records.get(metadata_type) metadata.old_rec = old_rec if old_rec: # Build old filename metadata.old_fn = os.path.join(self.old_repo_path, old_rec.location_href) if os.path.isfile(metadata.old_fn): metadata.old_fn_exists = True else: msg = "File {0} doesn't exist in the old repository" \ " (but it should - delta may rely on " \ "it)!".format(metadata.old_fn) self._warning(msg) if not self.ignore_missing: raise DeltaRepoError(msg + " Use --ignore-missing option " "to ignore this error") # Properties related to the second (delta) repository delta_rec = self.delta_records.get(metadata_type) metadata.delta_rec = delta_rec if delta_rec: metadata.delta_fn = os.path.join(self.delta_repo_path, delta_rec.location_href) if os.path.isfile(metadata.delta_fn): metadata.delta_fn_exists = True # Determine compression type detected_compression_type = cr.detect_compression( metadata.delta_fn) if (detected_compression_type != cr.UNKNOWN_COMPRESSION): metadata.compression_type = detected_compression_type else: self._warning("Cannot detect compression type for " "{0}".format(metadata.delta_fn)) else: msg = ("The file {0} doesn't exist in the delta" "repository!".format(metadata.new_fn)) self._warning(msg) if not self.ignore_missing: raise DeltaRepoError(msg + " Use --ignore-missing option " "to ignore this error") metadata.checksum_type = cr.checksum_type(delta_rec.checksum_type) return metadata
def test_detect_compression(self): # no compression path = os.path.join(COMPRESSED_FILES_PATH, "01_plain.txt") comtype = cr.detect_compression(path) self.assertEqual(comtype, cr.NO_COMPRESSION) # gz compression path = os.path.join(COMPRESSED_FILES_PATH, "01_plain.txt.gz") comtype = cr.detect_compression(path) self.assertEqual(comtype, cr.GZ) # bz2 compression path = os.path.join(COMPRESSED_FILES_PATH, "01_plain.txt.bz2") comtype = cr.detect_compression(path) self.assertEqual(comtype, cr.BZ2) # xz compression path = os.path.join(COMPRESSED_FILES_PATH, "01_plain.txt.xz") comtype = cr.detect_compression(path) self.assertEqual(comtype, cr.XZ) # zck compression path = os.path.join(COMPRESSED_FILES_PATH, "01_plain.txt.zck") comtype = cr.detect_compression(path) self.assertEqual(comtype, cr.ZCK) # Bad suffix - no compression path = os.path.join(COMPRESSED_FILES_PATH, "01_plain.foo0") comtype = cr.detect_compression(path) self.assertEqual(comtype, cr.NO_COMPRESSION) # Bad suffix - gz compression path = os.path.join(COMPRESSED_FILES_PATH, "01_plain.foo1") comtype = cr.detect_compression(path) self.assertEqual(comtype, cr.GZ) # Bad suffix - bz2 compression path = os.path.join(COMPRESSED_FILES_PATH, "01_plain.foo2") comtype = cr.detect_compression(path) self.assertEqual(comtype, cr.BZ2) # Bad suffix - xz compression path = os.path.join(COMPRESSED_FILES_PATH, "01_plain.foo3") comtype = cr.detect_compression(path) self.assertEqual(comtype, cr.XZ)
def _new_metadata(self, metadata_type): """Return Metadata Object for the metadata_type""" metadata = Metadata(metadata_type) metadata.checksum_type = self.checksum_type metadata.compression_type = DEFAULT_COMPRESSION_TYPE # Set output directory metadata.out_dir = self.new_repodata_path # Properties related to the first (old) repository old_rec = self.old_records.get(metadata_type) metadata.old_rec = old_rec if old_rec: # Build old filename metadata.old_fn = os.path.join(self.old_repo_path, old_rec.location_href) if os.path.isfile(metadata.old_fn): metadata.old_fn_exists = True else: msg = ( "File {0} doesn't exist in the old repository" " (but it should - delta may rely on " "it)!".format(metadata.old_fn) ) self._warning(msg) if not self.ignore_missing: raise DeltaRepoError(msg + " Use --ignore-missing option " "to ignore this error") # Properties related to the second (delta) repository delta_rec = self.delta_records.get(metadata_type) metadata.delta_rec = delta_rec if delta_rec: metadata.delta_fn = os.path.join(self.delta_repo_path, delta_rec.location_href) if os.path.isfile(metadata.delta_fn): metadata.delta_fn_exists = True # Determine compression type detected_compression_type = cr.detect_compression(metadata.delta_fn) if detected_compression_type != cr.UNKNOWN_COMPRESSION: metadata.compression_type = detected_compression_type else: self._warning("Cannot detect compression type for " "{0}".format(metadata.delta_fn)) else: msg = "The file {0} doesn't exist in the delta" "repository!".format(metadata.new_fn) self._warning(msg) if not self.ignore_missing: raise DeltaRepoError(msg + " Use --ignore-missing option " "to ignore this error") metadata.checksum_type = cr.checksum_type(delta_rec.checksum_type) return metadata