USE_DB = 0
import ConfigParser
-import sys, os, string, re, pwd, signal, math
+import sys, os, string, re, pwd, signal, math, syslog
import logging, logging.handlers
from traceback import format_tb
if USE_DB: import pg
from HorizScroll import HorizScroll
from random import random, seed
from Idler import GreetingIdler,TrainIdler,GrayIdler,StringIdler,ClockIdler,FortuneIdler,FileIdler,PipeIdler
+from SnackConfig import get_snacks, get_snack
import socket
from posix import geteuid
c = c.strip()
(slot_num, price, slot_name) = c.split(' ', 2)
if slot_name == 'dead': continue
- choices += '%s8-%s (%sc) '%(slot_num, slot_name, price)
+ choices += '%s-(%sc)-%s8 '%(slot_name, price, slot_num)
+
+# we don't want to print snacks for now since it'll be too large
+# and there's physical bits of paper in the machine anyway - matt
+# try:
+# snacks = get_snacks()
+# except:
+# snacks = {}
+#
+# for slot, ( name, price ) in snacks.items():
+# choices += '%s8-%s (%sc) ' % ( slot, name, price )
+
choices += '55-DOOR '
- choices += 'OR A SNACK. '
+ choices += 'OR ANOTHER SNACK. '
choices += '99 TO READ AGAIN. '
choices += 'CHOICE? '
msg.append((choices, False, None))
GrayIdler(v,one="/",zero="\\"),
ClockIdler(v),
GrayIdler(v,one="X",zero="O"),
- FileIdler(v, '/usr/share/common-licenses/GPL-2'),
+ FileIdler(v, '/usr/share/common-licenses/GPL-2',affinity=2),
GrayIdler(v,one="*",zero="-",reorder=1),
StringIdler(v, text=str(math.pi) + " "),
ClockIdler(v),
GrayIdler(v,one="/",zero="\\",reorder=1),
StringIdler(v, text=str(math.e) + " "),
GrayIdler(v,one="X",zero="O",reorder=1),
- StringIdler(v, text=" I want some pizza - please call Pizza Hut Shenton Park on +61 8 9381 9979 - and order as Quinn - I am getting really hungry", repeat=False),
- PipeIdler(v, "/usr/bin/ypcat", "passwd"),
+ StringIdler(v, text=" I want some pizza - please call Pizza Hut Shenton Park on +61 8 9381 9979 [now closed? - MSH] - and order as Quinn - I am getting really hungry", repeat=False),
+ PipeIdler(v, "/usr/bin/getent", "passwd"),
FortuneIdler(v),
ClockIdler(v),
StringIdler(v),
idler = GreetingIdler(v, t)
vstatus.time_of_next_idlestep = time()+idler.next()
vstatus.time_of_next_idler = None
+ vstatus.time_to_autologout = None
vstatus.change_state(STATE_IDLE, 1)
def choose_idler():
vstatus.cur_user = ''
vstatus.cur_selection = ''
- reset_idler(v, vstatus)
-
vstatus.mk.set_messages([(center('BYE!'), False, 1.5)])
+ reset_idler(v, vstatus, 2)
return
vstatus.cur_selection += chr(key + ord('0'))
vstatus.mk.set_message('SELECT: '+vstatus.cur_selection)
vstatus.cur_selection = ''
return
elif vstatus.cur_selection[1] == '8':
- v.display('GOT COKE?')
+ v.display('GOT DRINK?')
if ((os.system('su - "%s" -c "dispense %s"'%(vstatus.username, vstatus.cur_selection[0])) >> 8) != 0):
v.display('SEEMS NOT')
else:
- v.display('GOT COKE!')
+ v.display('GOT DRINK!')
else:
- v.display(vstatus.cur_selection+' - $1.00')
- if ((os.system('su - "%s" -c "dispense snack"'%(vstatus.username)) >> 8) == 0):
+ # first see if it's a named slot
+ try:
+ price, shortname, name = get_snack( vstatus.cur_selection )
+ except:
+ price, shortname, name = get_snack( '--' )
+ dollarprice = "$%.2f" % ( price / 100.0 )
+ v.display(vstatus.cur_selection+' - %s'%dollarprice)
+ exitcode = os.system('su - "%s" -c "dispense give oday %d"'%(vstatus.username, price)) >> 8
+ if (exitcode == 0):
+ # magic dispense syslog service
+ syslog.syslog(syslog.LOG_INFO | syslog.LOG_LOCAL4, "vended %s (slot %s) for %s" % (name, vstatus.cur_selection, vstatus.username))
v.vend(vstatus.cur_selection)
v.display('THANK YOU')
else:
+ syslog.syslog(syslog.LOG_INFO | syslog.LOG_LOCAL4, "failed vending %s (slot %s) for %s (code %d)" % (name, vstatus.cur_selection, vstatus.username, exitcode))
v.display('NO MONEY?')
sleep(1)
if len(vstatus.cur_user) == 5:
uid = int(vstatus.cur_user)
+ if uid == 0:
+ logging.info('user '+vstatus.cur_user+' has a bad PIN')
+ pfalken="""
+CARRIER DETECTED
+
+CONNECT 128000
+
+Welcome to Picklevision Sytems, Sunnyvale, CA
+
+Greetings Professor Falken.
+
+
+
+
+Shall we play a game?
+
+
+Please choose from the following menu:
+
+1. Tic-Tac-Toe
+2. Chess
+3. Checkers
+4. Backgammon
+5. Poker
+6. Toxic and Biochemical Warfare
+7. Global Thermonuclear War
+
+7 [ENTER]
+
+Wouldn't you prefer a nice game of chess?
+
+""".replace('\n',' ')
+ vstatus.mk.set_messages([(pfalken, False, 10)])
+ vstatus.cur_user = ''
+ vstatus.cur_pin = ''
+
+ reset_idler(v, vstatus, 10)
+
+ return
+
if not has_good_pin(uid):
logging.info('user '+vstatus.cur_user+' has a bad PIN')
vstatus.mk.set_messages(
- [(' '*10+'INVALID PIN SETUP'+' '*10, False, 3)])
+ [(' '*10+'INVALID PIN SETUP'+' '*11, False, 3)])
vstatus.cur_user = ''
vstatus.cur_pin = ''
- reset_idler(v, vstatus, 5)
+ reset_idler(v, vstatus, 3)
return
def handle_idle_tick(state, event, params, v, vstatus):
### State idling
- idle_step(vstatus)
+ if vstatus.mk.done():
+ idle_step(vstatus)
if vstatus.time_of_next_idler and time() > vstatus.time_of_next_idler:
vstatus.time_of_next_idler = time() + 30
def get_state_table_handler(vstatus, state, event, counter):
return vstatus.state_table[(state,event,counter)]
+def time_to_next_update(vstatus):
+ idle_update = vstatus.time_of_next_idlestep - time()
+ if not vstatus.mk.done() and vstatus.mk.next_update is not None:
+ mk_update = vstatus.mk.next_update - time()
+ if mk_update < idle_update:
+ idle_update = mk_update
+ return idle_update
+
def run_forever(rfh, wfh, options, cf):
v = VendingMachine(rfh, wfh)
vstatus = VendState(v)
logging.error('Database error: '+str(e))
- e = v.next_event(vstatus.time_of_next_idlestep-time())
+ timeout = time_to_next_update(vstatus)
+ e = v.next_event(timeout)
(event, params) = e
run_handler(event, params, v, vstatus)