[Checkins] SVN: hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/hash.py Calculating the hash of a resource library

Jan-Jaap Driessen jdriessen at thehealthagency.com
Sun Nov 14 09:31:35 EST 2010


Log message for revision 118397:
  Calculating the hash of a resource library

Changed:
  A   hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/hash.py

-=-
Added: hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/hash.py
===================================================================
--- hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/hash.py	                        (rev 0)
+++ hurry.resource/branches/janjaapdriessen-resource-publisher/src/hurry/resource/hash.py	2010-11-14 14:31:35 UTC (rev 118397)
@@ -0,0 +1,29 @@
+import os
+import zlib
+
+def list_directory(path):
+    # ignore any VCS directories
+    ignored_dirs = ['.svn', '.git', '.bzr']
+    for root, dirs, files in os.walk(path):
+        for dir in ignored_dirs:
+            try:
+                dirs.remove(dir)
+            except ValueError:
+                pass
+        for file in files:
+            yield os.path.join(root, file)
+
+def checksum(path):
+    # ignored extensions
+    ignored_extensions = ['.swp', '.tmp', '.pyc']
+
+    data = ''
+    for path in list_directory(path):
+        for ext in ignored_extensions:
+            if path.endswith(ext):
+               continue
+        f = open(path, 'rb')
+        data += path + f.read()
+        f.close()
+    return zlib.adler32(data) & 0xffffffff
+



More information about the checkins mailing list