Skip to content

Commit

Permalink
WIP Add sync support for content types from comps.xml
Browse files Browse the repository at this point in the history
Updates model relations, adds serializers, constants, viewsets,
libcomps parsing, and sync support for comps.xml content types

closes #5423
https://pulp.plan.io/issues/5423
  • Loading branch information
CodeHeeler committed Sep 26, 2019
1 parent 44720a4 commit 3b3d5a1
Show file tree
Hide file tree
Showing 6 changed files with 631 additions and 14 deletions.
1 change: 1 addition & 0 deletions CHANGES/5423.misc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Comps.xml sync
75 changes: 75 additions & 0 deletions pulp_rpm/app/constants.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,6 +76,7 @@
PACKAGE_DB_REPODATA = ['primary_db', 'filelists_db', 'other_db']
UPDATE_REPODATA = ['updateinfo']
MODULAR_REPODATA = ['modules']
COMPS_REPODATA = ['comps']

CR_UPDATE_RECORD_ATTRS = SimpleNamespace(
ID='id',
Expand Down Expand Up @@ -167,3 +168,77 @@
)

PULP_MODULE_ATTR = MODULEMD_MODULE_ATTR

LIBCOMPS_GROUP_ATTRS = SimpleNamespace(
ID='id',
DEFAULT='default',
USER_VISIBLE='uservisible',
DISPLAY_ORDER='display_order',
NAME='name',
DESCRIPTION='desc',
PACKAGES='packages',
BIARCH_ONLY='biarchonly',
DESC_BY_LANG='desc_by_lang',
NAME_BY_LANG='name_by_lang'
)

LIBCOMPS_CATEGORY_ATTRS = SimpleNamespace(
ID='id',
NAME='name',
DESCRIPTION='desc',
DISPLAY_ORDER='display_order',
GROUP_IDS='group_ids',
DESC_BY_LANG='desc_by_lang',
NAME_BY_LANG='name_by_lang'
)

LIBCOMPS_ENVIRONMENT_ATTRS = SimpleNamespace(
ID='id',
NAME='name',
DESCRIPTION='desc',
DISPLAY_ORDER='display_order',
GROUP_IDS='group_ids',
OPTION_IDS='option_ids',
DESC_BY_LANG='desc_by_lang',
NAME_BY_LANG='name_by_lang'
)

LIBCOMPS_LANGPACKS_ATTRS = SimpleNamespace(
MATCHES='matches'
)

PULP_GROUP_ATTRS = SimpleNamespace(
ID='id',
DEFAULT='default',
USER_VISIBLE='user_visible',
DISPLAY_ORDER='display_order',
NAME='name',
DESCRIPTION='description',
PACKAGES='packages',
BIARCH_ONLY='biarch_only',
DESC_BY_LANG='desc_by_lang',
NAME_BY_LANG='name_by_lang'
)

PULP_CATEGORY_ATTRS = SimpleNamespace(
ID='id',
NAME='name',
DESCRIPTION='description',
DISPLAY_ORDER='display_order',
GROUP_IDS='group_ids',
DESC_BY_LANG='desc_by_lang',
NAME_BY_LANG='name_by_lang'
)

PULP_ENVIRONMENT_ATTRS = SimpleNamespace(
ID='id',
NAME='name',
DESCRIPTION='description',
DISPLAY_ORDER='display_order',
GROUP_IDS='group_ids',
OPTION_IDS='option_ids',
DESC_BY_LANG='desc_by_lang',
NAME_BY_LANG='name_by_lang'
)

PULP_LANGPACKS_ATTRS = LIBCOMPS_LANGPACKS_ATTRS
146 changes: 132 additions & 14 deletions pulp_rpm/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,14 @@
CR_UPDATE_RECORD_ATTRS,
CR_UPDATE_COLLECTION_ATTRS_MODULE,
CR_UPDATE_REFERENCE_ATTRS,
LIBCOMPS_CATEGORY_ATTRS,
LIBCOMPS_ENVIRONMENT_ATTRS,
LIBCOMPS_GROUP_ATTRS,
LIBCOMPS_LANGPACKS_ATTRS,
PULP_CATEGORY_ATTRS,
PULP_ENVIRONMENT_ATTRS,
PULP_GROUP_ATTRS,
PULP_LANGPACKS_ATTRS,
PULP_PACKAGE_ATTRS,
PULP_UPDATE_COLLECTION_ATTRS,
PULP_UPDATE_COLLECTION_ATTRS_MODULE,
Expand Down Expand Up @@ -723,6 +731,8 @@ class PackageGroup(Content):
A dictionary of names by language
digest (Text):
A checksum for the group
related_packages (ManyToMany):
Packages related to this PackageGroup
"""

TYPE = 'packagegroup'
Expand All @@ -736,20 +746,47 @@ class PackageGroup(Content):
display_order = models.IntegerField()
name = models.CharField(max_length=255)
description = models.TextField()
packages = models.TextField()
packages = models.TextField(default='[]')

biarch_only = models.BooleanField(default=False)

desc_by_lang = models.TextField()
name_by_lang = models.TextField()
desc_by_lang = models.TextField(default='[]')
name_by_lang = models.TextField(default='[]')

digest = models.CharField(unique=True, max_length=64)

related_packages = models.ManyToManyField(Package)

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"

@classmethod
def libcomps_to_dict(cls, group):
"""
Convert libcomps group object to dict for instantiating PackageGroup object.
Args:
group(libcomps.group): a RPM/SRPM group to convert
Returns:
dict: all data for RPM/SRPM group content creation
"""
return {
PULP_GROUP_ATTRS.ID: getattr(group, LIBCOMPS_GROUP_ATTRS.ID),
PULP_GROUP_ATTRS.DEFAULT: getattr(group, LIBCOMPS_GROUP_ATTRS.DEFAULT),
PULP_GROUP_ATTRS.USER_VISIBLE: getattr(group, LIBCOMPS_GROUP_ATTRS.USER_VISIBLE),
PULP_GROUP_ATTRS.DISPLAY_ORDER: getattr(group, LIBCOMPS_GROUP_ATTRS.DISPLAY_ORDER),
PULP_GROUP_ATTRS.NAME: getattr(group, LIBCOMPS_GROUP_ATTRS.NAME),
PULP_GROUP_ATTRS.DESCRIPTION: getattr(group, LIBCOMPS_GROUP_ATTRS.DESCRIPTION),
PULP_GROUP_ATTRS.PACKAGES: getattr(group, LIBCOMPS_GROUP_ATTRS.PACKAGES),
PULP_GROUP_ATTRS.BIARCH_ONLY: getattr(group, LIBCOMPS_GROUP_ATTRS.BIARCH_ONLY),
PULP_GROUP_ATTRS.DESC_BY_LANG: getattr(group, LIBCOMPS_GROUP_ATTRS.DESC_BY_LANG),
PULP_GROUP_ATTRS.NAME_BY_LANG: getattr(group, LIBCOMPS_GROUP_ATTRS.NAME_BY_LANG),
}


class Category(Content):
class PackageCategory(Content):
"""
The "Category" content type. Formerly "PackageCategory" in Pulp 2.
Expand All @@ -774,9 +811,11 @@ class Category(Content):
A dictionary of names by language
digest (Text):
A checksum for the category
packagegroups (ManyToMany):
PackageGroups related to this category
"""

TYPE = 'category'
TYPE = 'packagecategory'

# Required metadata
id = models.CharField(max_length=255)
Expand All @@ -787,16 +826,43 @@ class Category(Content):

group_ids = models.TextField(default='[]')

desc_by_lang = models.TextField()
name_by_lang = models.TextField()
desc_by_lang = models.TextField(default='[]')
name_by_lang = models.TextField(default='[]')

digest = models.CharField(unique=True, max_length=64)

packagegroups = models.ManyToManyField(PackageGroup)

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"

@classmethod
def libcomps_to_dict(cls, category):
"""
Convert libcomps category object to dict for instantiating PackageCategory object.
Args:
category(libcomps.category): a RPM/SRPM category to convert
Returns:
dict: all data for RPM/SRPM category content creation
"""
return {
PULP_CATEGORY_ATTRS.ID: getattr(category, LIBCOMPS_CATEGORY_ATTRS.ID),
PULP_CATEGORY_ATTRS.NAME: getattr(category, LIBCOMPS_CATEGORY_ATTRS.NAME),
PULP_CATEGORY_ATTRS.DESCRIPTION: getattr(category, LIBCOMPS_CATEGORY_ATTRS.DESCRIPTION),
PULP_CATEGORY_ATTRS.DISPLAY_ORDER: getattr(category,
LIBCOMPS_CATEGORY_ATTRS.DISPLAY_ORDER),
PULP_CATEGORY_ATTRS.GROUP_IDS: getattr(category, LIBCOMPS_CATEGORY_ATTRS.GROUP_IDS),
PULP_CATEGORY_ATTRS.DESC_BY_LANG: getattr(category,
LIBCOMPS_CATEGORY_ATTRS.DESC_BY_LANG),
PULP_CATEGORY_ATTRS.NAME_BY_LANG: getattr(category,
LIBCOMPS_CATEGORY_ATTRS.NAME_BY_LANG),
}


class Environment(Content):
class PackageEnvironment(Content):
"""
The "Environment" content type. Formerly "PackageEnvironment" in Pulp 2.
Expand All @@ -823,9 +889,13 @@ class Environment(Content):
A dictionary of names by language
digest (Text):
A checksum for the environment
packagegroups (ManyToMany):
PackageGroups related to this environment
optionalgroups (ManyToMany):
PackageGroups optionally related to this environment
"""

TYPE = 'environment'
TYPE = 'packageenvironment'

# Required metadata
id = models.CharField(max_length=255)
Expand All @@ -837,16 +907,48 @@ class Environment(Content):
group_ids = models.TextField(default='[]')
option_ids = models.TextField(default='[]')

desc_by_lang = models.TextField()
name_by_lang = models.TextField()
desc_by_lang = models.TextField(default='[]')
name_by_lang = models.TextField(default='[]')

digest = models.CharField(unique=True, max_length=64)

packagegroups = models.ManyToManyField(PackageGroup, related_name='packagegroups_to_env')
optionalgroups = models.ManyToManyField(PackageGroup, related_name='optionalgroups_to_env')

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"

@classmethod
def libcomps_to_dict(cls, environment):
"""
Convert libcomps environment object to dict for instantiating PackageEnvironment object.
Args:
environment(libcomps.environment): a RPM/SRPM environment to convert
Returns:
dict: all data for RPM/SRPM environment content creation
"""
return {
PULP_ENVIRONMENT_ATTRS.ID: getattr(environment, LIBCOMPS_ENVIRONMENT_ATTRS.ID),
PULP_ENVIRONMENT_ATTRS.NAME: getattr(environment, LIBCOMPS_ENVIRONMENT_ATTRS.NAME),
PULP_ENVIRONMENT_ATTRS.DESCRIPTION: getattr(environment,
LIBCOMPS_ENVIRONMENT_ATTRS.DESCRIPTION),
PULP_ENVIRONMENT_ATTRS.DISPLAY_ORDER: getattr(environment,
LIBCOMPS_ENVIRONMENT_ATTRS.DISPLAY_ORDER),
PULP_ENVIRONMENT_ATTRS.GROUP_IDS: getattr(environment,
LIBCOMPS_ENVIRONMENT_ATTRS.GROUP_IDS),
PULP_ENVIRONMENT_ATTRS.OPTION_IDS: getattr(environment,
LIBCOMPS_ENVIRONMENT_ATTRS.OPTION_IDS),
PULP_ENVIRONMENT_ATTRS.DESC_BY_LANG: getattr(environment,
LIBCOMPS_ENVIRONMENT_ATTRS.DESC_BY_LANG),
PULP_ENVIRONMENT_ATTRS.NAME_BY_LANG: getattr(environment,
LIBCOMPS_ENVIRONMENT_ATTRS.NAME_BY_LANG),
}


class Langpacks(Content):
class PackageLangpacks(Content):
"""
The "Langpacks" content type. Formerly "PackageLangpacks" in Pulp 2.
Expand All @@ -859,15 +961,31 @@ class Langpacks(Content):
The langpacks dictionary
"""

TYPE = 'langpacks'
TYPE = 'packagelangpacks'

matches = models.TextField()
matches = models.TextField(default='[]')

digest = models.CharField(unique=True, max_length=64)

class Meta:
default_related_name = "%(app_label)s_%(model_name)s"

@classmethod
def libcomps_to_dict(cls, langpacks):
"""
Convert libcomps langpacks object to dict for instantiating PackageLangpacks object.
Args:
langpacks(libcomps.langpacks): a RPM/SRPM langpacks to convert
Returns:
dict: all data for RPM/SRPM langpacks content creation
"""
return {
PULP_LANGPACKS_ATTRS.MATCHES: getattr(langpacks, LIBCOMPS_LANGPACKS_ATTRS.MATCHES)
}


class RpmRemote(Remote):
"""
Expand Down
Loading

0 comments on commit 3b3d5a1

Please sign in to comment.