summaryrefslogtreecommitdiffstats
path: root/yum-deltarpm.py
blob: 4b2ad10a38da3a7493d0662a244bdca7ef8cd6f2 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
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 ')