|
Panu Matilainen |
7bc2da |
commit 62bdcc0a32d07a7423876b3ae17900da04eb8a97
|
|
Panu Matilainen |
7bc2da |
Author: Jan Silhan <jsilhan@redhat.com>
|
|
Panu Matilainen |
7bc2da |
Date: Fri Oct 18 18:30:52 2013 +0200
|
|
Panu Matilainen |
7bc2da |
|
|
Panu Matilainen |
7bc2da |
Python 3 compatibility fixes
|
|
Panu Matilainen |
7bc2da |
|
|
Panu Matilainen |
7bc2da |
- Use open() instead of calling file constructor
|
|
Panu Matilainen |
7bc2da |
- Borrow python-six trick of dealing with difference in string types
|
|
Panu Matilainen |
7bc2da |
|
|
Panu Matilainen |
7bc2da |
Signed-off-by: Panu Matilainen <pmatilai@redhat.com>
|
|
Panu Matilainen |
7bc2da |
|
|
Panu Matilainen |
7bc2da |
diff --git a/python/rpm/transaction.py b/python/rpm/transaction.py
|
|
Panu Matilainen |
7bc2da |
index 756e893..df72ce9 100644
|
|
Panu Matilainen |
7bc2da |
--- a/python/rpm/transaction.py
|
|
Panu Matilainen |
7bc2da |
+++ b/python/rpm/transaction.py
|
|
Panu Matilainen |
7bc2da |
@@ -1,8 +1,14 @@
|
|
Panu Matilainen |
7bc2da |
#!/usr/bin/python
|
|
Panu Matilainen |
7bc2da |
|
|
Panu Matilainen |
7bc2da |
+import sys
|
|
Panu Matilainen |
7bc2da |
import rpm
|
|
Panu Matilainen |
7bc2da |
from rpm._rpm import ts as TransactionSetCore
|
|
Panu Matilainen |
7bc2da |
|
|
Panu Matilainen |
7bc2da |
+if sys.version_info[0] == 3:
|
|
Panu Matilainen |
7bc2da |
+ _string_types = str,
|
|
Panu Matilainen |
7bc2da |
+else:
|
|
Panu Matilainen |
7bc2da |
+ _string_types = basestring,
|
|
Panu Matilainen |
7bc2da |
+
|
|
Panu Matilainen |
7bc2da |
# TODO: migrate relevant documentation from C-side
|
|
Panu Matilainen |
7bc2da |
class TransactionSet(TransactionSetCore):
|
|
Panu Matilainen |
7bc2da |
_probFilter = 0
|
|
Panu Matilainen |
7bc2da |
@@ -45,14 +51,14 @@ class TransactionSet(TransactionSetCore):
|
|
Panu Matilainen |
7bc2da |
return tuple(keys)
|
|
Panu Matilainen |
7bc2da |
|
|
Panu Matilainen |
7bc2da |
def addInstall(self, item, key, how="u"):
|
|
Panu Matilainen |
7bc2da |
- if isinstance(item, basestring):
|
|
Panu Matilainen |
7bc2da |
- f = file(item)
|
|
Panu Matilainen |
7bc2da |
+ if isinstance(item, _string_types):
|
|
Panu Matilainen |
7bc2da |
+ f = open(item)
|
|
Panu Matilainen |
7bc2da |
header = self.hdrFromFdno(f)
|
|
Panu Matilainen |
7bc2da |
f.close()
|
|
Panu Matilainen |
7bc2da |
- elif isinstance(item, file):
|
|
Panu Matilainen |
7bc2da |
- header = self.hdrFromFdno(item)
|
|
Panu Matilainen |
7bc2da |
- else:
|
|
Panu Matilainen |
7bc2da |
+ elif isinstance(item, rpm.hdr):
|
|
Panu Matilainen |
7bc2da |
header = item
|
|
Panu Matilainen |
7bc2da |
+ else:
|
|
Panu Matilainen |
7bc2da |
+ header = self.hdrFromFdno(item)
|
|
Panu Matilainen |
7bc2da |
|
|
Panu Matilainen |
7bc2da |
if not how in ['u', 'i']:
|
|
Panu Matilainen |
7bc2da |
raise ValueError('how argument must be "u" or "i"')
|
|
Panu Matilainen |
7bc2da |
@@ -69,7 +75,7 @@ class TransactionSet(TransactionSetCore):
|
|
Panu Matilainen |
7bc2da |
hdrs = item
|
|
Panu Matilainen |
7bc2da |
elif isinstance(item, int):
|
|
Panu Matilainen |
7bc2da |
hdrs = self.dbMatch(rpm.RPMDBI_PACKAGES, item)
|
|
Panu Matilainen |
7bc2da |
- elif isinstance(item, basestring):
|
|
Panu Matilainen |
7bc2da |
+ elif isinstance(item, _string_types):
|
|
Panu Matilainen |
7bc2da |
hdrs = self.dbMatch(rpm.RPMDBI_LABEL, item)
|
|
Panu Matilainen |
7bc2da |
else:
|
|
Panu Matilainen |
7bc2da |
raise TypeError("invalid type %s" % type(item))
|