Update LAT version.
[zanchey/dispense2.git] / sql-edition / servers / VendServer.py
index 992a65d..c82dda8 100755 (executable)
@@ -4,7 +4,7 @@
 USE_DB = 0
 
 import ConfigParser
-import sys, os, string, re, pwd, signal
+import sys, os, string, re, pwd, signal, math
 import logging, logging.handlers
 from traceback import format_tb
 if USE_DB: import pg
@@ -12,12 +12,29 @@ from time import time, sleep
 from popen2 import popen2
 from LATClient import LATClient, LATClientException
 from VendingMachine import VendingMachine, VendingException
+from MessageKeeper import MessageKeeper
 from HorizScroll import HorizScroll
 from random import random, seed
-from Idler import TrainIdler,GrayIdler
+from Idler import TrainIdler,GrayIdler,StringIdler
 import socket
 from posix import geteuid
 
+CREDITS="""
+This vending machine software brought to you by:
+Bernard Blackham
+Mark Tearle
+Nick Bannon
+Cameron Patrick
+and a collective of hungry alpacas.
+
+
+
+For a good time call +61 8 6488 3901
+
+
+
+"""
+
 GREETING = 'UCC SNACKS'
 PIN_LENGTH = 4
 
@@ -164,58 +181,20 @@ def center(str):
        LEN = 10
        return ' '*((LEN-len(str))/2)+str
 
-class MessageKeeper:
-       def __init__(self, vendie):
-               # Each element of scrolling_message should be a 3-tuple of
-               # ('message', True/False if it is to be repeated, time to display)
-               self.scrolling_message = []
-               self.v = vendie
-               self.next_update = None
-
-       def set_message(self, string):
-               self.scrolling_message = [(string, False, None)]
-               self.update_display(True)
-
-       def set_messages(self, strings):
-               self.scrolling_message = strings
-               self.update_display(True)
-
-       def update_display(self, forced = False):
-               if not forced and self.next_update != None and time() < self.next_update:
-                       return
-               if len(self.scrolling_message) > 0:
-                       if len(self.scrolling_message[0][0]) > 10:
-                               (m, r, t) = self.scrolling_message[0]
-                               a = []
-                               exp = HorizScroll(m).expand(padding = 0, wraparound = True)
-                               if t == None:
-                                       t = 0.1
-                               else:
-                                       t = t / len(exp)
-                               for x in exp:
-                                       a.append((x, r, t))
-                               del self.scrolling_message[0]
-                               self.scrolling_message = a + self.scrolling_message
-                       newmsg = self.scrolling_message[0]
-                       if newmsg[2] != None:
-                               self.next_update = time() + newmsg[2]
-                       else:
-                               self.next_update = None
-                       self.v.display(self.scrolling_message[0][0])
-                       if self.scrolling_message[0][1]:
-                               self.scrolling_message.append(self.scrolling_message[0])
-                       del self.scrolling_message[0]
 
-       def done(self):
-               return len(self.scrolling_message) == 0
 
 idlers = []
 idler = None
+
 def setup_idlers(v):
        global idlers, idler
        idlers = [
-               TrainIdler(v),
+               StringIdler(v),
+               StringIdler(v, text=CREDITS),
+               StringIdler(v, text=str(math.pi) + "            "),
+               StringIdler(v, text=str(math.e) + "            "),
                GrayIdler(v),
+               TrainIdler(v),
                GrayIdler(v,one="*",zero="-"),
                GrayIdler(v,one="/",zero="\\"),
                GrayIdler(v,one="X",zero="O"),
@@ -278,11 +257,11 @@ def run_forever(rfh, wfh, options, cf):
                        time_to_autologout = time() + 15
 
                if time_to_idle == None and cur_user == '':
-                       time_to_idle = time() + 30
+                       time_to_idle = time() + 5
                        choose_idler()
-               if time_to_idle != None and cur_user != '': time_to_idle = None
+               if time_to_idle is not None and cur_user != '': time_to_idle = None
                if time_to_idle is not None and time() > time_to_idle: idle_step()
-               if time() > time_to_idle + 300:
+               if time_to_idle is not None and time() > time_to_idle + 300:
                        time_to_idle = time()
                        choose_idler()
 

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