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 probs = self.problems()
111 # compatibility: munge problem strings into dependency tuples of doom
114 # is it anything we need to care about?
115 if p.type == rpm.RPMPROB_CONFLICT:
116 sense = rpm.RPMDEP_SENSE_CONFLICTS
117 elif p.type == rpm.RPMPROB_REQUIRES:
118 sense = rpm.RPMDEP_SENSE_REQUIRES
122 # strip arch, split to name, version, release
123 nevr = p.pkgNEVR.rsplit('.', 1)[0]
124 n, v, r = nevr.rsplit('-', 2)
126 # extract the dependency information
127 needs = p.altNEVR.split()[1:]
129 needflags = rpm.RPMSENSE_ANY
132 if needop.find('<') >= 0: needflags |= rpm.RPMSENSE_LESS
133 if needop.find('=') >= 0: needflags |= rpm.RPMSENSE_EQUAL
134 if needop.find('>') >= 0: needflags |= rpm.RPMSENSE_GREATER
139 res.append(((n, v, r),(needname,needver),needflags,sense,p.key))
143 def hdrCheck(self, blob):
144 res, msg = _rpmts.hdrCheck(self, blob)
145 # generate backwards compatibly broken exceptions
146 if res == rpm.RPMRC_NOKEY:
147 raise rpm.error("public key not available")
148 elif res == rpm.RPMRC_NOTTRUSTED:
149 raise rpm.error("public key not trusted")
150 elif res != rpm.RPMRC_OK:
153 def hdrFromFdno(self, fd):
154 res, h = _rpmts.hdrFromFdno(self, fd)
155 # generate backwards compatibly broken exceptions
156 if res == rpm.RPMRC_NOKEY:
157 raise rpm.error("public key not available")
158 elif res == rpm.RPMRC_NOTTRUSTED:
159 raise rpm.error("public key not trusted")
160 elif res != rpm.RPMRC_OK:
161 raise rpm.error("error reading package header")