Skip to content
This repository has been archived by the owner on Dec 7, 2022. It is now read-only.

Commit

Permalink
Better support for auto-distribution.
Browse files Browse the repository at this point in the history
closes #4045
  • Loading branch information
jortel committed Nov 2, 2018
1 parent e5c69bf commit 6cbfec5
Showing 1 changed file with 41 additions and 8 deletions.
49 changes: 41 additions & 8 deletions pulpcore/pulpcore/app/models/publication.py
Expand Up @@ -107,21 +107,54 @@ def delete(self, **kwargs):
CreatedResource.objects.filter(object_id=self.pk).delete()
super().delete(**kwargs)

def update_distributions(self, model=None):
"""
Update distributions with this publication.
This supports the auto-distribution feature by updating the publication on
distributions with matching repository and publisher. By doing this, this
publication will be distributed. This method may only be called after
setting complete=True and saved.
Args:
model (pulpcore.app.models.BaseDistribution): A distribution model used.
The Distribution model is used when not specified.
"""
model = model or Distribution
distributions = model.objects.filter(
publisher=self.publisher,
repository=self.repository)
for distribution in distributions:
distribution.publication = self
distribution.save()

def __enter__(self):
"""
Enter context.
Returns:
Publication: self
"""
return self

def __exit__(self, exc_type, exc_val, exc_tb):
"""
Exit the context.
Set the complete=True, create the publication, and update distributions
configured for auto-distribution (as needed).
Args:
exc_type (Type): (optional) Type of exception raised.
exc_val (Exception): (optional) Instance of exception raised.
exc_tb (types.TracebackType): (optional) stack trace.
"""
if not exc_val:
self.complete = True
with transaction.atomic():
self.complete = True
self.save()

# Auto-Distribution
distributions = Distribution.objects.filter(publisher=self.publisher,
repository=self.repository)
for distribution in distributions:
distribution.publication = self
distribution.save()
self.update_distributions()
else:
self.delete()

Expand Down

0 comments on commit 6cbfec5

Please sign in to comment.