From 4336f5f06f61de30ae3fa54650fce63a9d5ef5be Mon Sep 17 00:00:00 2001 From: ttt Date: Sat, 13 May 2017 00:29:47 +0530 Subject: added all server files --- .../management/commands/generate_checksum.py | 33 ++++++++++++++++++++++ 1 file changed, 33 insertions(+) create mode 100644 sbhs_server/tables/management/commands/generate_checksum.py (limited to 'sbhs_server/tables/management/commands/generate_checksum.py') 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 -- cgit