1 from __future__ import with_statement
4 import @PYTHON_MODULENAME@ as rpm
5 from @PYTHON_MODULENAME@._rpm import ts as TransactionSetCore
7 if sys.version_info[0] == 3:
10 _string_types = basestring,
13 # TODO: migrate relevant documentation from C-side
14 class TransactionSet(TransactionSetCore):
17 def _wrapSetGet(self, attr, val):
18 oval = getattr(self, attr)
19 setattr(self, attr, val)
22 def setVSFlags(self, flags):
23 return self._wrapSetGet('_vsflags', flags)
28 def setColor(self, color):
29 return self._wrapSetGet('_color', color)
31 def setPrefColor(self, color):
32 return self._wrapSetGet('_prefcolor', color)
34 def setFlags(self, flags):
35 return self._wrapSetGet('_flags', flags)
37 def setProbFilter(self, ignoreSet):
38 return self._wrapSetGet('_probFilter', ignoreSet)
40 def parseSpec(self, specfile):
41 return rpm.spec(specfile)
47 # Backwards compatibility goo - WTH does this return a *tuple* ?!
53 def _f2hdr(self, item):
54 if isinstance(item, _string_types):
56 header = self.hdrFromFdno(f)
57 elif isinstance(item, rpm.hdr):
60 header = self.hdrFromFdno(item)
63 def addInstall(self, item, key, how="u"):
64 header = self._f2hdr(item)
66 if how not in ['u', 'i']:
67 raise ValueError('how argument must be "u" or "i"')
68 upgrade = (how == "u")
70 if not TransactionSetCore.addInstall(self, header, key, upgrade):
71 raise rpm.error("adding package to transaction failed")
73 def addReinstall(self, item, key):
74 header = self._f2hdr(item)
76 if not TransactionSetCore.addReinstall(self, header, key):
77 raise rpm.error("adding package to transaction failed")
79 def addErase(self, item):
81 if isinstance(item, rpm.hdr):
83 elif isinstance(item, rpm.mi):
85 elif isinstance(item, int):
86 hdrs = self.dbMatch(rpm.RPMDBI_PACKAGES, item)
87 elif isinstance(item, _string_types):
88 hdrs = self.dbMatch(rpm.RPMDBI_LABEL, item)
90 raise TypeError("invalid type %s" % type(item))
93 if not TransactionSetCore.addErase(self, h):
94 raise rpm.error("package not installed")
96 # garbage collection should take care but just in case...
97 if isinstance(hdrs, rpm.mi):
100 def run(self, callback, data):
101 rc = TransactionSetCore.run(self, callback, data, self._probFilter)
103 # crazy backwards compatibility goo: None for ok, list of problems
104 # if transaction didn't complete and empty list if it completed
111 for prob in self.problems():
112 item = ("%s" % prob, (prob.type, prob._str, prob._num))
116 def check(self, *args, **kwds):
117 TransactionSetCore.check(self, *args, **kwds)
119 # compatibility: munge problem strings into dependency tuples of doom
121 for p in self.problems():
122 # is it anything we need to care about?
123 if p.type == rpm.RPMPROB_CONFLICT:
124 sense = rpm.RPMDEP_SENSE_CONFLICTS
125 elif p.type == rpm.RPMPROB_REQUIRES:
126 sense = rpm.RPMDEP_SENSE_REQUIRES
130 # strip arch, split to name, version, release
131 nevr = p.altNEVR.rsplit('.', 1)[0]
132 n, v, r = nevr.rsplit('-', 2)
134 # extract the dependency information
135 needs = p._str.split()
137 needflags = rpm.RPMSENSE_ANY
141 needflags |= rpm.RPMSENSE_LESS
143 needflags |= rpm.RPMSENSE_EQUAL
145 needflags |= rpm.RPMSENSE_GREATER
150 res.append(((n, v, r),
151 (needname, needver), needflags, sense, p.key))
155 def hdrCheck(self, blob):
156 res, msg = TransactionSetCore.hdrCheck(self, blob)
157 # generate backwards compatibly broken exceptions
158 if res == rpm.RPMRC_NOKEY:
159 raise rpm.error("public key not available")
160 elif res == rpm.RPMRC_NOTTRUSTED:
161 raise rpm.error("public key not trusted")
162 elif res != rpm.RPMRC_OK:
165 def hdrFromFdno(self, fd):
166 res, h = TransactionSetCore.hdrFromFdno(self, fd)
167 # generate backwards compatibly broken exceptions
168 if res == rpm.RPMRC_NOKEY:
169 raise rpm.error("public key not available")
170 elif res == rpm.RPMRC_NOTTRUSTED:
171 raise rpm.error("public key not trusted")
172 elif res != rpm.RPMRC_OK:
173 raise rpm.error("error reading package header")