[Yum-devel] [PATCH 2/4] _commonRetrieveDataMD(): split the code

Zdeněk Pavlas zpavlas at redhat.com
Wed Mar 28 15:06:38 UTC 2012


Add _commonRetrieveDataMD_list() that returns the list of metadata
objects to be downloaded.

Add _commonRetrieveDataMD_done() to unpack and commit new files
after they have been succesfully downloaded.
---
 yum/yumRepo.py |   47 +++++++++++++++++------------------------------
 1 files changed, 17 insertions(+), 30 deletions(-)

diff --git a/yum/yumRepo.py b/yum/yumRepo.py
index 5a91fcd..9441cf6 100644
--- a/yum/yumRepo.py
+++ b/yum/yumRepo.py
@@ -1324,6 +1324,17 @@ Insufficient space in download directory %s
             into the delete list, this means metadata can change filename
             without us leaking it. """
 
+        downloading = self._commonRetrieveDataMD_list(mdtypes)
+        for (ndata, nmdtype) in downloading:
+            if not self._retrieveMD(nmdtype, retrieve_can_fail=True):
+                self._revertOldRepoXML()
+                return False
+        self._commonRetrieveDataMD_done(downloading)
+        return True
+
+    def _commonRetrieveDataMD_list(self, mdtypes):
+        """ Return a list of metadata to be retrieved """
+
         def _mdtype_eq(omdtype, odata, nmdtype, ndata):
             """ Check if two returns from _get_mdtype_data() are equal. """
             if ndata is None:
@@ -1355,8 +1366,7 @@ Insufficient space in download directory %s
 
         # Inited twice atm. ... sue me
         self._oldRepoMDData['new_MD_files'] = []
-        downloading_with_size = []
-        downloading_no_size   = []
+        downloading = []
         for mdtype in all_mdtypes:
             (nmdtype, ndata) = self._get_mdtype_data(mdtype)
 
@@ -1393,43 +1403,20 @@ Insufficient space in download directory %s
             # No old repomd data, but we might still have uncompressed MD
             if self._groupCheckDataMDValid(ndata, nmdtype, mdtype):
                 continue
+            downloading.append((ndata, nmdtype))
+        return downloading
 
-            if ndata.size is None:
-                downloading_no_size.append((ndata, nmdtype))
-            else:
-                downloading_with_size.append((ndata, nmdtype))
-
-        if len(downloading_with_size) == 1:
-            downloading_no_size.extend(downloading_with_size)
-            downloading_with_size = []
-
-        remote_size = 0
-        local_size  = 0
-        for (ndata, nmdtype) in downloading_with_size: # Get total size...
-            remote_size += int(ndata.size)
+    def _commonRetrieveDataMD_done(self, downloading):
+        """ Uncompress the downloaded metadata """
 
-        for (ndata, nmdtype) in downloading_with_size:
-            urlgrabber.progress.text_meter_total_size(remote_size, local_size)
-            if not self._retrieveMD(nmdtype, retrieve_can_fail=True):
-                self._revertOldRepoXML()
-                return False
-            local_size += int(ndata.size)
-        urlgrabber.progress.text_meter_total_size(0)
-        for (ndata, nmdtype) in downloading_no_size:
-            if not self._retrieveMD(nmdtype, retrieve_can_fail=True):
-                self._revertOldRepoXML()
-                return False
-
-        for (ndata, nmdtype) in downloading_with_size + downloading_no_size:
+        for (ndata, nmdtype) in downloading:
             local = self._get_mdtype_fname(ndata, False)
             if nmdtype.endswith("_db"): # Uncompress any compressed files
                 dl_local = local
                 local = misc.decompress(dl_local)
                 misc.unlink_f(dl_local)
             self._oldRepoMDData['new_MD_files'].append(local)
-
         self._doneOldRepoXML()
-        return True
 
     def _groupLoadRepoXML(self, text=None, mdtypes=None):
         """ Retrieve the new repomd.xml from the repository, then check it
-- 
1.7.4.4



More information about the Yum-devel mailing list