def add_package(self, path, deltas, repo_uri): package = Package(path, 'r') md = package.get_metadata() md.package.packageSize = os.path.getsize(path) md.package.packageHash = util.sha1_file(path) if ctx.config.options and ctx.config.options.absolute_urls: md.package.packageURI = os.path.realpath(path) else: # create relative path by default # TODO: in the future well do all of this with purl/pfile/&helpers # really? heheh -- future exa md.package.packageURI = util.removepathprefix(repo_uri, path) # check package semantics errs = md.errors() if md.errors(): ctx.ui.error(_('Package %s: metadata corrupt, skipping...') % md.package.name) ctx.ui.error(unicode(Error(*errs))) else: # No need to carry these with index (#3965) md.package.files = None md.package.additionalFiles = None if md.package.name in deltas: for delta_path in deltas[md.package.name]: delta = metadata.Delta() delta.packageURI = util.removepathprefix(repo_uri, delta_path) delta.packageSize = os.path.getsize(delta_path) delta.packageHash = util.sha1_file(delta_path) name, buildFrom, buildTo = util.parse_delta_package_name(delta_path) delta.buildFrom = buildFrom md.package.deltaPackages.append(delta) self.packages.append(md.package)
def add_package(self, path, repo_uri): package = Package(path, 'r') md = package.get_metadata() md.package.packageSize = os.path.getsize(path) md.package.packageHash = util.sha1_file(path) if ctx.config.options and ctx.config.options.absolute_urls: md.package.packageURI = os.path.realpath(path) else: # create relative path by default # TODO: in the future well do all of this with purl/pfile/&helpers # really? heheh -- future exa md.package.packageURI = util.removepathprefix(repo_uri, path) # check package semantics errs = md.errors() if md.errors(): ctx.ui.error(_('Package %s: metadata corrupt, skipping...') % md.package.name) ctx.ui.error(unicode(Error(*errs))) else: self.packages.append(md.package)
def create_delta_package(old_package, new_package): if old_package == new_package: ctx.ui.error(_("Cannot create delta for same package!")) return oldpkg = Package(old_package, "r") newpkg = Package(new_package, "r") newmd = newpkg.get_metadata() oldmd = oldpkg.get_metadata() oldfiles = oldpkg.get_files() newfiles = newpkg.get_files() files_delta = find_delta(oldfiles, newfiles) ctx.ui.info(_("Creating delta PiSi package between %s %s") % (old_package, new_package)) # Unpack new package to temp newpkg_name = util.package_name(newmd.package.name, newmd.package.version, newmd.package.release, newmd.package.build, False) newpkg_path = util.join_path(ctx.config.tmp_dir(), newpkg_name) newpkg.extract_to(newpkg_path, True) tar = archive.ArchiveTar(util.join_path(newpkg_path, ctx.const.install_tar_lzma), "tarlzma", False, False) tar.unpack_dir(newpkg_path) # Create delta package deltaname = "%s-%s-%s%s" % (oldmd.package.name, oldmd.package.build, newmd.package.build, ctx.const.delta_package_suffix) outdir = ctx.get_option("output_dir") if outdir: deltaname = util.join_path(outdir, deltaname) deltapkg = Package(deltaname, "w") c = os.getcwd() os.chdir(newpkg_path) # add comar files to package for pcomar in newmd.package.providesComar: fname = util.join_path(ctx.const.comar_dir, pcomar.script) deltapkg.add_to_package(fname) # add xmls and files deltapkg.add_to_package(ctx.const.metadata_xml) deltapkg.add_to_package(ctx.const.files_xml) # only metadata information may change in a package, so no install.tar.lzma added to delta package if files_delta: ctx.build_leftover = util.join_path(ctx.config.tmp_dir(), ctx.const.install_tar_lzma) tar = archive.ArchiveTar(util.join_path(ctx.config.tmp_dir(), ctx.const.install_tar_lzma), "tarlzma") for file in files_delta: tar.add_to_archive(file.path) tar.close() os.chdir(ctx.config.tmp_dir()) deltapkg.add_to_package(ctx.const.install_tar_lzma) deltapkg.close() tmp_file = util.join_path(ctx.config.tmp_dir(), ctx.const.install_tar_lzma) if os.path.exists(tmp_file): os.unlink(tmp_file) ctx.build_leftover = None os.chdir(c) ctx.ui.info(_("Done."))