diff options
author | John Wiegley <johnw@newartisans.com> | 2004-09-14 06:36:16 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-09-14 06:36:16 -0400 |
commit | f2162bf7ee556c5d46a3a48a4d93bb892041b067 (patch) | |
tree | e58736a8414328c0a3d0aefcf146dc332b677248 | |
parent | 061e19e302fb62eaafbd2029671bdd46dd4d7814 (diff) | |
download | fork-ledger-f2162bf7ee556c5d46a3a48a4d93bb892041b067.tar.gz fork-ledger-f2162bf7ee556c5d46a3a48a4d93bb892041b067.tar.bz2 fork-ledger-f2162bf7ee556c5d46a3a48a4d93bb892041b067.zip |
further python integration improvements
-rw-r--r-- | format.cc | 11 | ||||
-rw-r--r-- | main.py | 11 | ||||
-rw-r--r-- | valexpr.cc | 14 |
3 files changed, 29 insertions, 7 deletions
@@ -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>) @@ -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) @@ -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>) |