From b5eb3c2d488aa4acc671a028f656b30933eee5be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?S=2E=C3=87a=C4=9Flar=20Onur?= Date: Fri, 17 Feb 2006 05:04:21 +0000 Subject: [PATCH] initial xdelta support, not well tested :P --- pisi/constants.py | 1 + pisi/package.py | 45 ++++++++++++++++++++++++++++++++++++++++----- pisi/util.py | 12 ++++++++++++ 3 files changed, 53 insertions(+), 5 deletions(-) diff --git a/pisi/constants.py b/pisi/constants.py index 95e06748..91860158 100644 --- a/pisi/constants.py +++ b/pisi/constants.py @@ -47,6 +47,7 @@ class Constants: def __init__(self): # prefix for package names self.__c.package_suffix = ".pisi" + self.__c.xdelta_suffix = ".xdelta" # directory suffixes for build self.__c.work_dir_suffix = "/work" diff --git a/pisi/package.py b/pisi/package.py index a1101e0f..662383de 100644 --- a/pisi/package.py +++ b/pisi/package.py @@ -15,7 +15,7 @@ # maintainer: baris and meren -from os.path import join, exists +from os.path import join, exists, basename, dirname import gettext __trans = gettext.translation('pisi', fallback=True) @@ -39,16 +39,51 @@ class Package: def __init__(self, packagefn, mode='r'): self.filepath = packagefn url = URI(packagefn) - + if url.is_remote_file(): - from fetcher import fetch_url + from fetcher import fetch_url, FetchError dest = ctx.config.packages_dir() self.filepath = join(dest, url.filename()) - + + # get current package name without version info (like tasma) + current_pkg = util.pure_package_name(url.filename()) + + # if package is installed (which means we are upgrading it), + # calculate needed info + if ctx.installdb.is_installed(current_pkg): + installed = True + + # calculate currently installed package's name and pisi file's location + (version, release, build) = ctx.installdb.get_version(current_pkg) + current = util.package_name(current_pkg, version, release, build, prependSuffix=False) + current_fn = join(dest, current) + ctx.const.package_suffix + + # calculate xdelta file location (format: oldpackage_newpackage.xdelta) + # ex: tasma-1.0.2-4-1_tasma-1.0.3-5-2.xdelta + delta = basename(url.filename()).strip(ctx.const.package_suffix) + delta = "%s_%s" % (current, delta) + ctx.const.xdelta_suffix + + # create xdelta_url for fetching + xdelta_url = URI(join(dirname(str(url)), delta)) + xdelta_fn = join(dest, xdelta_url.filename()) + else: + installed = False + # FIXME: exists is not enough, also sha1sum check needed # when implemented in pisi-index.xml if not exists(self.filepath): - fetch_url(url, dest, ctx.ui.Progress) + if installed and exists(current_fn): + # if package is installed and old pisi file exists, fetch xdelta + if not exists(xdelta_fn): + ctx.ui.debug(_("Package xdelta URI: %s") % xdelta_url) + try: + fetch_url(xdelta_url, dest, ctx.ui.Progress) + except FetchError: + pass + # generate new one using old pisi file and xdelta + util.generate_pisi_file(xdelta_fn, current_fn, self.filepath) + else: + fetch_url(url, dest, ctx.ui.Progress) else: ctx.ui.info(_('%s [cached]') % url.filename()) diff --git a/pisi/util.py b/pisi/util.py index efddea3f..566f893c 100644 --- a/pisi/util.py +++ b/pisi/util.py @@ -610,3 +610,15 @@ def env_update(): # run ldconfig run_batch("/sbin/ldconfig -X -r %s" % ctx.config.dest_dir()) + +def pure_package_name(package_name): + "return pure package name from given string" + "ex: package_name=tasma-1.0.3-5-2.pisi, returns tasma" + + if package_name.endswith(ctx.const.package_suffix): + package_name = package_name.strip(ctx.const.package_suffix) + + return '-'.join([part for part in package_name.split('-') if part[0] not in string.digits]) + +def generate_pisi_file(patchFile, fromFile, toFile): + run_batch("xdelta patch %s %s %s" % (patchFile, fromFile, toFile))