Move stdout processing into send_command

This commit is contained in:
Joar Wandborg 2013-12-09 21:04:17 +01:00
parent f8f51f7489
commit dd260aa021
2 changed files with 14 additions and 20 deletions

View file

@ -96,23 +96,23 @@ class Ledger:
return output
def send_command(self, p, command):
# TODO: Should be extended to handle the locking and return the output
_bytes = p.stdin.write(command + b'\n')
p.stdin.flush()
return _bytes
def bal(self):
def send_command(self, command):
output = None
with self.locked_process() as p:
_log.debug('aquired process lock')
self.send_command(p, b'bal --format "%A|%t\\\\n"')
_log.debug('sent command')
if isinstance(command, str):
command = command.encode('utf8')
p.stdin.write(command + b'\n')
p.stdin.flush()
output = self.read_until_prompt(p)
return output
def bal(self):
output = self.send_command('bal --format "%A|%t\\\\n"')
if output is None:
raise RuntimeError('bal call returned no output')
@ -129,13 +129,7 @@ class Ledger:
return accounts
def reg(self):
output = None
with self.locked_process() as p:
_log.debug('aquired process lock')
self.send_command(p, b'xml')
output = self.read_until_prompt(p)
output = self.send_command( 'xml')
if output is None:
raise RuntimeError('reg call returned no output')

View file

@ -20,7 +20,7 @@ class AccountingEncoder(json.JSONEncoder):
)
elif isinstance(o, Transaction):
return dict(
date=o.date,
date=o.date.strftime('%Y-%m-%d'),
payee=o.payee,
postings=o.postings
)
@ -53,7 +53,7 @@ def register_report():
def main():
app.run(debug=True)
app.run(host=app.config['HOST'], port=app.config['PORT'])
if __name__ == '__main__':
main()