Below is the file 'LedgerInterface.py' from this revision. You can also download the file.

#!/usr/bin/env python

# LedgerInterface.py

# Utilities associated with command line UI

import sys
from Chart import Chart
from Ledger import Ledger
from LedgerRender import LedgerRender

from CLIParser import CLIParser, CLIParserError
from States import *

class LedgerInterface:
	def _init_(self):
		self.input = None

	def ledger_prompt(self, state, event, params, v, vstatus):
		sys.stdout.write("fourstar-ledger> ")
		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] == "exit":
			vstatus.change_state(STATE_IDLE, 1)
			return

		if args[0] == "balance":
			if len(args) == 2:
				vstatus.change_state(STATE_LEDGER_BALANCE, 1)
			else:
				print "filename not given: %s" % (self.input,)
			return


		if len(args) >= 1 and args[0] == "print":
			vstatus.change_state(STATE_LEDGER_PRINT, 1)
			return


		print "3 command not understood: %s" % (self.input,)

	def balance(self, state, event, params, v, vstatus):
		args = self.input.split()
		print "filename is %s" % (args[1],)

		c = Chart(v)
		l = Ledger(c)

		r = LedgerRender(l)

		print l.balance(args[1])

		vstatus.change_state(STATE_LEDGER_IDLE, 1)

	def printledger(self, state, event, params, v, vstatus):
		args = self.input.split()
		print "filename is %s" % (args[1],)

		c = Chart(v)
		l = Ledger(c)

		r = LedgerRender(l)

		print l.printledger(args[1])

		vstatus.change_state(STATE_LEDGER_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


#		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)