4 from rpm._rpm import ts as _rpmts
6 # TODO: migrate relevant documentation from C-side
7 class TransactionSet(_rpmts):
9 # FIXME: kludge for keeping refcounts on transaction element keys
12 def _wrapSetGet(self, attr, val):
13 oval = getattr(self, attr)
14 setattr(self, attr, val)
17 def setVSFlags(self, flags):
18 return self._wrapSetGet('_vsflags', flags)
23 def setColor(self, color):
24 return self._wrapSetGet('_color', color)
26 def setPrefColor(self, color):
27 return self._wrapSetGet('_prefcolor', color)
29 def setFlags(self, flags):
30 return self._wrapSetGet('_flags', flags)
32 def setProbFilter(self, ignoreSet):
33 return self._wrapSetGet('_probFilter', ignoreSet)
35 def parseSpec(self, specfile):
37 return _rpmb.spec(specfile)
43 # Backwards compatibility goo - WTH does this return a *tuple* ?!
49 def addInstall(self, item, key, how="u"):
50 if isinstance(item, str):
52 header = self.hdrFromFdno(f)
54 elif isinstance(item, file):
55 header = self.hdrFromFdno(item)
59 if not how in ['u', 'i']:
60 raise ValueError('how argument must be "u" or "i"')
61 upgrade = (how == "u")
63 if not _rpmts.addInstall(self, header, key, upgrade):
64 raise rpm.error("adding package to transaction failed")
65 self._keyList.append(key)
67 def addErase(self, item):
69 if isinstance(item, rpm.hdr):
71 elif isinstance(item, rpm.mi):
73 elif isinstance(item, int):
74 hdrs = self.dbMatch(rpm.RPMDBI_PACKAGES, item)
75 elif isinstance(item, str):
76 hdrs = self.dbMatch(rpm.RPMDBI_LABEL, item)
78 raise TypeError("invalid type %s" % type(item))
81 if not _rpmts.addErase(self, h):
82 raise rpm.error("package not installed")
84 # garbage collection should take care but just in case...
85 if isinstance(hdrs, rpm.mi):
88 def run(self, callback, data):
89 rc = _rpmts.run(self, callback, data, self._probFilter)
91 # crazy backwards compatibility goo: None for ok, list of problems
92 # if transaction didnt complete and empty list if it completed
99 for prob in self.problems():
100 item = ("%s" % prob, (prob.type, prob._str, prob._num))
104 def check(self, *args, **kwds):
105 _rpmts.check(self, *args, **kwds)
107 # compatibility: munge problem strings into dependency tuples of doom
109 for p in self.problems():
110 # is it anything we need to care about?
111 if p.type == rpm.RPMPROB_CONFLICT:
112 sense = rpm.RPMDEP_SENSE_CONFLICTS
113 elif p.type == rpm.RPMPROB_REQUIRES:
114 sense = rpm.RPMDEP_SENSE_REQUIRES
118 # strip arch, split to name, version, release
119 nevr = p.pkgNEVR.rsplit('.', 1)[0]
120 n, v, r = nevr.rsplit('-', 2)
122 # extract the dependency information
123 needs = p.altNEVR.split()[1:]
125 needflags = rpm.RPMSENSE_ANY
128 if needop.find('<') >= 0: needflags |= rpm.RPMSENSE_LESS
129 if needop.find('=') >= 0: needflags |= rpm.RPMSENSE_EQUAL
130 if needop.find('>') >= 0: needflags |= rpm.RPMSENSE_GREATER
135 res.append(((n, v, r),(needname,needver),needflags,sense,p.key))
139 def hdrCheck(self, blob):
140 res, msg = _rpmts.hdrCheck(self, blob)
141 # generate backwards compatibly broken exceptions
142 if res == rpm.RPMRC_NOKEY:
143 raise rpm.error("public key not available")
144 elif res == rpm.RPMRC_NOTTRUSTED:
145 raise rpm.error("public key not trusted")
146 elif res != rpm.RPMRC_OK:
149 def hdrFromFdno(self, fd):
150 res, h = _rpmts.hdrFromFdno(self, fd)
151 # generate backwards compatibly broken exceptions
152 if res == rpm.RPMRC_NOKEY:
153 raise rpm.error("public key not available")
154 elif res == rpm.RPMRC_NOTTRUSTED:
155 raise rpm.error("public key not trusted")
156 elif res != rpm.RPMRC_OK:
157 raise rpm.error("error reading package header")