summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorELIPTUS <eliptus+git@gmail.com>2014-11-12 22:51:56 -0800
committerELIPTUS <eliptus+git@gmail.com>2014-11-12 22:51:56 -0800
commitaf571c104790b0703d94b0f94b949041cf4f5c1d (patch)
tree43d0d7024aeb3d0f9327307f420acd9b5c182b32
parenta3f3aa304fcfb19fc716c5eaf33a6e152bb3aa71 (diff)
downloadfork-ledger-af571c104790b0703d94b0f94b949041cf4f5c1d.tar.gz
fork-ledger-af571c104790b0703d94b0f94b949041cf4f5c1d.tar.bz2
fork-ledger-af571c104790b0703d94b0f94b949041cf4f5c1d.zip
Improve Embedded Python Support
Discussion: https://groups.google.com/d/msg/ledger-cli/kq9sKoRX9vw/fmyhvPslzokJ
-rw-r--r--src/py_account.cc27
-rw-r--r--src/py_balance.cc2
-rw-r--r--src/py_session.cc2
-rw-r--r--src/session.cc5
-rw-r--r--src/session.h2
5 files changed, 35 insertions, 3 deletions
diff --git a/src/py_account.cc b/src/py_account.cc
index 3054512e..7b8eda8c 100644
--- a/src/py_account.cc
+++ b/src/py_account.cc
@@ -35,6 +35,7 @@
#include "pyutils.h"
#include "account.h"
#include "post.h"
+#include "expr.h"
namespace ledger {
@@ -97,6 +98,26 @@ namespace {
return str_to_py_unicode(account.fullname());
}
+ value_t py_amount_0(const account_t& account)
+ {
+ return account.amount();
+ }
+
+ value_t py_amount_1(const account_t& account, const boost::optional<expr_t&>& expr)
+ {
+ return account.amount(expr);
+ }
+
+ value_t py_total_0(const account_t& account)
+ {
+ return account.total();
+ }
+
+ value_t py_total_1(const account_t& account, const boost::optional<expr_t&>& expr)
+ {
+ return account.total(expr);
+ }
+
} // unnamed namespace
void export_account()
@@ -221,8 +242,10 @@ void export_account()
.def("xdata", py_xdata,
return_internal_reference<>())
- .def("amount", &account_t::amount)
- .def("total", &account_t::total)
+ .def("amount", py_amount_0)
+ .def("amount", py_amount_1, args("expr"))
+ .def("total", py_total_0)
+ .def("total", py_total_1, args("expr"))
.def("self_details", &account_t::self_details,
return_internal_reference<>())
diff --git a/src/py_balance.cc b/src/py_balance.cc
index 8bf30050..dec08a51 100644
--- a/src/py_balance.cc
+++ b/src/py_balance.cc
@@ -64,7 +64,7 @@ namespace {
boost::optional<amount_t>
py_commodity_amount_1(const balance_t& balance,
- const boost::optional<const commodity_t&>& commodity) {
+ const commodity_t& commodity) {
return balance.commodity_amount(commodity);
}
diff --git a/src/py_session.cc b/src/py_session.cc
index 25d13cc0..5253dba3 100644
--- a/src/py_session.cc
+++ b/src/py_session.cc
@@ -61,6 +61,8 @@ void export_session()
.def("read_journal_files", &session_t::read_journal_files,
return_internal_reference<>())
.def("close_journal_files", &session_t::close_journal_files)
+ .def("journal", &session_t::get_journal,
+ return_internal_reference<>())
;
scope().attr("session") =
diff --git a/src/session.cc b/src/session.cc
index e373eb03..f20b4f6c 100644
--- a/src/session.cc
+++ b/src/session.cc
@@ -265,6 +265,11 @@ void session_t::close_journal_files()
amount_t::initialize();
}
+journal_t * session_t::get_journal()
+{
+ return journal.get();
+}
+
value_t session_t::fn_account(call_scope_t& args)
{
if (args[0].is_string())
diff --git a/src/session.h b/src/session.h
index d20ba74a..88146c1e 100644
--- a/src/session.h
+++ b/src/session.h
@@ -84,6 +84,8 @@ public:
journal_t * read_journal_files();
void close_journal_files();
+ journal_t * get_journal();
+
value_t fn_account(call_scope_t& scope);
value_t fn_min(call_scope_t& scope);
value_t fn_max(call_scope_t& scope);