Commits

Lars Yencken  committed fe449bb

Allows more flexible needs_update() dependencies, including module instances.

- Allows module instances, converting them to their source filename.
- Converts compiled python source files to the original source when available.

  • Participants
  • Parent commits 5ed9350

Comments (0)

Files changed (1)

File src/models.py

 Models for the checksum app.
 """
 
+from os import path
+import types
 from zlib import crc32
 
 from django.db import models
     @staticmethod
     def checksum(files):
         result = 0
-        for filename in files:
+        for module_or_filename in files:
+            # Replace module references with the file which defines them.
+            if type(module_or_filename) == types.ModuleType:
+                filename = module_or_filename.__file__
+            else:
+                filename = module_or_filename
+
+            # Replace compiled python files with their source code.
+            if (filename.endswith('.pyc') or filename.endswith('.pyo')) \
+                        and path.exists(filename[:-1]):
+                filename = filename[:-1]
+
             i_stream = open(filename, 'r')
             result = crc32(i_stream.read(), result)
             i_stream.close()