Add sensibility
[uccvend-vendserver.git] / sql-edition / servers / VendServer.py
index 819de13..b1274da 100755 (executable)
@@ -1,8 +1,10 @@
 #!/usr/bin/python
 # vim:ts=4
 
 #!/usr/bin/python
 # vim:ts=4
 
+USE_DB = 0
+
 import sys, os, string, re, pwd
 import sys, os, string, re, pwd
-import pg
+if USE_DB: import pg
 from time import time, sleep
 from popen2 import popen2
 from LATClient import LATClient
 from time import time, sleep
 from popen2 import popen2
 from LATClient import LATClient
@@ -54,8 +56,13 @@ def scroll_options(username, mk, welcome = False):
        else:
                msg = []
        choices = ' '*10+'CHOICES: '
        else:
                msg = []
        choices = ' '*10+'CHOICES: '
-       coke_machine = file('/home/other/coke/coke_contents')
-       cokes = coke_machine.readlines()
+       try:
+               coke_machine = file('/home/other/coke/coke_contents')
+               cokes = coke_machine.readlines()
+               coke_machine.close()
+       except:
+               cokes = []
+               pass
        for c in cokes:
                c = c.strip()
                (slot_num, price, slot_name) = c.split(' ', 2)
        for c in cokes:
                c = c.strip()
                (slot_num, price, slot_name) = c.split(' ', 2)
@@ -63,7 +70,8 @@ def scroll_options(username, mk, welcome = False):
                choices += '%s8-%s (%sc) '%(slot_num, slot_name, price)
        choices += '55-DOOR '
        choices += 'OR A SNACK. '
                choices += '%s8-%s (%sc) '%(slot_num, slot_name, price)
        choices += '55-DOOR '
        choices += 'OR A SNACK. '
-       choices += '99 TO READ AGAIN.'
+       choices += '99 TO READ AGAIN. '
+       choices += 'CHOICE?   '
        msg.append((choices, False, None))
        mk.set_messages(msg)
 
        msg.append((choices, False, None))
        mk.set_messages(msg)
 
@@ -140,7 +148,7 @@ class MessageKeeper:
                        if len(self.scrolling_message[0][0]) > 10:
                                (m, r, t) = self.scrolling_message[0]
                                a = []
                        if len(self.scrolling_message[0][0]) > 10:
                                (m, r, t) = self.scrolling_message[0]
                                a = []
-                               exp = HorizScroll(m).expand(padding = 10)
+                               exp = HorizScroll(m).expand(padding = 0, wraparound = False)
                                if t == None:
                                        t = 0.1
                                else:
                                if t == None:
                                        t = 0.1
                                else:
@@ -186,7 +194,7 @@ if __name__ == '__main__':
        v = VendingMachine(rfh, wfh)
        print 'PING is', v.ping()
 
        v = VendingMachine(rfh, wfh)
        print 'PING is', v.ping()
 
-       db = DispenseDatabase(v, DBServer, DBName, DBUser, DBPassword)
+       if USE_DB: db = DispenseDatabase(v, DBServer, DBName, DBUser, DBPassword)
        cur_user = ''
        cur_pin = ''
        cur_selection = ''
        cur_user = ''
        cur_pin = ''
        cur_selection = ''
@@ -197,13 +205,14 @@ if __name__ == '__main__':
        last_timeout_refresh = None
 
        while True:
        last_timeout_refresh = None
 
        while True:
-               db.handle_events()
+               if USE_DB: db.handle_events()
 
                if logout_timeout != None:
                        time_left = logout_timeout - time()
 
                if logout_timeout != None:
                        time_left = logout_timeout - time()
-                       if time_left < 10 and (last_timeout_refresh > time_left or last_timeout_refresh is None):
+                       if time_left < 5 and (last_timeout_refresh is None or last_timeout_refresh > time_left):
                                mk.set_message('LOGOUT: '+str(int(time_left)))
                                last_timeout_refresh = int(time_left)
                                mk.set_message('LOGOUT: '+str(int(time_left)))
                                last_timeout_refresh = int(time_left)
+                               cur_selection = ''
 
                if logout_timeout != None and logout_timeout - time() <= 0:
                        logout_timeout = None
 
                if logout_timeout != None and logout_timeout - time() <= 0:
                        logout_timeout = None
@@ -215,7 +224,7 @@ if __name__ == '__main__':
                if logout_timeout and not mk.done(): logout_timeout = None
                if len(cur_pin) == PIN_LENGTH and mk.done() and logout_timeout == None:
                        # start autologout
                if logout_timeout and not mk.done(): logout_timeout = None
                if len(cur_pin) == PIN_LENGTH and mk.done() and logout_timeout == None:
                        # start autologout
-                       logout_timeout = time() + 10
+                       logout_timeout = time() + 15
 
                mk.update_display()
 
 
                mk.update_display()
 
@@ -300,6 +309,7 @@ if __name__ == '__main__':
                        elif len(cur_selection) == 1:
                                if key == 11:
                                        cur_selection = ''
                        elif len(cur_selection) == 1:
                                if key == 11:
                                        cur_selection = ''
+                                       logout_timeout = None
                                        scroll_options(username, mk)
                                        continue
                                else:
                                        scroll_options(username, mk)
                                        continue
                                else:

UCC git Repository :: git.ucc.asn.au