Move stdout processing into send_command
This commit is contained in:
parent
f8f51f7489
commit
dd260aa021
2 changed files with 14 additions and 20 deletions
|
@ -96,23 +96,23 @@ class Ledger:
|
||||||
|
|
||||||
return output
|
return output
|
||||||
|
|
||||||
def send_command(self, p, command):
|
def send_command(self, 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):
|
|
||||||
output = None
|
output = None
|
||||||
|
|
||||||
with self.locked_process() as p:
|
with self.locked_process() as p:
|
||||||
_log.debug('aquired process lock')
|
if isinstance(command, str):
|
||||||
self.send_command(p, b'bal --format "%A|%t\\\\n"')
|
command = command.encode('utf8')
|
||||||
_log.debug('sent command')
|
|
||||||
|
p.stdin.write(command + b'\n')
|
||||||
|
p.stdin.flush()
|
||||||
|
|
||||||
output = self.read_until_prompt(p)
|
output = self.read_until_prompt(p)
|
||||||
|
|
||||||
|
return output
|
||||||
|
|
||||||
|
def bal(self):
|
||||||
|
output = self.send_command('bal --format "%A|%t\\\\n"')
|
||||||
|
|
||||||
if output is None:
|
if output is None:
|
||||||
raise RuntimeError('bal call returned no output')
|
raise RuntimeError('bal call returned no output')
|
||||||
|
|
||||||
|
@ -129,13 +129,7 @@ class Ledger:
|
||||||
return accounts
|
return accounts
|
||||||
|
|
||||||
def reg(self):
|
def reg(self):
|
||||||
output = None
|
output = self.send_command( 'xml')
|
||||||
|
|
||||||
with self.locked_process() as p:
|
|
||||||
_log.debug('aquired process lock')
|
|
||||||
self.send_command(p, b'xml')
|
|
||||||
|
|
||||||
output = self.read_until_prompt(p)
|
|
||||||
|
|
||||||
if output is None:
|
if output is None:
|
||||||
raise RuntimeError('reg call returned no output')
|
raise RuntimeError('reg call returned no output')
|
||||||
|
|
|
@ -20,7 +20,7 @@ class AccountingEncoder(json.JSONEncoder):
|
||||||
)
|
)
|
||||||
elif isinstance(o, Transaction):
|
elif isinstance(o, Transaction):
|
||||||
return dict(
|
return dict(
|
||||||
date=o.date,
|
date=o.date.strftime('%Y-%m-%d'),
|
||||||
payee=o.payee,
|
payee=o.payee,
|
||||||
postings=o.postings
|
postings=o.postings
|
||||||
)
|
)
|
||||||
|
@ -53,7 +53,7 @@ def register_report():
|
||||||
|
|
||||||
|
|
||||||
def main():
|
def main():
|
||||||
app.run(debug=True)
|
app.run(host=app.config['HOST'], port=app.config['PORT'])
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
main()
|
main()
|
||||||
|
|
Loading…
Reference in a new issue