unices (Alexis) on IRC had a great idea for the Ledger Python support today.
He suggested adding a method to Journal objects which would allows you to get
back a collection of the postings related to a report query. The code would
look a lot like this:
import sys
from ledger import Journal
running_total = ledger.Value(0)
for post in ledger.Journal("sample.dat").collect(sys.argv[1]):
print "%s %-20.20s %-20.20s %12s %12s" % \
(post.xact.date, post.xact.payee, post.account, post.amount,
running_total)
At first I thought this would be fairly easy to implement, and it turns out the
code to provide the basic facility wasn't much. However, what it unearthed
concerning Ledger's compatibility with Python was most disturbing.
As a result, I realize that to properly support Python, parts of Ledger will
need to be fundamentally changed. There is too much of a "one run, one report"
mentality in the code, as much as I've tried to change it to support the REPL
and interfacing with a GUI. The data structures in Ledger don't like you
creating a Journal object, for example, and then keeping a reference to one of
its member Accounts while deleting the Journal that owned it. There is no
reference counting being done to ensure that all the necessary object stay
alive, to support the continued existence of any single object.
So, this is definitely a 3.1 feature, not only because of the work involved,
but because I think it needs a lot more thought. It shouldn't require *too*
big of a change, but it will be an extensive one. I essentially need to add
reference counting everywhere, and also allow deep copying of every object so
that report sets and object can be truly standalone once created.
John