Push most work of ts.addInstall() over to python
[platform/upstream/rpm.git] / python / rpm / transaction.py
1 #!/usr/bin/python
2
3 import _rpm
4
5 # TODO: migrate relevant documentation from C-side
6 class TransactionSet(_rpm.ts):
7     # FIXME: kludge for keeping refcounts on transaction element keys
8     _keyList = []
9
10     def _wrapSetGet(self, attr, val):
11         oval = getattr(self, attr)
12         setattr(self, attr, val)
13         return oval
14         
15     def setVSFlags(self, flags):
16         return self._wrapSetGet('_vsflags', flags)
17
18     def getVSFlags(self):
19         return self._vsflags
20
21     def setColor(self, color):
22         return self._wrapSetGet('_color', color)
23
24     def setPrefColor(self, color):
25         return self._wrapSetGet('_prefcolor', color)
26
27     def setFlags(self, flags):
28         return self._wrapSetGet('_flags', flags)
29
30     def setProbFilter(self, ignoreSet):
31         return self._wrapSetGet('_probFilter', ignoreSet)
32
33     def parseSpec(self, specfile):
34         import _rpmb
35         return _rpmb.spec(specfile)
36
37     def getKeys(self):
38         keys = []
39         for te in self:
40             keys.append(te.Key())
41         # Backwards compatibility goo - WTH does this return a *tuple* ?!
42         if not keys:
43             return None
44         else:
45             return tuple(keys)
46
47     def addInstall(self, header, key, how="u"):
48         if not how in ['u', 'i']:
49             raise ValueError, 'how argument must be "u" or "i"'
50         upgrade = (how == "u")
51
52         if not _rpm.ts.addInstall(self, header, key, upgrade):
53             raise _rpm.error, "adding package to transaction failed"
54         self._keyList.append(key)