summaryrefslogtreecommitdiff
path: root/sbhs_server/tables/management
diff options
context:
space:
mode:
authorttt2017-05-13 00:29:47 +0530
committerttt2017-05-13 00:29:47 +0530
commitabf599be33b383a6a5baf9493093b2126a622ac8 (patch)
tree4c5ab6e0d935d5e65fabcf0258e4a00dd20a5afa /sbhs_server/tables/management
downloadSBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.gz
SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.tar.bz2
SBHS-2018-Rpi-abf599be33b383a6a5baf9493093b2126a622ac8.zip
added all server files
Diffstat (limited to 'sbhs_server/tables/management')
-rw-r--r--sbhs_server/tables/management/__init__.py0
-rw-r--r--sbhs_server/tables/management/__init__.pycbin0 -> 156 bytes
-rw-r--r--sbhs_server/tables/management/commands/__init__.py0
-rw-r--r--sbhs_server/tables/management/commands/__init__.pycbin0 -> 165 bytes
-rw-r--r--sbhs_server/tables/management/commands/generate_checksum.py33
-rw-r--r--sbhs_server/tables/management/commands/generate_checksum.pycbin0 -> 1437 bytes
-rw-r--r--sbhs_server/tables/management/commands/initialize_machines.py45
-rw-r--r--sbhs_server/tables/management/commands/initialize_machines.pycbin0 -> 2354 bytes
8 files changed, 78 insertions, 0 deletions
diff --git a/sbhs_server/tables/management/__init__.py b/sbhs_server/tables/management/__init__.py
new file mode 100644
index 0000000..e69de29
--- /dev/null
+++ b/sbhs_server/tables/management/__init__.py
diff --git a/sbhs_server/tables/management/__init__.pyc b/sbhs_server/tables/management/__init__.pyc
new file mode 100644
index 0000000..409acc5
--- /dev/null
+++ b/sbhs_server/tables/management/__init__.pyc
Binary files differ
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
new file mode 100644
index 0000000..2bcdd35
--- /dev/null
+++ b/sbhs_server/tables/management/commands/__init__.pyc
Binary files differ
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
new file mode 100644
index 0000000..36d45a7
--- /dev/null
+++ b/sbhs_server/tables/management/commands/generate_checksum.pyc
Binary files differ
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
new file mode 100644
index 0000000..cbbb123
--- /dev/null
+++ b/sbhs_server/tables/management/commands/initialize_machines.pyc
Binary files differ