summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--format.cc11
-rw-r--r--main.py11
-rw-r--r--valexpr.cc14
3 files changed, 29 insertions, 7 deletions
diff --git a/format.cc b/format.cc
index 36b0bd16..c02242f7 100644
--- a/format.cc
+++ b/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>)
diff --git a/main.py b/main.py
index e30e229e..24fdc2b6 100644
--- a/main.py
+++ b/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)
diff --git a/valexpr.cc b/valexpr.cc
index 8b6b5d7d..c40b962c 100644
--- a/valexpr.cc
+++ b/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>)