summaryrefslogtreecommitdiff
path: root/sbhs_server/tables/management/commands/generate_checksum.py
diff options
context:
space:
mode:
authorttt2017-05-13 00:29:47 +0530
committerttt2017-05-13 00:29:47 +0530
commit4336f5f06f61de30ae3fa54650fce63a9d5ef5be (patch)
tree23b4ee9b8e8f24bf732acf2f7ad22ed50cdd5670 /sbhs_server/tables/management/commands/generate_checksum.py
downloadSBHS-2018-Rpi-4336f5f06f61de30ae3fa54650fce63a9d5ef5be.tar.gz
SBHS-2018-Rpi-4336f5f06f61de30ae3fa54650fce63a9d5ef5be.tar.bz2
SBHS-2018-Rpi-4336f5f06f61de30ae3fa54650fce63a9d5ef5be.zip
added all server files
Diffstat (limited to 'sbhs_server/tables/management/commands/generate_checksum.py')
-rw-r--r--sbhs_server/tables/management/commands/generate_checksum.py33
1 files changed, 33 insertions, 0 deletions
diff --git a/sbhs_server/tables/management/commands/generate_checksum.py b/sbhs_server/tables/management/commands/generate_checksum.py
new file mode 100644
index 0000000..5e708f0
--- /dev/null
+++ b/sbhs_server/tables/management/commands/generate_checksum.py
@@ -0,0 +1,33 @@
+from django.core.management.base import BaseCommand
+from sbhs_server.tables.models import Experiment
+import hashlib
+
+class Command(BaseCommand):
+ args = ''
+ help = 'Calculates checksum for unchecked experiments'
+
+ def handle(self, *args, **options):
+ experiments = Experiment.objects.filter(checksum="NONE")
+
+ for e in experiments:
+ try:
+ f = open(e.log, "r")
+ # If log file doesn't exist, it means experiment is not done yet.
+ # This takes care of that.
+ except:
+ return
+
+ data = f.read()
+ f.close()
+ data = data.strip().split("\n")
+ clean_data = ""
+ for line in data:
+ columns = line.split(" ")
+ if len(columns) >= 6:
+ clean_data += (" ".join(columns[0:6]) + "\n")
+
+ checksum = hashlib.sha1(clean_data).hexdigest()
+
+ e.checksum = checksum
+ e.save()
+ print checksum