summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--devel/management/commands/reporead.py7
-rw-r--r--packages/models.py36
2 files changed, 42 insertions, 1 deletions
diff --git a/devel/management/commands/reporead.py b/devel/management/commands/reporead.py
index 2e8c4625..4e242af1 100644
--- a/devel/management/commands/reporead.py
+++ b/devel/management/commands/reporead.py
@@ -14,6 +14,7 @@ Example:
"""
from collections import defaultdict
+from copy import copy
import io
import os
import re
@@ -31,7 +32,7 @@ from django.db.utils import IntegrityError
from devel.utils import UserFinder
from main.models import Arch, Package, PackageFile, Repo
from main.utils import utc_now
-from packages.models import Depend, Conflict, Provision, Replacement
+from packages.models import Depend, Conflict, Provision, Replacement, Update
logging.basicConfig(
@@ -362,6 +363,7 @@ def db_update(archname, reponame, pkgs, force=False):
try:
with transaction.commit_on_success():
populate_pkg(dbpkg, pkg, timestamp=utc_now())
+ Update.objects.log_update(None, dbpkg)
except IntegrityError:
logger.warning("Could not add package %s; "
"not fatal if another thread beat us to it.",
@@ -372,6 +374,7 @@ def db_update(archname, reponame, pkgs, force=False):
logger.info("Removing package %s", pkgname)
dbpkg = dbdict[pkgname]
with transaction.commit_on_success():
+ Update.objects.log_update(dbpkg, None)
# no race condition here as long as simultaneous threads both
# issue deletes; second delete will be a no-op
delete_pkg_files(dbpkg)
@@ -399,7 +402,9 @@ def db_update(archname, reponame, pkgs, force=False):
logger.debug("Package %s was already updated", pkg.name)
continue
logger.info("Updating package %s", pkg.name)
+ prevpkg = copy(dbpkg)
populate_pkg(dbpkg, pkg, force=force, timestamp=timestamp)
+ Update.objects.log_update(prevpkg, dbpkg)
logger.info('Finished updating arch: %s', archname)
diff --git a/packages/models.py b/packages/models.py
index 5ee06575..04f35f9d 100644
--- a/packages/models.py
+++ b/packages/models.py
@@ -203,6 +203,40 @@ UPDATE_ACTION_CHOICES = (
)
+class UpdateManager(models.Manager):
+ def log_update(self, old_pkg, new_pkg):
+ '''Utility method to help log an update. This will determine the type
+ based on how many packages are passed in, and will pull the relevant
+ necesary fields off the given packages.'''
+ update = Update()
+ if new_pkg:
+ update.action_flag = ADDITION
+ update.package = new_pkg
+ update.arch = new_pkg.arch
+ update.repo = new_pkg.repo
+ update.pkgname = new_pkg.pkgname
+ update.pkgbase = new_pkg.pkgbase
+ update.new_pkgver = new_pkg.pkgver
+ update.new_pkgrel = new_pkg.pkgrel
+ update.new_epoch = new_pkg.epoch
+ if old_pkg:
+ if new_pkg:
+ update.action_flag = CHANGE
+ else:
+ update.action_flag = DELETION
+ update.arch = old_pkg.arch
+ update.repo = old_pkg.repo
+ update.pkgname = old_pkg.pkgname
+ update.pkgbase = old_pkg.pkgbase
+
+ update.old_pkgver = old_pkg.pkgver
+ update.old_pkgrel = old_pkg.pkgrel
+ update.old_epoch = old_pkg.epoch
+
+ update.save(force_insert=True)
+ return update
+
+
class Update(models.Model):
package = models.ForeignKey(Package, related_name="updates",
null=True, on_delete=models.SET_NULL)
@@ -222,6 +256,8 @@ class Update(models.Model):
new_pkgrel = models.CharField(max_length=255, null=True)
new_epoch = models.PositiveIntegerField(null=True)
+ objects = UpdateManager()
+
class Meta:
get_latest_by = 'created'