Lars Yencken committed cf48ce5

Adds support for dependent tags on needs_update().

- Adds a timestamp field to each checksum.
- In order to be clean, the desired tag must have a more recent timestamp than
its dependencies.

  • Participants
  • Parent commits fe449bb

Comments (0)

Files changed (1)

File src/

 from os import path
 import types
 from zlib import crc32
+import datetime
 from django.db import models
 from django.core.exceptions import ObjectDoesNotExist
     tag = models.CharField(max_length=50)
     value = models.CharField(max_length=15)
+    timestamp = models.DateTimeField(auto_add_now=True)
     def __unicode__(self):
         return u'%s' % self.tag
         return str(result)
-    def needs_update(tag, files, delete_if_old=True):
+    def needs_update(tag, files, dep_tags=None, delete_if_old=True):
         Returns True if the database stored checksum doesn't exist or is
         different to that calculated by storing the files.
+        @param tag      The tag for the stored checksum.
+        @param files    Files or modules used to generate the checksum.
+        @param dep_tags Tags for other objects this object depends on.
+        @param delete_if_old
+                        Delete any existing tag when the current tag is dirty.
         if not files:
             raise ValueError, "Need at least one file to checksum"
+        if dep_tags:
+            latest_dep = max(Checksum.get_timestamp(t) for t in dep_tags)
+        else:
+            # Default to some time long in the past (1 year ago).
+            latest_dep = - datetime.timedelta(365)
         result = Checksum.checksum(files)
             existing = Checksum.objects.get(tag=tag)
-            if existing.value == result:
+            if existing.value == result and existing.timestamp > latest_dep:
                 return False
                 if delete_if_old:
         return True
+    def get_timestamp(tag):
+        try:
+            return Checksum.objects.get(tag=tag).timestamp
+        except ObjectDoesNotExist:
+            return
+    @staticmethod
     def store(tag, files):
         "Store the given checksum."