diff options
Diffstat (limited to 'yum-deltarpm.py')
-rw-r--r-- | yum-deltarpm.py | 76 |
1 files changed, 76 insertions, 0 deletions
diff --git a/yum-deltarpm.py b/yum-deltarpm.py new file mode 100644 index 0000000..4b2ad10 --- /dev/null +++ b/yum-deltarpm.py @@ -0,0 +1,76 @@ +# author: Lars Herrmann <herrmann@redhat.com> +# license: GPL (see COPYING file in distribution) +# + +from yum.plugins import PluginYumExit, TYPE_INTERACTIVE + +import os +import sys + +sys.path.append("/usr/share/deltarpm-python") +import deltarpm + +deltarpm.DEBUG = 1 + +requires_api_version = '2.1' +plugin_type = (TYPE_INTERACTIVE,) + + +def predownload_hook(conduit): + rpmdb = conduit.getRpmDB() + up2date_cfg={} + + # Read configuration + conduit.info(2, 'Reading deltarpm configuration') + delta_rpm_url = conduit.confString('main', 'deltaRpmURL') + + if not delta_rpm_url: + conduit.error(2, 'deltaRpmURL not set in deltarpm plugin config') + + # set delta storage dir if provide, else fallback to default + delta_storage_dir = conduit.confString('main', 'deltaStorageDir') + if delta_storage_dir: + up2date_cfg[deltarpm.DELTA_STORAGE] = delta_storage_dir + + # get up2date config and adjust some values for use with yum + ## up2date_cfg = config.initUp2dateConfig() + up2date_cfg[deltarpm.USE_DELTA] = 1 + up2date_cfg[deltarpm.DELTA_URL] = delta_rpm_url + + for p in conduit.getDownloadPackages(): + # 0. Maybe rpm is already there? + #if os.path.exists(p.localpath): + # conduit.info(2, "target rpm already exists in cache - continue") + # continue + + # 1. Is the package already installed? + installed = rpmdb.returnTupleByKeyword(name=p.name) + if not installed: + # Package not installed so fetching delta makes no sense + continue + + # 2. Try to fetch deltarpm + filename = os.path.basename(p.localpath) + # Set the storage path for this package + up2date_cfg[deltarpm.STORAGE] = os.path.dirname(p.localpath) + + try: + # invoke getPackageFromDelta method + # this method does all the work: reading config, fetching delta + # and reconstructing the new rpm. if something goes wrong, an + # exception is thrown + package = [p.name, p.version, p.release, p.epoch, p.arch] + # FIXME: handle this in deltarpm.py + if (package[3] == '0'): + package[3] = 0 + deltarpm.getPackageFromDelta(up2date_cfg, package) + + except Exception, e: + # Warn about failure + print "could not use delta rpm for %s: %s" % (filename, e) + # And remove anything we might have created + try: + os.unlink(p.localpath) + except OSError, msg: + pass + #raise PluginYumExit('exiting for testing in predownload hook ') |