deltarepo: use real cost during solving
authorTomas Mlcoch <xtojaj@gmail.com>
Mon, 24 Feb 2014 18:20:47 +0000 (19:20 +0100)
committerTomas Mlcoch <xtojaj@gmail.com>
Mon, 24 Feb 2014 18:20:47 +0000 (19:20 +0100)
deltarepo/deltarepo/deltarepos.py
deltarepo/deltarepo/updater_common.py
deltarepo/example/test.sh
deltarepo/repoupdater.py

index b619800..2dcc4dd 100644 (file)
@@ -12,6 +12,8 @@ from .xmlcommon import getNode, getRequiredNode
 from .xmlcommon import getAttribute, getRequiredAttribute, getNumAttribute
 from .xmlcommon import getValue
 
+# TODO: Remove total_size (it is redundant)
+
 class DeltaReposRecord(object):
     def __init__(self):
         self.location_base = None
index 9c712b6..96b38d7 100644 (file)
@@ -22,19 +22,20 @@ class _Repo(object):
         self.contenthash_type = None        # Type of calculated content hash
         self.repomd_contenthash = None      # Content hash from repomd
         self.repomd_contenthash_type = None # Content hash from repomd
-        self.present_metadata = []  # ["primary", "filelists", ...]
+        self.listed_metadata = []  # ["primary", "filelists", ...]
+        self.present_metadata = [] # Metadata files which really exist in repo
 
-    def _fill_from_repomd_object(self, repomd):
+    def _fill_from_repomd_object(self, repomd, check_metadata_presence=False):
         timestamp = -1
-        present_metadata = []
+        listed_metadata = []
         for rec in repomd.records:
-            present_metadata.append(rec.type)
             if rec.timestamp:
                 timestamp = max(timestamp, rec.timestamp)
+            listed_metadata.append(rec.type)
 
         self.revision = repomd.revision
         self.timestamp = timestamp
-        self.present_metadata = present_metadata
+        self.listed_metadata = listed_metadata
 
     def _fill_from_path(self, path, contenthash=True, contenthash_type="sha256"):
         """Fill the repo attributes from a repository specified by path.
@@ -58,16 +59,18 @@ class _Repo(object):
 
         self._fill_from_repomd_object(repomd)
 
+        primary_path = None
+        for rec in repomd.records:
+            md_path = os.path.join(path, rec.location_href)
+            if os.path.isfile(md_path):
+                self.present_metadata.append(rec.type)
+            if rec.type == "primary":
+                primary_path = md_path
+
         if contenthash:
-            primary_path = None
-            for rec in repomd.records:
-                if rec.type == "primary":
-                    primary_path = rec.location_href
-                    break
             if not primary_path:
                 raise DeltaRepoError("{0} - primary metadata are missing"
                                      "".format(primary_path))
-            primary_path = os.path.join(path, primary_path)
             self.contenthash = calculate_contenthash(primary_path, contenthash_type)
             self.contenthash_type = contenthash_type
 
@@ -259,7 +262,15 @@ class Link(object):
     def cost(self, whitelisted_metadata=None):
         """Cost (currently just a total size).
         In future maybe just sizes of needed delta metadata."""
-        return self._deltareposrecord.size_total
+        if whitelisted_metadata is None:
+            return self._deltareposrecord.size_total
+
+        cost = self._deltareposrecord.repomd_size
+        for md_type in whitelisted_metadata:
+            md = self._deltareposrecord.get_data(md_type)
+            if md:
+                cost += md.get("size", 0)
+        return cost
 
     @classmethod
     def links_from_drmirror(cls, drmirror):
index 12239f0..6d9ab01 100755 (executable)
@@ -6,3 +6,13 @@ cp -r repos/repo1 test/
 cp -r repos/repo3 test/
 
 ../repoupdater.py test/repo1/ $@ --repo file://`pwd`/test/repo3/ --drmirror file://`pwd`/deltarepos/
+
+rm -rf test2/
+mkdir test2/
+cp -r repos/repo1 test2/
+cp -r repos/repo3 test2/
+rm -f test2/repo1/repodata/*sqlite*
+rm -f test2/repo1/repodata/*other*
+rm -f test2/repo1/repodata/*foobar*
+
+../repoupdater.py test2/repo1/ $@ --repo file://`pwd`/test/repo3/ --drmirror file://`pwd`/deltarepos/
index 823ff9c..44c42e1 100755 (executable)
@@ -137,6 +137,15 @@ def update_with_deltas(args, drmirros, localrepo, originrepo, logger):
     # Resolve path
     resolved_path = updatesolver.resolve_path(source_contenthash, target_contenthash)
 
+    logger.debug("Resolved path:")
+    x = 0
+    for link in resolved_path:
+        x += 1
+        logger.debug("{0:2}) {1} -> {2}".format(x, link.src, link.dst))
+    logger.debug("--------------------------")
+    logger.debug("Total cost: {0}".format(resolved_path.cost()))
+    logger.debug("Real: {0}".format(resolved_path.cost(whitelisted_metadata)))
+
     # TODO check cost, if bigger then cost of downloading
     #      origin repo then download origin repo