initial xdelta support, not well tested :P

This commit is contained in:
S.Çağlar Onur
2006-02-17 05:04:21 +00:00
parent 7268894c85
commit b5eb3c2d48
3 changed files with 53 additions and 5 deletions
+1
View File
@@ -47,6 +47,7 @@ class Constants:
def __init__(self): def __init__(self):
# prefix for package names # prefix for package names
self.__c.package_suffix = ".pisi" self.__c.package_suffix = ".pisi"
self.__c.xdelta_suffix = ".xdelta"
# directory suffixes for build # directory suffixes for build
self.__c.work_dir_suffix = "/work" self.__c.work_dir_suffix = "/work"
+40 -5
View File
@@ -15,7 +15,7 @@
# maintainer: baris and meren # maintainer: baris and meren
from os.path import join, exists from os.path import join, exists, basename, dirname
import gettext import gettext
__trans = gettext.translation('pisi', fallback=True) __trans = gettext.translation('pisi', fallback=True)
@@ -39,16 +39,51 @@ class Package:
def __init__(self, packagefn, mode='r'): def __init__(self, packagefn, mode='r'):
self.filepath = packagefn self.filepath = packagefn
url = URI(packagefn) url = URI(packagefn)
if url.is_remote_file(): if url.is_remote_file():
from fetcher import fetch_url from fetcher import fetch_url, FetchError
dest = ctx.config.packages_dir() dest = ctx.config.packages_dir()
self.filepath = join(dest, url.filename()) 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 # FIXME: exists is not enough, also sha1sum check needed
# when implemented in pisi-index.xml # when implemented in pisi-index.xml
if not exists(self.filepath): 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: else:
ctx.ui.info(_('%s [cached]') % url.filename()) ctx.ui.info(_('%s [cached]') % url.filename())
+12
View File
@@ -610,3 +610,15 @@ def env_update():
# run ldconfig # run ldconfig
run_batch("/sbin/ldconfig -X -r %s" % ctx.config.dest_dir()) 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))