diff options
author | vikas179 | 2017-06-23 10:45:58 +0530 |
---|---|---|
committer | vikas179 | 2017-06-23 10:48:02 +0530 |
commit | 294d54dac2b8715891ac32d9b93b3bfd885827f6 (patch) | |
tree | 5f174a6b40f3abb6db877162c77ad311e89dfc8f /sbhs_server | |
parent | 470fc4aa20fc68fd0d3ef5c94768a39f3623765c (diff) | |
download | SBHS-2018-Rpi-294d54dac2b8715891ac32d9b93b3bfd885827f6.tar.gz SBHS-2018-Rpi-294d54dac2b8715891ac32d9b93b3bfd885827f6.tar.bz2 SBHS-2018-Rpi-294d54dac2b8715891ac32d9b93b3bfd885827f6.zip |
add further docstrings
Diffstat (limited to 'sbhs_server')
-rw-r--r-- | sbhs_server/helpers/mailer.py | 2 | ||||
-rw-r--r-- | sbhs_server/helpers/simple_encrypt.py | 4 | ||||
-rw-r--r-- | sbhs_server/sbhs.py | 22 | ||||
-rw-r--r-- | sbhs_server/scan_machine1.py | 10 | ||||
-rw-r--r-- | sbhs_server/settings.py | 4 | ||||
-rw-r--r-- | sbhs_server/tables/models.py | 43 |
6 files changed, 61 insertions, 24 deletions
diff --git a/sbhs_server/helpers/mailer.py b/sbhs_server/helpers/mailer.py index e24d3e5..4c61035 100644 --- a/sbhs_server/helpers/mailer.py +++ b/sbhs_server/helpers/mailer.py @@ -2,6 +2,8 @@ from sbhs_server import settings import smtplib def email(to, subject, message): + """ Utility function to send the e-mail using SMTP. + """ smtpserver = smtplib.SMTP() smtpserver.connect(settings.EMAIL_HOST, settings.EMAIL_PORT) smtpserver.ehlo() diff --git a/sbhs_server/helpers/simple_encrypt.py b/sbhs_server/helpers/simple_encrypt.py index 976fe4d..09f8aba 100644 --- a/sbhs_server/helpers/simple_encrypt.py +++ b/sbhs_server/helpers/simple_encrypt.py @@ -1,6 +1,8 @@ import base64 def encrypt(cleartext): + """ Function to encrypt the text which is send over the e-mail to verify the user. + """ string = cleartext string = string[::-1] @@ -17,6 +19,8 @@ def encrypt(cleartext): def decrypt(ciphertext): + """ Function to decrypt the ciphertext + """ data = ciphertext.split(".") padding = int(data[0]) cipher = data[1] diff --git a/sbhs_server/sbhs.py b/sbhs_server/sbhs.py index f7873cb..6820ce5 100644 --- a/sbhs_server/sbhs.py +++ b/sbhs_server/sbhs.py @@ -19,9 +19,10 @@ class Sbhs: """ This is the Single Board Heater System class """ def __init__(self): - # status of the board - # 0 = not connected - # 1 = connected + """ status of the board + 0 = not connected + 1 = connected + """ self.machine_id = 26 self.device_num = 26 self.boardcon = False @@ -106,7 +107,10 @@ class Sbhs: return False def setHeat(self, val): - """ Set the heat """ + """ Sets the heat, checks if value is valid i.e. within range. + Input: self object, val + Output: Error message if heat cannot be set. + """ if val > MAX_HEAT or val < 0: print 'Error: heat value cannot be more than %d' % MAX_HEAT return False @@ -122,7 +126,10 @@ class Sbhs: return False def setFan(self, val): - """ Set the fan """ + """ Sets the fan speed, checks if value is valid i.e. within range. + Input: self object, val + Output: Error message if fan cannot be set. + """ if val > MAX_FAN or val < 0: print 'Error: fan value cannot be more than %d' % MAX_FAN return False @@ -137,7 +144,8 @@ class Sbhs: return False def getTemp(self): - """ Get the temperature """ + """ Gets the temperature from the machine. + """ try: self.boardcon.flushInput() self._write(chr(OUTGOING_TEMP)) @@ -149,7 +157,7 @@ class Sbhs: return 0.0 def getMachineId(self): - """ Get machine id from the device """ + """ Gets machine id from the device """ try: self.boardcon.flushInput() self._write(chr(OUTGOING_MACHINE_ID)) diff --git a/sbhs_server/scan_machine1.py b/sbhs_server/scan_machine1.py index f6922de..d33f32d 100644 --- a/sbhs_server/scan_machine1.py +++ b/sbhs_server/scan_machine1.py @@ -3,25 +3,25 @@ import sbhs import os import sys -# erase the old map_machine_ids.txt file +"""erase the old map_machine_ids.txt file""" try: file('map_machine_ids.txt', 'w').close() except: print 'Failed to create machine map file file' sys.exit(1) -# open the map_machine_ids file for writing +"""open the map_machine_ids file for writing""" try: map_machine_file = file('map_machine_ids.txt', 'w') except: print 'Failed to create machine map file file' sys.exit(1) -# get list of device file names that start with ttyUSB* in the /dev folder -#device_files = [] +""" get list of device file names that start with ttyUSB* in the /dev folder + device_files = []""" device_files = [each for each in os.listdir('/dev') if each.startswith('ttyUSB')] -# if no device filename found then exit +"""if no device filename found then exit""" if not device_files: print 'No USB device found in /dev folder' sys.exit(1) diff --git a/sbhs_server/settings.py b/sbhs_server/settings.py index ba6a19e..271ca16 100644 --- a/sbhs_server/settings.py +++ b/sbhs_server/settings.py @@ -52,7 +52,9 @@ if not DEBUG: ] # Application definition - +""" + Installed apps +""" INSTALLED_APPS = ( #'django.contrib.admin', 'django.contrib.auth', diff --git a/sbhs_server/tables/models.py b/sbhs_server/tables/models.py index 0010d2d..7ab7966 100644 --- a/sbhs_server/tables/models.py +++ b/sbhs_server/tables/models.py @@ -10,6 +10,13 @@ from django.core.exceptions import ObjectDoesNotExist # Create your models here. class Board(TrashableMixin): + """ Declaring varibales + mid = Integer and unique + online = Boolean, Default - True + temp_offline = Boolean, default - False + created_at = DateTime + updated_at = DateTime + """ mid = models.IntegerField(unique=True) online = models.BooleanField(default=True) @@ -24,6 +31,8 @@ class Board(TrashableMixin): @staticmethod def toggle_random_allotment(): + """ Enables to toggle allotment of machines between Workshop mode and Random mode + """ if Board.can_do_random_allotment(): f = open(os.path.join(settings.BASE_DIR, "WORKSHOP_MODE"), "w") f.close() @@ -32,6 +41,8 @@ class Board(TrashableMixin): @staticmethod def allot_board(): + """ + """ if Board.can_do_random_allotment(): online_boards_count = len(settings.online_mids) board_num = random.randrange(online_boards_count) @@ -55,11 +66,12 @@ class Board(TrashableMixin): return -1 def image_link(self): + """ Function to show the image obtained from webcam + """ return settings.WEBCAM_STATIC_DIR + "image" + str(self.mid) + ".jpeg" -class Account(TrashableMixin, AbstractBaseUser): - +class Account(TrashableMixin, AbstractBaseUser): name = models.CharField(max_length=255) username = models.CharField(max_length=127, unique=True) email = models.EmailField(max_length=255, unique=True) @@ -83,12 +95,17 @@ class Account(TrashableMixin, AbstractBaseUser): return self.name def send_confirmation(self): + """ Function to show message to the user to confirm their account by visiting the link sent + to their e-mail. + """ message = """Hi,\n\nPlease visit the link """ + settings.BASE_URL + """sbhs/account/confirm/""" message = message + self.confirmation_token() message = message + """ to confirm your account.\n\n\nRegards,\nVlabs Team""" mailer.email(self.email, "Please confirm your account", message) def send_password_link(self, token): + """ Function to show message to user to visit the link in order to change the password. + """ message = """Hi,\n\nPlease visit the link """ + settings.BASE_URL + """password/edit/""" message = message + token message = message + """ to change your password.\n\n\nRegards,\nVlabs Team""" @@ -122,15 +139,15 @@ class Slot(TrashableMixin): @staticmethod def indices(self, other): - # These lines are irrelevant due to booking date scheme - # - # now = datetime.datetime.now() - # cur_hour = now.hour - - # s = abs(cur_hour - self.start_hour) - # s = s + 100 if self.start_hour < cur_hour else s - # o = abs(cur_hour - other.start_hour) - # o = o + 100 if other.start_hour < cur_hour else o + These lines are irrelevant due to booking date scheme + """ now = datetime.datetime.now() + cur_hour = now.hour + + s = abs(cur_hour - self.start_hour) + s = s + 100 if self.start_hour < cur_hour else s + o = abs(cur_hour - other.start_hour) + o = o + 100 if other.start_hour < cur_hour else o + """ return self.start_hour, other.start_hour def __lt__(self, other): @@ -159,6 +176,10 @@ class Slot(TrashableMixin): @staticmethod def current_slots(mid): + """ Function to display the current slots to the user. + Input: mid + Output: slots + """ now = datetime.datetime.now() slots = list(Slot.objects.filter(start_hour=now.hour, end_minute__gt=now.minute)) bookings = Booking.objects.filter(booking_date__year=now.year, |