summaryrefslogtreecommitdiffstats
path: root/packages
diff options
context:
space:
mode:
authorDan McGee <dan@archlinux.org>2012-07-01 20:21:34 -0500
committerDan McGee <dan@archlinux.org>2012-07-01 20:21:34 -0500
commita87fe016d1a1bf7fdcd2b19f515aa72a5b93db2b (patch)
treec2dd261f4f0ea8c6610b3f0ce5e165a5e542dbfb /packages
parent43b5c29b3d89cc2e7e7109bb3c7717a87cfc67b5 (diff)
downloadarchweb-a87fe016d1a1bf7fdcd2b19f515aa72a5b93db2b.tar.gz
archweb-a87fe016d1a1bf7fdcd2b19f515aa72a5b93db2b.zip
Log package updates during reporead invocation
This adds a Manager and log_update method to help log all updates made to the packages table during reporead runs. Signed-off-by: Dan McGee <dan@archlinux.org>
Diffstat (limited to 'packages')
-rw-r--r--packages/models.py36
1 files changed, 36 insertions, 0 deletions
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'