delta: Implement function to create multiple delta packages

create_delta_package is now a wrapper around create_delta_packages.
This commit is contained in:
Fatih Aşıcı
2010-06-22 07:20:36 +00:00
parent a038fcb986
commit 2c50cc2c84
+60 -50
View File
@@ -21,65 +21,72 @@ import pisi.util as util
import pisi.archive as archive import pisi.archive as archive
def create_delta_package(old_package, new_package): def create_delta_packages(old_packages, new_package):
if new_package in old_packages:
ctx.ui.warning(_("New package '%s' exists in the list of old "
"packages. Skipping it...") % new_package)
while new_package in old_packages:
old_packages.remove(new_package)
if old_package == new_package: new_pkg = pisi.package.Package(new_package)
ctx.ui.error(_("Cannot create delta for same package!")) new_pkg_info = new_pkg.metadata.package
return new_pkg_files = new_pkg.get_files()
oldpkg = pisi.package.Package(old_package, "r")
newpkg = pisi.package.Package(new_package, "r")
newmd = newpkg.metadata
oldmd = oldpkg.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 # Unpack new package to temp
newpkg_name = util.package_name(newmd.package.name, new_pkg_name = util.package_name(new_pkg_info.name,
newmd.package.version, new_pkg_info.version,
newmd.package.release, new_pkg_info.release,
newmd.package.build, new_pkg_info.build, False)
False)
newpkg_path = util.join_path(ctx.config.tmp_dir(), newpkg_name)
newpkg.extract_pisi_files(newpkg_path)
newpkg.extract_dir("comar", newpkg_path)
install_dir = util.join_path(newpkg_path, "install") new_pkg_path = util.join_path(ctx.config.tmp_dir(), new_pkg_name)
new_pkg.extract_pisi_files(new_pkg_path)
new_pkg.extract_dir("comar", new_pkg_path)
install_dir = util.join_path(new_pkg_path, "install")
util.clean_dir(install_dir) util.clean_dir(install_dir)
os.mkdir(install_dir) os.mkdir(install_dir)
newpkg.extract_install(install_dir) new_pkg.extract_install(install_dir)
# Create delta package cwd = os.getcwd()
deltaname = "%s-%s-%s%s" % (oldmd.package.name, out_dir = ctx.get_option("output_dir")
oldmd.package.build, target_format = ctx.get_option("package_format")
newmd.package.build, delta_packages = []
for old_package in old_packages:
old_pkg = pisi.package.Package(old_package)
old_pkg_info = old_pkg.metadata.package
if old_pkg_info.build == new_pkg_info.build:
ctx.ui.warning(_("Package '%s' has the same build number with "
"the new package. Skipping it...") % old_package)
continue
delta_name = "%s-%s-%s%s" % (old_pkg_info.name,
old_pkg_info.build,
new_pkg_info.build,
ctx.const.delta_package_suffix) ctx.const.delta_package_suffix)
outdir = ctx.get_option("output_dir") ctx.ui.info(_("Creating %s...") % delta_name)
if outdir:
deltaname = util.join_path(outdir, deltaname)
deltapkg = pisi.package.Package(deltaname, "w", if out_dir:
format=ctx.get_option("package_format")) delta_name = util.join_path(out_dir, delta_name)
c = os.getcwd() old_pkg_files = old_pkg.get_files()
os.chdir(newpkg_path)
delta_pkg = pisi.package.Package(delta_name, "w", format=target_format)
os.chdir(new_pkg_path)
# add comar files to package # add comar files to package
for pcomar in newmd.package.providesComar: for pcomar in new_pkg_info.providesComar:
fname = util.join_path(ctx.const.comar_dir, pcomar.script) fname = util.join_path(ctx.const.comar_dir, pcomar.script)
deltapkg.add_to_package(fname) delta_pkg.add_to_package(fname)
# add xmls and files # add xmls and files
deltapkg.add_metadata_xml(ctx.const.metadata_xml) delta_pkg.add_metadata_xml(ctx.const.metadata_xml)
deltapkg.add_files_xml(ctx.const.files_xml) delta_pkg.add_files_xml(ctx.const.files_xml)
files_delta = find_delta(old_pkg_files, new_pkg_files)
# only metadata information may change in a package, # only metadata information may change in a package,
# so no install archive added to delta package # so no install archive added to delta package
@@ -92,19 +99,22 @@ def create_delta_package(old_package, new_package):
os.chdir(install_dir) os.chdir(install_dir)
for f in files_delta: for f in files_delta:
deltapkg.add_to_install(f.path) delta_pkg.add_to_install(f.path)
deltapkg.close() os.chdir(cwd)
os.chdir(c) delta_pkg.close()
delta_packages.append(delta_name)
# Remove temp dir # Remove temp dir
util.clean_dir(newpkg_path) util.clean_dir(new_pkg_path)
ctx.ui.info(_("Done.")) # Return delta package names
return delta_packages
# return delta package name def create_delta_package(old_package, new_package):
return deltaname packages = create_delta_packages([old_package], new_package)
return packages or None
# Hash not equals (these are the deltas) # Hash not equals (these are the deltas)