Package rpmUtils :: Module transaction
[hide private]
[frames] | no frames]

Source Code for Module rpmUtils.transaction

  1  #!/usr/bin/python 
  2   
  3  # 
  4  # Client code for Update Agent 
  5  # Copyright (c) 1999-2002 Red Hat, Inc.  Distributed under GPL. 
  6  # 
  7  #         Adrian Likins <alikins@redhat.com> 
  8  # Some Edits by Seth Vidal <skvidal@phy.duke.edu> 
  9  # 
 10  # a couple of classes wrapping up transactions so that we   
 11  #    can share transactions instead of creating new ones all over 
 12  # 
 13   
 14  import rpm 
 15  import miscutils 
 16   
 17  read_ts = None 
 18  ts = None 
 19   
 20  # wrapper/proxy class for rpm.Transaction so we can 
 21  # instrument it, etc easily 
22 -class TransactionWrapper:
23 - def __init__(self, root='/'):
24 self.ts = rpm.TransactionSet(root) 25 self._methods = ['dbMatch', 26 'check', 27 'order', 28 'addErase', 29 'addInstall', 30 'run', 31 'IDTXload', 32 'IDTXglob', 33 'rollback', 34 'pgpImportPubkey', 35 'pgpPrtPkts', 36 'Debug', 37 'problems', 38 'setFlags', 39 'setVSFlags', 40 'setProbFilter', 41 'hdrFromFdno', 42 'next', 43 'clean'] 44 self.tsflags = [] 45 self.open = True
46
47 - def __del__(self):
48 # Automatically close the rpm transaction when the reference is lost 49 self.close()
50
51 - def close(self):
52 if self.open: 53 self.ts.closeDB() 54 self.ts = None 55 self.open = False
56
57 - def __getattr__(self, attr):
58 if attr in self._methods: 59 return self.getMethod(attr) 60 else: 61 raise AttributeError, attr
62
63 - def __iter__(self):
64 return self.ts
65
66 - def getMethod(self, method):
67 # in theory, we can override this with 68 # profile/etc info 69 return getattr(self.ts, method)
70 71 # push/pop methods so we dont lose the previous 72 # set value, and we can potentiall debug a bit 73 # easier
74 - def pushVSFlags(self, flags):
75 self.tsflags.append(flags) 76 self.ts.setVSFlags(self.tsflags[-1])
77
78 - def popVSFlags(self):
79 del self.tsflags[-1] 80 self.ts.setVSFlags(self.tsflags[-1])
81
82 - def addTsFlag(self, flag):
83 curflags = self.ts.setFlags(0) 84 self.ts.setFlags(curflags | flag)
85 86 # def addProblemFilter(self, filt): 87 # curfilter = self.ts.setProbFilter(0) 88 # self.ts.setProbFilter(cutfilter | filt) 89
90 - def test(self, cb, conf={}):
91 """tests the ts we've setup, takes a callback function and a conf dict 92 for flags and what not""" 93 94 self.addTsFlag(rpm.RPMTRANS_FLAG_TEST) 95 # FIXME GARBAGE - remove once this is reimplemented elsehwere 96 # KEEPING FOR API COMPLIANCE ONLY 97 if conf.has_key('diskspacecheck'): 98 if conf['diskspacecheck'] == 0: 99 self.ts.setProbFilter(rpm.RPMPROB_FILTER_DISKSPACE) 100 tserrors = self.ts.run(cb.callback, '') 101 102 reserrors = [] 103 if tserrors: 104 for (descr, (etype, mount, need)) in tserrors: 105 reserrors.append(descr) 106 107 return reserrors
108 109
110 - def returnLeafNodes(self, headers=False):
111 """returns a list of package tuples (n,a,e,v,r) that are not required by 112 any other package on the system 113 If headers is True then it will return a list of (header, index) tuples 114 """ 115 116 req = {} 117 orphan = [] 118 119 mi = self.dbMatch() 120 if mi is None: # this is REALLY unlikely but let's just say it for the moment 121 return orphan 122 123 # prebuild the req dict 124 for h in mi: 125 if h['name'] == 'gpg-pubkey': 126 continue 127 if not h[rpm.RPMTAG_REQUIRENAME]: 128 continue 129 tup = miscutils.pkgTupleFromHeader(h) 130 for r in h[rpm.RPMTAG_REQUIRENAME]: 131 if r not in req: 132 req[r] = set() 133 req[r].add(tup) 134 135 136 mi = self.dbMatch() 137 if mi is None: 138 return orphan 139 140 def _return_all_provides(hdr): 141 """ Return all the provides, via yield. """ 142 # These are done one by one, so that we get lazy loading 143 for prov in hdr[rpm.RPMTAG_PROVIDES]: 144 yield prov 145 for prov in hdr[rpm.RPMTAG_FILENAMES]: 146 yield prov
147 148 for h in mi: 149 if h['name'] == 'gpg-pubkey': 150 continue 151 preq = 0 152 tup = miscutils.pkgTupleFromHeader(h) 153 for p in _return_all_provides(h): 154 if req.has_key(p): 155 # Don't count a package that provides its require 156 s = req[p] 157 if len(s) > 1 or tup not in s: 158 preq = preq + 1 159 break 160 161 if preq == 0: 162 if headers: 163 orphan.append((h, mi.instance())) 164 else: 165 orphan.append(tup) 166 167 return orphan
168 169
170 -def initReadOnlyTransaction(root='/'):
171 read_ts = TransactionWrapper(root=root) 172 read_ts.pushVSFlags((rpm._RPMVSF_NOSIGNATURES|rpm._RPMVSF_NODIGESTS)) 173 return read_ts
174