import socket
from posix import geteuid
from OpenDispense import OpenDispense as Dispense
+import TracebackPrinter
CREDITS="""
This vending machine software brought to you by:
# If the user has just logged in, show them their balance
if welcome:
balance = self.dispense.getBalance()
- balance = balance[:-4] + '.' + balance[-4] + balance[-2:] # Work around display bug
-
msg = [(self.center('WELCOME'), False, TEXT_SPEED),
(self.center(self.dispense.getUsername()), False, TEXT_SPEED),
(self.center(balance), False, TEXT_SPEED),]
# Price check mode.
(name,price) = self.dispense.getItemInfo(self.vstatus.cur_selection)
dollarprice = "$%.2f" % ( price / 100.0 )
- dollarprice = dollarprice[:-4] + '.' + dollarprice[-4] + dollarprice[-2:] # Work around display bug
self.v.display( self.vstatus.cur_selection+' - %s'%dollarprice)
self.vstatus.cur_selection = ''
exitcode = os.system('dispense -u "%s" snack:%s'%(self.vstatus.username, self.vstatus.cur_selection)) >> 8
if (exitcode == 0):
# magic dispense syslog service
- syslog.syslog(syslog.LOG_INFO | syslog.LOG_LOCAL4, "vended %s (slot %s) for %s" % (name, self.vstatus.cur_selection, self.vstatus.username))
(worked, code, string) = self.v.vend(self.vstatus.cur_selection)
if worked:
self.v.display('THANK YOU')
+ syslog.syslog(syslog.LOG_INFO | syslog.LOG_LOCAL4, "vended %s (slot %s) for %s" % (name, self.vstatus.cur_selection, self.vstatus.username))
else:
print "Vend Failed:", code, string
+ syslog.syslog(syslog.LOG_WARNING | syslog.LOG_LOCAL4, "vending %s (slot %s) for %s FAILED %r %r" % (name, self.vstatus.cur_selection, self.vstatus.username, code, string))
self.v.display('VEND FAIL')
elif (exitcode == 5): # RV_BALANCE
self.v.display('NO MONEY?')
if self.vstatus.cur_pin == '':
self.vstatus.cur_user = ''
self.dispense.logOut()
- slef.reset_idler()
+ self.reset_idler()
return
self.vstatus.cur_pin = ''
op.add_option('-v', '--verbose', dest='verbose', action='store_true', default=False, help='spit out lots of debug output')
op.add_option('-q', '--quiet', dest='quiet', action='store_true', default=False, help='only report errors')
op.add_option('--pid-file', dest='pid_file', metavar='FILE', default='', help='store daemon\'s pid in the given file')
+ op.add_option('--traceback-file', dest='traceback_file', default='', help='destination to print tracebacks when receiving SIGUSR1')
options, args = op.parse_args()
if len(args) != 0:
if options.daemon: become_daemon()
set_up_logging(options)
if options.pid_file != '': create_pid_file(options.pid_file)
-
+ if options.traceback_file != '': TracebackPrinter.traceback_init(options.traceback_file)
return options, config_opts
def clean_up_nicely(options, config_opts):
continue
# run_forever(rfh, wfh, options, config_opts)
-
+
try:
vserver = VendServer()
vserver.run_forever(rfh, wfh, options, config_opts)