diff options
author | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2011-08-22 17:23:53 -0300 |
---|---|---|
committer | Adolfo Fitoria <adolfo.fitoria@gmail.com> | 2011-08-22 17:23:53 -0300 |
commit | 53af845f1ae4d77c817c5179c600c2a656754996 (patch) | |
tree | 4b7b8a1192056996c878c4bd4ee905f8b9587127 | |
parent | 972394faf7422db35b30b09a73fcd41a1af080e9 (diff) | |
download | askbot-53af845f1ae4d77c817c5179c600c2a656754996.tar.gz askbot-53af845f1ae4d77c817c5179c600c2a656754996.tar.bz2 askbot-53af845f1ae4d77c817c5179c600c2a656754996.zip |
adding the hasher function
-rw-r--r-- | askbot/utils/hasher.py | 40 |
1 files changed, 40 insertions, 0 deletions
diff --git a/askbot/utils/hasher.py b/askbot/utils/hasher.py new file mode 100644 index 00000000..4c68ed79 --- /dev/null +++ b/askbot/utils/hasher.py @@ -0,0 +1,40 @@ +import hashlib, os +from askbot.conf import settings as askbot_settings +use_skin = askbot_settings.ASKBOT_DEFAULT_SKIN +resource_revision = askbot_settings.MEDIA_RESOURCE_REVISION + +def GetHashofDirs(directory, verbose=0): + SHAhash = hashlib.sha1() + if not os.path.exists (directory): + return -1 + + try: + for root, dirs, files in os.walk(directory): + for names in files: + filepath = os.path.join(root,names) + try: + f1 = open(filepath, 'rb') + except: + # You can't open the file for some reason + f1.close() + continue + + while 1: + # Read file in as little chunks + buf = f1.read(4096) + if not buf : break + SHAhash.update(hashlib.sha1(buf).hexdigest()) + f1.close() + + except: + import traceback + # Print the stack traceback + traceback.print_exc() + return -2 + + return SHAhash.hexdigest() + +if __name__ == '__main__': + #directory = raw_input('directory:') + #print GetHashofDirs(directory, 0) + print GetHashofDirs('skins/default/media', 0) |