def prepare_paths_in_metadata(md, xmlclass, dbclass): if md is None: return notes = self._metadata_notes_from_plugin_bundle(md.metadata_type) if not notes: # TODO: Add flag to ignore this kind of warnings (?) self._warning("Metadata \"{0}\" doesn't have a record in " "deltametadata.xml - Ignoring") return suffix = cr.compression_suffix(md.compression_type) or "" md.new_fn = os.path.join( md.out_dir, "{0}.xml{1}".format(md.metadata_type, suffix)) md.new_f_stat = cr.ContentStat(md.checksum_type) md.new_f = xmlclass(md.new_fn, md.compression_type, md.new_f_stat) if self.globalbundle.force_database or notes.get( "database") == "1": md.db_fn = os.path.join(md.out_dir, "{0}.sqlite".format(md.metadata_type)) md.db = dbclass(md.db_fn) else: md.db_fn = None md.db = None
def dump(self, fn, compression_type=deltarepo.XZ, stat=None): """Dump data to a file. :param fn: path to a file :type fn: str :param compression_type: Type of compression :type compression_type: int :param stat: Stat object :type stat: cr.ContentStat or None :returns: Final path (the used basename with compression suffix) :rtype: str """ if (compression_type is None or compression_type == cr.UNKNOWN_COMPRESSION or compression_type == cr.AUTO_DETECT_COMPRESSION): raise DeltaRepoError("Bad compression type: " "{0}".format(compression_type)) suffix = cr.compression_suffix(compression_type) if suffix and not fn.endswith(suffix): fn += suffix content = self.dumps() f = cr.CrFile(fn, cr.MODE_WRITE, compression_type) f.write(content) f.close() return fn
def dump(self, fn, compression_type=deltarepo.XZ, stat=None): """ Dump data to a file. :param fn: path to a file :type fn: str :param compression_type: Type of compression :type compression_type: int :param stat: Stat object :type stat: cr.ContentStat or None :returns: Real used path (basename with compression suffix) :rtype: str """ if (compression_type is None or compression_type == cr.UNKNOWN_COMPRESSION or compression_type == cr.AUTO_DETECT_COMPRESSION): raise DeltaRepoError("Bad compression type: " "{0}".format(compression_type)) suffix = cr.compression_suffix(compression_type) if suffix and not fn.endswith(suffix): fn += suffix content = self.dumps() f = cr.CrFile(fn, cr.MODE_WRITE, compression_type, stat) f.write(content) f.close() return fn
def gen_use_original(self, md, compression_type=cr.NO_COMPRESSION): """Function that takes original metadata file and copy it to the delta repo unmodified. Plugins could use this function when they cannot generate delta file for some reason (eg. file is newly added, so delta is meaningless/impossible).""" md.delta_fn = os.path.join(md.out_dir, os.path.basename(md.new_fn)) # Compress or copy original file stat = None if (compression_type != cr.NO_COMPRESSION): md.delta_fn += cr.compression_suffix(compression_type) stat = cr.ContentStat(md.checksum_type) cr.compress_file(md.new_fn, md.delta_fn, compression_type, stat) else: shutil.copy2(md.new_fn, md.delta_fn) # Prepare repomd record of xml file rec = cr.RepomdRecord(md.metadata_type, md.delta_fn) if stat is not None: rec.load_contentstat(stat) rec.fill(md.checksum_type) if self.globalbundle.unique_md_filenames: rec.rename_file() md.delta_fn = rec.location_real return rec
def prepare_paths_in_metadata(md, xmlclass, dbclass): if md is None: return notes = self._metadata_notes_from_plugin_bundle(md.metadata_type) if not notes: # TODO: Add flag to ignore this kind of warnings (?) self._warning("Metadata \"{0}\" doesn't have a record in " "deltametadata.xml - Ignoring") return suffix = cr.compression_suffix(md.compression_type) or "" md.new_fn = os.path.join(md.out_dir, "{0}.xml{1}".format( md.metadata_type, suffix)) md.new_f_stat = cr.ContentStat(md.checksum_type) md.new_f = xmlclass(md.new_fn, md.compression_type, md.new_f_stat) if self.globalbundle.force_database or notes.get("database") == "1": md.db_fn = os.path.join(md.out_dir, "{0}.sqlite".format( md.metadata_type)) md.db = dbclass(md.db_fn) else: md.db_fn = None md.db = None
def test_compression_suffix(self): self.assertEqual(cr.compression_suffix(cr.AUTO_DETECT_COMPRESSION), None) self.assertEqual(cr.compression_suffix(cr.UNKNOWN_COMPRESSION), None) self.assertEqual(cr.compression_suffix(cr.NO_COMPRESSION), None) self.assertEqual(cr.compression_suffix(123), None) self.assertEqual(cr.compression_suffix(cr.GZ), ".gz") self.assertEqual(cr.compression_suffix(cr.BZ2), ".bz2") self.assertEqual(cr.compression_suffix(cr.XZ), ".xz") self.assertEqual(cr.compression_suffix(cr.ZCK), ".zck")
def __create_db(queues, db_path, db_func, name): db = db_func(db_path) for pkg in pkglist: db.add_pkg(pkg) db.dbinfo_update(queues[name].get(True)) db.close() cs = cr.ContentStat(cr.SHA256) cr.compress_file_with_stat( db_path, db_path + cr.compression_suffix(cr.BZ2_COMPRESSION), cr.BZ2_COMPRESSION, cs) os.remove(db_path) queues['master'].put( ((name + '_db', db_path + cr.compression_suffix(cr.BZ2_COMPRESSION)), (cs.checksum, cs.size, cs.checksum_type)), True)
def prepare_paths_in_metadata(md, xmlclass): if md is None: return None # Make a note about if the database should be generated db_available = metadata.get(md.metadata_type + "_db").new_fn_exists if db_available or self.globalbundle.force_database: metadata_notes.setdefault(md.metadata_type, {})["database"] = "1" else: metadata_notes.setdefault(md.metadata_type, {})["database"] = "0" suffix = cr.compression_suffix(md.compression_type) or "" md.delta_fn = os.path.join( md.out_dir, "{0}.xml{1}".format(md.metadata_type, suffix)) md.delta_f_stat = cr.ContentStat(md.checksum_type) md.delta_f = xmlclass(md.delta_fn, md.compression_type, md.delta_f_stat) return md
def prepare_paths_in_metadata(md, xmlclass): if md is None: return None # Make a note about if the database should be generated db_available = metadata.get(md.metadata_type+"_db").new_fn_exists if db_available or self.globalbundle.force_database: metadata_notes.setdefault(md.metadata_type, {})["database"] = "1" else: metadata_notes.setdefault(md.metadata_type, {})["database"] = "0" suffix = cr.compression_suffix(md.compression_type) or "" md.delta_fn = os.path.join(md.out_dir, "{0}.xml{1}".format( md.metadata_type, suffix)) md.delta_f_stat = cr.ContentStat(md.checksum_type) md.delta_f = xmlclass(md.delta_fn, md.compression_type, md.delta_f_stat) return md