Skip to content

Commit

Permalink
- repodata custom checksumtype in yum association process and in yum/…
Browse files Browse the repository at this point in the history
…publish
  • Loading branch information
midnightercz committed May 18, 2015
1 parent af19206 commit 5ded67b
Show file tree
Hide file tree
Showing 3 changed files with 51 additions and 2 deletions.
16 changes: 15 additions & 1 deletion plugins/pulp_rpm/plugins/distributors/yum/metadata/other.py
Expand Up @@ -39,7 +39,21 @@ def add_unit_metadata(self, unit):
:param unit: unit whose metadata is to be written
:type unit: pulp.plugins.model.Unit
"""
metadata = unit.metadata['repodata']['other']

if self.checksum_type == "sha256":
label = "repodata"
else:
label = "repodata-%s" % self.checksum_type

if label not in unit.metadata and "repodata" in unit.metadata:
unit.metadata[label] = rpm_parse.get_package_xml(unit.storage_path,
sumtype=self.checksum_type,
changelog_limit=unit.metadata.get("changelog_limit", 10))
metadata = {'label': unit.metadata[label]}
content_manager = manager_factory.content_manager()
content_manager.update_content_unit(unit_type_id, unit_id, metadata)

metadata = unit.metadata[label]['other']
if isinstance(metadata, unicode):
metadata = metadata.encode('utf-8')
self.metadata_file_handle.write(metadata)
16 changes: 15 additions & 1 deletion plugins/pulp_rpm/plugins/distributors/yum/metadata/primary.py
@@ -1,6 +1,7 @@
import os

from pulp.plugins.util.metadata_writer import FastForwardXmlFileContext
from pulp_rpm.plugins.importers.yum.parse import rpm as rpm_parse

from pulp_rpm.plugins.distributors.yum.metadata.metadata import REPO_DATA_DIR_NAME
from pulp_rpm.yum_plugin import util
Expand Down Expand Up @@ -51,7 +52,20 @@ def add_unit_metadata(self, unit):
:param unit: unit whose metadata is to be written
:type unit: pulp.plugins.model.Unit
"""
metadata = unit.metadata['repodata']['primary']

if self.checksum_type == "sha256":
label = "repodata"
else:
label = "repodata-%s" % self.checksum_type
if label not in unit.metadata and "repodata" in unit.metadata:
unit.metadata[label] = rpm_parse.get_package_xml(unit.storage_path,
sumtype=self.checksum_type,
changelog_limit=unit.metadata.get("changelog_limit", 10))
metadata = {'label': unit.metadata[label]}
content_manager = manager_factory.content_manager()
content_manager.update_content_unit(unit_type_id, unit_id, metadata)

metadata = unit.metadata[label]['primary']
if isinstance(metadata, unicode):
metadata = metadata.encode('utf-8')
self.metadata_file_handle.write(metadata)
21 changes: 21 additions & 0 deletions plugins/pulp_rpm/plugins/importers/yum/associate.py
Expand Up @@ -10,6 +10,8 @@
from pulp_rpm.plugins.importers.yum import depsolve
from pulp_rpm.plugins.importers.yum import existing

from pulp_rpm.plugins.importers.yum.parse import rpm as rpm_parse


_LOGGER = logging.getLogger(__name__)

Expand Down Expand Up @@ -44,6 +46,9 @@ def associate(source_repo, dest_repo, import_conduit, config, units=None):
if recursive is None:
recursive = False

for unit in units:
custom_checksum_type_check(dest_repo, unit, config, import_conduit)

associated_units = set([_associate_unit(dest_repo, import_conduit, unit) for unit in units])
# allow garbage collection
units = None
Expand Down Expand Up @@ -358,3 +363,19 @@ def _safe_copy_unit_without_file(unit):
if key.startswith('_'):
del new_unit.metadata[key]
return new_unit

def custom_checksum_type_check(repo, unit, config, import_conduit):
_LOGGER.error("repo metadata %s" % repo.notes)

if "checksum_type" in repo.notes:
label = "repodata-%s" % repo.notes.get("checksum_type")
if not label in unit.metadata:
_LOGGER.error("Adding repodata\n")
new_metadata = {}
new_metadata[label] = rpm_parse.get_package_xml(str(unit.storage_path),
sumtype=str(repo.notes["checksum_type"]),
changelog_limit=config.get('changelog_limit', 10))
content_manager = manager_factory.content_manager()
content_manager.update_content_unit(unit.metadata["_content_type_id"],
unit.metadata["_id"],
new_metadata)

0 comments on commit 5ded67b

Please sign in to comment.