diff options
Diffstat (limited to 'sbhs_server/tables/management/commands')
-rw-r--r-- | sbhs_server/tables/management/commands/__init__.py | 0 | ||||
-rw-r--r-- | sbhs_server/tables/management/commands/__init__.pyc | bin | 0 -> 165 bytes | |||
-rw-r--r-- | sbhs_server/tables/management/commands/generate_checksum.py | 33 | ||||
-rw-r--r-- | sbhs_server/tables/management/commands/generate_checksum.pyc | bin | 0 -> 1437 bytes | |||
-rw-r--r-- | sbhs_server/tables/management/commands/initialize_machines.py | 45 | ||||
-rw-r--r-- | sbhs_server/tables/management/commands/initialize_machines.pyc | bin | 0 -> 2354 bytes |
6 files changed, 78 insertions, 0 deletions
diff --git a/sbhs_server/tables/management/commands/__init__.py b/sbhs_server/tables/management/commands/__init__.py new file mode 100644 index 0000000..e69de29 --- /dev/null +++ b/sbhs_server/tables/management/commands/__init__.py diff --git a/sbhs_server/tables/management/commands/__init__.pyc b/sbhs_server/tables/management/commands/__init__.pyc Binary files differnew file mode 100644 index 0000000..2bcdd35 --- /dev/null +++ b/sbhs_server/tables/management/commands/__init__.pyc 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 diff --git a/sbhs_server/tables/management/commands/generate_checksum.pyc b/sbhs_server/tables/management/commands/generate_checksum.pyc Binary files differnew file mode 100644 index 0000000..36d45a7 --- /dev/null +++ b/sbhs_server/tables/management/commands/generate_checksum.pyc diff --git a/sbhs_server/tables/management/commands/initialize_machines.py b/sbhs_server/tables/management/commands/initialize_machines.py new file mode 100644 index 0000000..1987a27 --- /dev/null +++ b/sbhs_server/tables/management/commands/initialize_machines.py @@ -0,0 +1,45 @@ +from django.core.management.base import BaseCommand, CommandError +from sbhs_server import settings +from sbhs_server.tables.models import Board +from sbhs_server import helpers + +class Command(BaseCommand): + args = '' + help = 'Initializes the SBHS board data in the database' + + def handle(self, *args, **options): + previous_onlines = Board.objects.only("mid").filter(online=True) + previous_onlines = [p.mid for p in previous_onlines] + for o in settings.online_mids: + try: + Board.objects.get_or_create(mid=o) + except: + pass + + new_offlines = [] + for p in previous_onlines: + if p not in settings.online_mids: + new_offlines.append(p) + + message = "SBHS Administrator,\n\n" + message += "Following issue requires immidiate attention.\n\n" + message += "SBHS could not be connected\n" + for n in new_offlines: + message += ("MID: %d\n" % n) + message += "\nYou can check the SBHS status on http://vlabs.iitb.ac.in/sbhs/admin/." + message += " Possible correction actions are:\n" + message += "1. Run this command without brackets -> ( cd $SBHS_SERVER_ROOT; ./cron_job.sh )\n" + message += "2. If same machine comes offline multiple times, replacement of the machine is advised.\n\n\n" + message += "Regards,\nSBHS Vlabs Server Code" + + print "New offline board mids", new_offlines + subject = "SBHS Vlabs: Notice - SBHS not connected" + + if len(new_offlines) > 0: + for admin in settings.SBHS_ADMINS: + helpers.mailer.email(admin[2], subject, message) + + Board.objects.filter(mid__in=settings.online_mids).update(online=True) + Board.objects.exclude(mid__in=settings.online_mids).update(online=False) + + self.stdout.write('Boards loaded') diff --git a/sbhs_server/tables/management/commands/initialize_machines.pyc b/sbhs_server/tables/management/commands/initialize_machines.pyc Binary files differnew file mode 100644 index 0000000..cbbb123 --- /dev/null +++ b/sbhs_server/tables/management/commands/initialize_machines.pyc |