further python integration improvements
This commit is contained in:
parent
061e19e302
commit
f2162bf7ee
3 changed files with 29 additions and 7 deletions
11
format.cc
11
format.cc
|
|
@ -438,8 +438,16 @@ bool format_account::display_account(const account_t& account,
|
|||
using namespace boost::python;
|
||||
using namespace ledger;
|
||||
|
||||
std::string py_format_1(format_t& format, const details_t& item)
|
||||
{
|
||||
std::ostringstream out;
|
||||
format.format(out, item);
|
||||
return out.str();
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
std::string py_format(format_t& format, T& item) {
|
||||
std::string py_format(format_t& format, const T& item)
|
||||
{
|
||||
std::ostringstream out;
|
||||
format.format(out, details_t(item));
|
||||
return out.str();
|
||||
|
|
@ -450,6 +458,7 @@ void export_format()
|
|||
class_< format_t > ("Format")
|
||||
.def(init<std::string>())
|
||||
.def("reset", &format_t::reset)
|
||||
.def("format", py_format_1)
|
||||
.def("format", py_format<account_t>)
|
||||
.def("format", py_format<entry_t>)
|
||||
.def("format", py_format<transaction_t>)
|
||||
|
|
|
|||
11
main.py
11
main.py
|
|
@ -16,6 +16,9 @@ add_option_handler ("goodbye", ":", goodbye)
|
|||
args = process_arguments (sys.argv[1:])
|
||||
process_environment (os.environ, "LEDGER_")
|
||||
|
||||
if len (args) > 0:
|
||||
config.process_options (args[0], args[1:])
|
||||
|
||||
text_parser = TextualParser ()
|
||||
register_parser (text_parser)
|
||||
|
||||
|
|
@ -30,14 +33,14 @@ class FormatTransaction (TransactionHandler):
|
|||
def __call__ (self, xact):
|
||||
print self.formatter.format(xact)
|
||||
|
||||
def foo(d, val):
|
||||
return d.xact.amount + val
|
||||
expr = parse_value_expr ("a*2")
|
||||
|
||||
def foo(x, val):
|
||||
return x.xact.amount + expr.compute (x) + val
|
||||
|
||||
handler = FormatTransaction("%D %-20P %N %('foo'{$100})")
|
||||
handler = FilterTransactions (handler, "/Checking/")
|
||||
|
||||
expr = parse_value_expr ("a*2")
|
||||
|
||||
for entry in journal:
|
||||
for xact in entry:
|
||||
handler (xact)
|
||||
|
|
|
|||
14
valexpr.cc
14
valexpr.cc
|
|
@ -901,14 +901,23 @@ void dump_value_expr(std::ostream& out, const value_expr_t * node)
|
|||
using namespace boost::python;
|
||||
using namespace ledger;
|
||||
|
||||
value_t py_compute_1(value_expr_t& value_expr, const details_t& item)
|
||||
{
|
||||
value_t result;
|
||||
value_expr.compute(result, item);
|
||||
return result;
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
value_t py_compute(value_expr_t& value_expr, const T& item) {
|
||||
value_t py_compute(value_expr_t& value_expr, const T& item)
|
||||
{
|
||||
value_t result;
|
||||
value_expr.compute(result, details_t(item));
|
||||
return result;
|
||||
}
|
||||
|
||||
value_expr_t * py_parse_value_expr(const std::string& str) {
|
||||
value_expr_t * py_parse_value_expr(const std::string& str)
|
||||
{
|
||||
return parse_value_expr(str);
|
||||
}
|
||||
|
||||
|
|
@ -929,6 +938,7 @@ void export_valexpr()
|
|||
;
|
||||
|
||||
class_< value_expr_t > ("ValueExpr", init<value_expr_t::kind_t>())
|
||||
.def("compute", py_compute_1)
|
||||
.def("compute", py_compute<account_t>)
|
||||
.def("compute", py_compute<entry_t>)
|
||||
.def("compute", py_compute<transaction_t>)
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue