From 300aa93b97551e01b4737fdbe0bac525c951bb5f Mon Sep 17 00:00:00 2001 From: Kevin Midboe Date: Wed, 5 Apr 2017 18:53:36 +0200 Subject: [PATCH] A script showing how to create a hash of a directory (or other byte object) --- modules/dirHash.py | 23 +++++++++++++++++++++++ 1 file changed, 23 insertions(+) create mode 100755 modules/dirHash.py diff --git a/modules/dirHash.py b/modules/dirHash.py new file mode 100755 index 0000000..98a69c9 --- /dev/null +++ b/modules/dirHash.py @@ -0,0 +1,23 @@ +#!/usr/bin/env python3 +# -*- coding: utf-8 -*- +# @Author: KevinMidboe +# @Date: 2017-04-05 15:24:17 +# @Last Modified by: KevinMidboe +# @Last Modified time: 2017-04-05 18:22:13 +import os, hashlib +from functools import reduce + +hashDir = '/Volumes/media/tv' + +def main(): + dirList = os.listdir(hashDir) + concat = reduce(lambda x, y: x + y, dirList, "") + + m = hashlib.md5() + m.update(bytes(concat, 'utf-16be')) + return m.digest() + +if __name__ == '__main__': + print(main()) + +# TODO The hash value should be saved in a global manner \ No newline at end of file