Skip to content

Commit

Permalink
Add publish for content types from comps.xml
Browse files Browse the repository at this point in the history
Add publish for comps

closes #5495
https://pulp.plan.io/issues/5495
  • Loading branch information
CodeHeeler committed Nov 18, 2019
1 parent c10bea2 commit d658355
Show file tree
Hide file tree
Showing 5 changed files with 147 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES/5495.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Added sync and publish support for comps.xml types.
1 change: 1 addition & 0 deletions CHANGES/5495.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Add publish support for comps.xml
22 changes: 22 additions & 0 deletions pulp_rpm/app/comps.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,26 @@
import hashlib
import libcomps


def list_to_idlist(lst):
"""
Convert list to libcomps IdList object.
Args:
list: a list
Returns:
idlist: a libcomps IdList
"""
idlist = libcomps.IdList()

for i in lst:
group_id = libcomps.GroupId(i['name'], i['default'])
if group_id not in idlist:
idlist.append(group_id)

return idlist


def strdict_to_dict(value):
Expand Down
90 changes: 89 additions & 1 deletion pulp_rpm/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
from logging import getLogger

import createrepo_c as cr
import libcomps

from django.contrib.postgres.fields import JSONField
from django.db import (
Expand Down Expand Up @@ -47,7 +48,7 @@
PULP_UPDATE_REFERENCE_ATTRS,
)

from pulp_rpm.app.comps import strdict_to_dict
from pulp_rpm.app.comps import strdict_to_dict, list_to_idlist

log = getLogger(__name__)

Expand Down Expand Up @@ -899,6 +900,29 @@ def pkglist_to_lst(cls, value):
'requires': i.requires})
return package_list

@classmethod
def list_to_pkglist(cls, lst):
"""
Convert list of Packages to libcomps PackageList object.
Args:
list: a list of Packages
Returns:
pkglist: a libcomps PackageList
"""
pkglist = libcomps.PackageList()
for pkg in lst:
lib_pkg = libcomps.Package()
lib_pkg.name = pkg['name']
lib_pkg.type = pkg['type']
lib_pkg.basearchonly = bool(pkg['basearchonly'])
lib_pkg.requires = pkg['requires']
pkglist.append(lib_pkg)

return pkglist

@classmethod
def libcomps_to_dict(cls, group):
"""
Expand Down Expand Up @@ -929,6 +953,29 @@ def libcomps_to_dict(cls, group):
),
}

def pkg_grp_to_libcomps(self):
"""
Convert PackageGroup object to libcomps Group object.
Returns:
group: libcomps.Group object
"""
group = libcomps.Group()

group.id = getattr(self, PULP_GROUP_ATTRS.ID)
group.default = getattr(self, PULP_GROUP_ATTRS.DEFAULT)
group.uservisible = getattr(self, PULP_GROUP_ATTRS.USER_VISIBLE)
group.display_order = getattr(self, PULP_GROUP_ATTRS.DISPLAY_ORDER)
group.name = getattr(self, PULP_GROUP_ATTRS.NAME)
group.desc = getattr(self, PULP_GROUP_ATTRS.DESCRIPTION)
group.packages = self.list_to_pkglist(getattr(self, PULP_GROUP_ATTRS.PACKAGES))
group.biarchonly = getattr(self, PULP_GROUP_ATTRS.BIARCH_ONLY)
group.desc_by_lang = libcomps.StrDict(**getattr(self, PULP_GROUP_ATTRS.DESC_BY_LANG))
group.name_by_lang = libcomps.StrDict(**getattr(self, PULP_GROUP_ATTRS.NAME_BY_LANG))

return group


class PackageCategory(Content):
"""
Expand Down Expand Up @@ -1037,6 +1084,26 @@ def libcomps_to_dict(cls, category):
),
}

def pkg_cat_to_libcomps(self):
"""
Convert PackageCategory object to libcomps Category object.
Returns:
group: libcomps.Category object
"""
cat = libcomps.Category()

cat.id = getattr(self, PULP_CATEGORY_ATTRS.ID)
cat.name = getattr(self, PULP_CATEGORY_ATTRS.NAME)
cat.desc = getattr(self, PULP_CATEGORY_ATTRS.DESCRIPTION)
cat.display_order = getattr(self, PULP_CATEGORY_ATTRS.DISPLAY_ORDER)
cat.group_ids = list_to_idlist(getattr(self, PULP_CATEGORY_ATTRS.GROUP_IDS))
cat.desc_by_lang = libcomps.StrDict(**getattr(self, PULP_CATEGORY_ATTRS.DESC_BY_LANG))
cat.name_by_lang = libcomps.StrDict(**getattr(self, PULP_CATEGORY_ATTRS.NAME_BY_LANG))

return cat


class PackageEnvironment(Content):
"""
Expand Down Expand Up @@ -1155,6 +1222,27 @@ def libcomps_to_dict(cls, environment):
),
}

def pkg_env_to_libcomps(self):
"""
Convert PackageEnvironment object to libcomps Environment object.
Returns:
group: libcomps.Environment object
"""
env = libcomps.Environment()

env.id = getattr(self, PULP_ENVIRONMENT_ATTRS.ID)
env.name = getattr(self, PULP_ENVIRONMENT_ATTRS.NAME)
env.desc = getattr(self, PULP_ENVIRONMENT_ATTRS.DESCRIPTION)
env.display_order = getattr(self, PULP_ENVIRONMENT_ATTRS.DISPLAY_ORDER)
env.group_ids = list_to_idlist(getattr(self, PULP_ENVIRONMENT_ATTRS.GROUP_IDS))
env.option_ids = list_to_idlist(getattr(self, PULP_ENVIRONMENT_ATTRS.OPTION_IDS))
env.desc_by_lang = libcomps.StrDict(**getattr(self, PULP_ENVIRONMENT_ATTRS.DESC_BY_LANG))
env.name_by_lang = libcomps.StrDict(**getattr(self, PULP_ENVIRONMENT_ATTRS.NAME_BY_LANG))

return env


class PackageLangpacks(Content):
"""
Expand Down
34 changes: 34 additions & 0 deletions pulp_rpm/app/tasks/publishing.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
import shutil

import createrepo_c as cr
import libcomps

from django.core.files import File

Expand All @@ -20,6 +21,10 @@
Modulemd,
ModulemdDefaults,
Package,
PackageCategory,
PackageEnvironment,
PackageGroup,
PackageLangpacks,
RepoMetadataFile,
RpmPublication,
UpdateRecord,
Expand Down Expand Up @@ -215,6 +220,7 @@ def create_repomd_xml(packages, publication, extra_repomdrecords, sub_folder=Non
cwd = os.getcwd()
repodata_path = REPODATA_PATH
has_modules = False
has_comps = False

if sub_folder:
cwd = os.path.join(cwd, sub_folder)
Expand All @@ -230,6 +236,7 @@ def create_repomd_xml(packages, publication, extra_repomdrecords, sub_folder=Non
oth_db_path = os.path.join(cwd, "other.sqlite")
upd_xml_path = os.path.join(cwd, "updateinfo.xml.gz")
mod_yml_path = os.path.join(cwd, "modules.yaml")
comps_xml_path = os.path.join(cwd, "comps.xml")

pri_xml = cr.PrimaryXmlFile(pri_xml_path)
fil_xml = cr.FilelistsXmlFile(fil_xml_path)
Expand Down Expand Up @@ -270,6 +277,30 @@ def create_repomd_xml(packages, publication, extra_repomdrecords, sub_folder=Non
mod_yml.write(default._artifacts.get().file.read())
has_modules = True

# Process comps
comps = libcomps.Comps()
for pkg_grp in PackageGroup.objects.filter(
pk__in=publication.repository_version.content):
group = pkg_grp.pkg_grp_to_libcomps()
comps.groups.append(group)
has_comps = True
for pkg_cat in PackageCategory.objects.filter(
pk__in=publication.repository_version.content):
cat = pkg_cat.pkg_cat_to_libcomps()
comps.categories.append(cat)
has_comps = True
for pkg_env in PackageEnvironment.objects.filter(
pk__in=publication.repository_version.content):
env = pkg_env.pkg_env_to_libcomps()
comps.environments.append(env)
has_comps = True
for pkg_lng in PackageLangpacks.objects.filter(
pk__in=publication.repository_version.content):
comps.langpacks = libcomps.StrDict(**pkg_lng.matches)
has_comps = True

comps.toxml_f(comps_xml_path)

pri_xml.close()
fil_xml.close()
oth_xml.close()
Expand All @@ -288,6 +319,9 @@ def create_repomd_xml(packages, publication, extra_repomdrecords, sub_folder=Non
if has_modules:
repomdrecords.append(("modules", mod_yml_path, None))

if has_comps:
repomdrecords.append(("comps", comps_xml_path, None))

repomdrecords.extend(extra_repomdrecords)

sqlite_files = ("primary_db", "filelists_db", "other_db")
Expand Down

0 comments on commit d658355

Please sign in to comment.