Permit file objects and file names to ts.addInstall()
authorPanu Matilainen <pmatilai@redhat.com>
Fri, 2 Oct 2009 18:41:41 +0000 (21:41 +0300)
committerPanu Matilainen <pmatilai@redhat.com>
Fri, 2 Oct 2009 18:41:41 +0000 (21:41 +0300)
- largely removes the need for the klunky ts.hdrFromFdno()

python/rpm/transaction.py

index dcb28d4..9c8de0c 100644 (file)
@@ -44,7 +44,16 @@ class TransactionSet(_rpm.ts):
         else:
             return tuple(keys)
 
-    def addInstall(self, header, key, how="u"):
+    def addInstall(self, item, key, how="u"):
+        if isinstance(item, str):
+            f = file(item)
+            header = self.hdrFromFdno(f)
+            f.close()
+        elif isinstance(item, file):
+            header = self.hdrFromFdno(item)
+        else:
+            header = item
+
         if not how in ['u', 'i']:
             raise ValueError, 'how argument must be "u" or "i"'
         upgrade = (how == "u")