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.
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
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):
# 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