Below is the file 'SystemInterface.py' from this revision. You can also download the file.
#!/usr/bin/env python # SystemInterface.py # Utilities associated with command line UI import sys from CLIParser import CLIParser, CLIParserError from States import * class SystemInterface: def _init_(self): self.input = None def fourstar_prompt(self, state, event, params, v, vstatus): sys.stdout.write("fourstar> ") vstatus.change_state(state, vstatus.counter + 1) def command_input(self, state, event, params, v, vstatus): self.input = sys.stdin.readline().strip("\n") vstatus.change_state(state, vstatus.counter + 1) def parse_command(self, state, event, params, v, vstatus): #sys.stdout.write(self.input) vstatus.change_state(state, 1) args = self.input.split() if not len(args): return if len(args) >= 1 and args[0] == "quit": print "quitter!" vstatus.change_state(STATE_QUIT, 1) return if args[0] == "connect": if len(args) == 2: vstatus.change_state(STATE_CONNECT, 1) else: print "filename not given: %s" % (self.input,) return if args[0] == "create": if len(args) == 2: vstatus.change_state(STATE_CREATE, 1) else: print "filename not given: %s" % (self.input,) return if len(args) >= 1 and args[0] == "status": vstatus.change_state(STATE_STATUS, 1) return # restrict this mode if db not created/connected if len(args) >= 1 and args[0] == "chart": if v.connected: vstatus.change_state(STATE_CHART_IDLE, 1) else: print "not connected" return # restrict this mode if db not created/connected if len(args) >= 1 and args[0] == "ledger": if v.connected: vstatus.change_state(STATE_LEDGER_IDLE, 1) else: print "not connected" return # restrict this mode if db not created/connected if len(args) >= 1 and args[0] == "journal": if v.connected: vstatus.change_state(STATE_JOURNAL_IDLE, 1) else: print "not connected" return print "4 command not understood: %s" % (self.input,) def create(self, state, event, params, v, vstatus): args = self.input.split() filename = args[1] print "filename is %s" % (filename,) v.create_store(filename) vstatus.change_state(STATE_IDLE, 1) def connect(self, state, event, params, v, vstatus): args = self.input.split() filename = args[1] print "filename is %s" % (filename,) v.connect_store(filename) vstatus.change_state(STATE_IDLE, 1) # # need to subclass optionparser # op = CLIParser(usage = "foo") # try: # options, args = op.parse_args(args) # except CLIParserError: ## print "command problem: %s" % (self.input,) # return def status(self, state, event, params, v, vstatus): print "status!!!!!" vstatus.change_state(STATE_IDLE, 1) # if len(args) != 0: # op.error('extra command line arguments: ' + ' '.join(args)) #print args #return options # def chart_prompt(self, state, event, params, v, vstatus): # sys.stdout.write("fourstar-chart> ") # vstatus.change_state(state, vstatus.counter + 1) # # def ledger_prompt(self, state, event, params, v, vstatus): # sys.stdout.write("fourstar-ledger> ") # vstatus.change_state(state, vstatus.counter + 1) # # def journal_prompt(self, state, event, params, v, vstatus): # sys.stdout.write("fourstar-journal> ") # vstatus.change_state(state, vstatus.counter + 1)