Bases: accounting.storage.Storage
Writes a transaction to the ledger file by opening it in ‘ab’ mode and writing a ledger transaction based on the Transaction instance in transaction.
Returns a list of arguments suitable for subprocess.Popen based on self.ledger_bin and self.ledger_file.
Delete a transaction from the ledger file.
This method opens the ledger file, loads all lines into memory and looks for the transaction_id, then looks for the bounds of that transaction in the ledger file, removes all lines within the bounds of the transaction and removes them, then writes the lines back to the ledger file.
Exceptions:
Returns self.ledger_process if it evaluates to True. If self.ledger_process is not set the result of self.init_process() is returned.
Creates a new (presumably) ledger subprocess based on the args from Ledger.assemble_arguments() and then runs Ledger.read_until_prompt() once (which should return the banner text) and discards the output.
Context manager that checks that the ledger process is not already locked, then “locks” the process and yields the process handle and unlocks the process when execution is returned.
Since this decorated as a contextlib.contextmanager() the recommended use is with the with-statement.
with self.locked_process() as p:
p.stdin.write(b'bal\n')
output = self.read_until_prompt(p)
Reads from the subprocess instance process until it finds a combination of \n]\x20 (the prompt), then returns the output without the prompt.
Update a transaction in the ledger file.
Takes a Transaction object and removes the old transaction using transaction.id from the passed Transaction instance and adds transaction to the database.