No older revisions available
No older revisions available
#VendingMachineCommander.py
import cmd, cStringIO
import VendingMachineParser
def defaultHandler(cmds):
for cmd in cmds:
print cmd
class Commander(cmd.Cmd):
normalPrompt = ': '
def __init__(self,handler=defaultHandler):
cmd.Cmd.__init__(self)
self.timeToQuit = 0
self.prompt = self.normalPrompt
self.parser = VendingMachineParser.Parser()
self.doc_header = "Type 'help <topic>' for info on:"
self.intro = 'Welcome to Vending Machine Simulator!\n'\
"Enter a command or type 'help'"
self.misc_header = ''
self.undoc_header = ''
self.handler = handler
def default(self,line):
'Called on normal commands'
cmds = self.parser.parse(aString=line,aName='Console')
self.handler(cmds)
def do_quit(self,line):
self.timeToQuit = 1
def postcmd(self,stop,line):
if self.timeToQuit:
return 1
return stop
def help_help(self): print 'I need help!'
def help_quit(self): print 'Duh.'
def help_put(self):
print 'put <10 | 50 | 100 | '\
'500 | 1000>'
print 'put a coin or a paper into the slot'
def help_push(self):
print 'push <white | black | sugarwhite | sugarblack>'
print 'push a button on the front panel'
def help_include(self):
print 'include "file"\nExecutes the contents of a file'
if __name__ == '__main__':
c = Commander()
c.cmdloop()