Skip to content

Commit

Permalink
Remove plugin managed repos
Browse files Browse the repository at this point in the history
  • Loading branch information
fao89 committed Nov 12, 2019
1 parent 1387d0b commit 80cf977
Show file tree
Hide file tree
Showing 6 changed files with 69 additions and 4 deletions.
1 change: 1 addition & 0 deletions CHANGES/5627.feature
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Adding `sub_repo` field to `RpmRepository`
1 change: 1 addition & 0 deletions CHANGES/5627.removal
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Remove plugin managed repos
18 changes: 18 additions & 0 deletions pulp_rpm/app/migrations/0010_rpmrepository_sub_repo.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 2.2.7 on 2019-11-12 15:26

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
('rpm', '0009_auto_20191111_2001'),
]

operations = [
migrations.AddField(
model_name='rpmrepository',
name='sub_repo',
field=models.BooleanField(default=False),
),
]
49 changes: 47 additions & 2 deletions pulp_rpm/app/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,15 +4,18 @@
import createrepo_c as cr

from django.contrib.postgres.fields import JSONField
from django.db import models
from django.db import models, transaction
from pulpcore.plugin.models import (
Content,
ContentArtifact,
CreatedResource,
Model,
Remote,
Repository,
RepositoryVersion,
Publication,
PublicationDistribution
PublicationDistribution,
Task,
)

from pulp_rpm.app.constants import (CHECKSUM_CHOICES, CR_PACKAGE_ATTRS,
Expand Down Expand Up @@ -1082,10 +1085,52 @@ def libcomps_to_dict(cls, langpacks):
class RpmRepository(Repository):
"""
Repository for "rpm" content.
Fields:
sub_repo (Boolean):
Whether is sub_repo or not
"""

TYPE = "rpm"

sub_repo = models.BooleanField(default=False)

def new_version(self, base_version=None):
"""
Create a new RepositoryVersion for this Repository.
Creation of a RepositoryVersion should be done in a RQ Job.
Args:
repository (pulpcore.app.models.Repository): to create a new version of
base_version (pulpcore.app.models.RepositoryVersion): an optional repository version
whose content will be used as the set of content for the new version
Returns:
pulpcore.app.models.RepositoryVersion: The Created RepositoryVersion
"""
with transaction.atomic():
version = RepositoryVersion(
repository=self,
number=int(self.last_version) + 1,
base_version=base_version)
self.last_version = version.number
self.save()
version.save()

if base_version:
# first remove the content that isn't in the base version
version.remove_content(version.content.exclude(pk__in=base_version.content))
# now add any content that's in the base_version but not in version
version.add_content(base_version.content.exclude(pk__in=version.content))

if Task.current and not self.sub_repo:
resource = CreatedResource(content_object=version)
resource.save()
return version

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

Expand Down
2 changes: 1 addition & 1 deletion pulp_rpm/app/tasks/synchronizing.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def synchronize(remote_pk, repository_pk):
continue
name = f"{repodata}-{kickstart['hash']}"
new_repository, created = RpmRepository.objects.get_or_create(
name=name, plugin_managed=True
name=name, sub_repo=True
)
if created:
new_repository.save()
Expand Down
2 changes: 1 addition & 1 deletion pulp_rpm/app/viewsets.py
Original file line number Diff line number Diff line change
Expand Up @@ -100,7 +100,7 @@ class RpmRepositoryViewSet(RepositoryViewSet):
"""

endpoint_name = 'rpm'
queryset = RpmRepository.objects.all()
queryset = RpmRepository.objects.exclude(sub_repo=True)
serializer_class = RpmRepositorySerializer

@swagger_auto_schema(
Expand Down

0 comments on commit 80cf977

Please sign in to comment.