diff --git a/pisi/cli/delta.py b/pisi/cli/delta.py index 3b5f5e2a..8155a06d 100644 --- a/pisi/cli/delta.py +++ b/pisi/cli/delta.py @@ -1,6 +1,6 @@ # -*- coding:utf-8 -*- # -# Copyright (C) 2005 - 2007, TUBITAK/UEKAE +# Copyright (C) 2005-2010, TUBITAK/UEKAE # # This program is free software; you can redistribute it and/or modify it under # the terms of the GNU General Public License as published by the Free @@ -19,15 +19,21 @@ _ = __trans.ugettext import pisi.cli.command as command import pisi.context as ctx -class Delta(command.Command): - __doc__ = _("""Creates delta PiSi packages + +usage = _("""Creates delta PiSi packages Usage: delta oldpackage newpackage -Delta command finds the changed files between the given packages by comparing the sha1sum of the files -and creates a delta pisi package with the changed files between two releases. - +Delta command finds the changed files between the given +packages by comparing the sha1sum of the files and creates +a delta pisi package with the changed files between two +releases. """) + + +class Delta(command.Command): + + __doc__ = usage __metaclass__ = command.autocommand def __init__(self, args): @@ -36,18 +42,18 @@ and creates a delta pisi package with the changed files between two releases. name = ("delta", "dt") def options(self): - group = optparse.OptionGroup(self.parser, _("delta options")) self.add_options(group) self.parser.add_option_group(group) def add_options(self, group): - group.add_option("-O", "--output-dir", action="store", default=None, - help=_("Output directory for produced packages")) + group.add_option("-O", "--output-dir", + action="store", + default=None, + help=_("Output directory for produced packages")) def run(self): - - from pisi.operations.delta import create_delta_package + from pisi.operations.delta import create_delta_package self.init(database=False, write=False) @@ -56,7 +62,8 @@ and creates a delta pisi package with the changed files between two releases. return if ctx.get_option('output_dir'): - ctx.ui.info(_('Output directory: %s') % ctx.config.options.output_dir) + ctx.ui.info(_('Output directory: %s') + % ctx.config.options.output_dir) else: ctx.ui.info(_('Outputting packages in the working directory.')) ctx.config.options.output_dir = '.' diff --git a/pisi/operations/delta.py b/pisi/operations/delta.py index bb71bd6f..32aae43c 100644 --- a/pisi/operations/delta.py +++ b/pisi/operations/delta.py @@ -20,6 +20,7 @@ import pisi.package import pisi.util as util import pisi.archive as archive + def create_delta_package(old_package, new_package): if old_package == new_package: @@ -37,18 +38,27 @@ def create_delta_package(old_package, new_package): files_delta = find_delta(oldfiles, newfiles) - ctx.ui.info(_("Creating delta PiSi package between %s %s") % (old_package, new_package)) + 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_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) + newpkg_archive = util.join_path(newpkg_path, ctx.const.install_tar_lzma) + tar = archive.ArchiveTar(newpkg_archive, "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) + 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: @@ -68,16 +78,21 @@ def create_delta_package(old_package, new_package): 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 + # only metadata information may change in a package, + # so no install.tar.lzma added to delta package if files_delta: # Sort the files in-place according to their path for an ordered - # tarfile layout which dramatically improves the compression performance - # of lzma. This improvement is stolen from build.py (commit r23485). + # tarfile layout which dramatically improves the compression + # performance of lzma. This improvement is stolen from build.py + # (commit r23485). files_delta.sort(key=lambda x: x.path) - ctx.build_leftover = util.join_path(ctx.config.tmp_dir(), ctx.const.install_tar_lzma) + 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") + deltapkg_archive = util.join_path(ctx.config.tmp_dir(), + ctx.const.install_tar_lzma) + tar = archive.ArchiveTar(deltapkg_archive, "tarlzma") for f in files_delta: tar.add_to_archive(f.path) tar.close() @@ -99,6 +114,7 @@ def create_delta_package(old_package, new_package): # return delta package name return deltaname + # Hash not equals (these are the deltas) # Hash equal but path different ones (these are the relocations) # Hash and also path equal ones (do nothing) @@ -109,16 +125,17 @@ def find_delta(oldfiles, newfiles): for f in newfiles.list: hashto_files.setdefault(f.hash, []).append(f) - files_new = set(map(lambda x:x.hash, newfiles.list)) - files_old = set(map(lambda x:x.hash, oldfiles.list)) + files_new = set(map(lambda x: x.hash, newfiles.list)) + files_old = set(map(lambda x: x.hash, oldfiles.list)) files_delta = files_new - files_old deltas = [] for h in files_delta: deltas.extend(hashto_files[h]) - # Directory hashes are None. There was a bug with PolicyKit that should have an empty directory. - if hashto_files.has_key(None): + # Directory hashes are None. There was a bug with PolicyKit that + # should have an empty directory. + if None in hashto_files: deltas.extend(hashto_files[None]) return deltas