Seth Vidal b9ff2ac
From 0924c6540eeff8ac086c7b3ce9e0ca355a9bd258 Mon Sep 17 00:00:00 2001
Seth Vidal b9ff2ac
From: Bill Nottingham <notting@redhat.com>
Seth Vidal b9ff2ac
Date: Fri, 21 Aug 2009 14:45:07 -0400
Seth Vidal b9ff2ac
Subject: [PATCH] Use deltarpm bindings rather than parsing them ourselves.
Seth Vidal b9ff2ac
Seth Vidal b9ff2ac
---
Seth Vidal b9ff2ac
 createrepo/deltarpms.py |   32 ++++++++------------------------
Seth Vidal b9ff2ac
 1 files changed, 8 insertions(+), 24 deletions(-)
Seth Vidal b9ff2ac
Seth Vidal b9ff2ac
diff --git a/createrepo/deltarpms.py b/createrepo/deltarpms.py
Seth Vidal b9ff2ac
index 26a6715..d14d3fa 100644
Seth Vidal b9ff2ac
--- a/createrepo/deltarpms.py
Seth Vidal b9ff2ac
+++ b/createrepo/deltarpms.py
Seth Vidal b9ff2ac
@@ -18,7 +18,7 @@
Seth Vidal b9ff2ac
 import os.path
Seth Vidal b9ff2ac
 import commands
Seth Vidal b9ff2ac
 from yum import misc
Seth Vidal b9ff2ac
-import gzip
Seth Vidal b9ff2ac
+import deltarpm
Seth Vidal b9ff2ac
 from utils import MDError
Seth Vidal b9ff2ac
 
Seth Vidal b9ff2ac
 class DeltaRPMPackage:
Seth Vidal b9ff2ac
@@ -44,17 +44,16 @@ class DeltaRPMPackage:
Seth Vidal b9ff2ac
         os.lseek(fd, 0, 0)
Seth Vidal b9ff2ac
         fo = os.fdopen(fd, 'rb')
Seth Vidal b9ff2ac
         self.csum = misc.checksum(self.csum_type, fo)
Seth Vidal b9ff2ac
-        fo.seek(int(self.po.hdrend))
Seth Vidal b9ff2ac
-        self._getOldInfo(fo)
Seth Vidal b9ff2ac
         del fo
Seth Vidal b9ff2ac
         del fd
Seth Vidal b9ff2ac
+        self._getDRPMInfo(os.path.join(basedir, filename))
Seth Vidal b9ff2ac
                     
Seth Vidal b9ff2ac
     def _stringToNEVR(self, string):
Seth Vidal b9ff2ac
         i = string.rfind("-", 0, string.rfind("-")-1)
Seth Vidal b9ff2ac
         name = string[:i]
Seth Vidal b9ff2ac
         (epoch, ver, rel) = self._stringToVersion(string[i+1:])
Seth Vidal b9ff2ac
         return (name, epoch, ver, rel)
Seth Vidal b9ff2ac
-        
Seth Vidal b9ff2ac
+
Seth Vidal b9ff2ac
     def _getLength(self, in_data):
Seth Vidal b9ff2ac
         length = 0
Seth Vidal b9ff2ac
         for val in in_data:
Seth Vidal b9ff2ac
@@ -62,27 +61,12 @@ class DeltaRPMPackage:
Seth Vidal b9ff2ac
             length += ord(val)
Seth Vidal b9ff2ac
         return length
Seth Vidal b9ff2ac
         
Seth Vidal b9ff2ac
-    def _getOldInfo(self, fo):
Seth Vidal b9ff2ac
-        try:
Seth Vidal b9ff2ac
-            compobj = gzip.GzipFile("", "rb", 9, fo)
Seth Vidal b9ff2ac
-        except:
Seth Vidal b9ff2ac
-            raise zlibError("Data not stored in gzip format")
Seth Vidal b9ff2ac
-            
Seth Vidal b9ff2ac
-        if compobj.read(4)[:3] != "DLT":
Seth Vidal b9ff2ac
-            raise Exception("Not a deltarpm")
Seth Vidal b9ff2ac
+    def _getDRPMInfo(self, filename):
Seth Vidal b9ff2ac
+        d = deltarpm.readDeltaRPM(filename)
Seth Vidal b9ff2ac
+        self.oldnevrstring = d['old_nevr']
Seth Vidal b9ff2ac
+        self.oldnevr = self._stringToNEVR(d['old_nevr'])
Seth Vidal b9ff2ac
+        self.sequence = d['seq']
Seth Vidal b9ff2ac
         
Seth Vidal b9ff2ac
-        nevr_length = self._getLength(compobj.read(4))
Seth Vidal b9ff2ac
-        nevr = compobj.read(nevr_length).strip("\x00")
Seth Vidal b9ff2ac
-        seq_length = self._getLength(compobj.read(4))
Seth Vidal b9ff2ac
-        seq = compobj.read(seq_length)
Seth Vidal b9ff2ac
-        hex_seq = ""
Seth Vidal b9ff2ac
-        for char in seq:
Seth Vidal b9ff2ac
-            hex_seq += str("%02x" % ord(char))
Seth Vidal b9ff2ac
-        self.oldnevrstring = nevr
Seth Vidal b9ff2ac
-        self.oldnevr = self._stringToNEVR(nevr)
Seth Vidal b9ff2ac
-        self.sequence = hex_seq
Seth Vidal b9ff2ac
-        compobj.close()
Seth Vidal b9ff2ac
-            
Seth Vidal b9ff2ac
     def _stringToVersion(self, strng):
Seth Vidal b9ff2ac
         i = strng.find(':')
Seth Vidal b9ff2ac
         if i != -1:
Seth Vidal b9ff2ac
-- 
Seth Vidal b9ff2ac
1.6.4
Seth Vidal b9ff2ac