summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2007-04-27 10:09:00 +0000
committerJohn Wiegley <johnw@newartisans.com>2008-04-13 03:38:32 -0400
commitd0e9822ed16cb36de4cb1171a89d4049c615f1a0 (patch)
treefa48eba60a56dee5bcf1ebd266d822c5a96e4323
parent0eb597a681115d6d5dd2ea4511fa3b8c7b3d9c9f (diff)
downloadfork-ledger-d0e9822ed16cb36de4cb1171a89d4049c615f1a0.tar.gz
fork-ledger-d0e9822ed16cb36de4cb1171a89d4049c615f1a0.tar.bz2
fork-ledger-d0e9822ed16cb36de4cb1171a89d4049c615f1a0.zip
Moved around the Python code.
-rw-r--r--Makefile.am1
-rw-r--r--Makefile.in36
-rw-r--r--balance.cc209
-rw-r--r--format.cc18
-rw-r--r--journal.cc381
-rw-r--r--main.cc4
-rw-r--r--option.cc80
-rw-r--r--py_balance.cc202
-rw-r--r--py_eval.cc6
-rw-r--r--py_eval.h4
-rw-r--r--py_format.cc11
-rw-r--r--py_journal.cc374
-rw-r--r--py_option.cc73
-rw-r--r--py_parser.cc (renamed from parser.cc)0
-rw-r--r--py_report.cc13
-rw-r--r--py_session.cc36
-rw-r--r--py_transform.cc8
-rw-r--r--py_value.cc337
-rw-r--r--py_xpath.cc79
-rw-r--r--pyledger.cc4
-rw-r--r--quotes.cc2
-rw-r--r--report.cc20
-rw-r--r--session.cc49
-rw-r--r--session.h2
-rw-r--r--tests/python/corelib/numerics/BasicAmount.py6
-rw-r--r--tests/python/corelib/numerics/CommodityAmount.py3
-rw-r--r--transform.cc15
-rw-r--r--utils.h4
-rw-r--r--value.cc344
-rw-r--r--xpath.cc86
30 files changed, 1164 insertions, 1243 deletions
diff --git a/Makefile.am b/Makefile.am
index 13ec77c2..18ce448f 100644
--- a/Makefile.am
+++ b/Makefile.am
@@ -44,7 +44,6 @@ libledger_la_SOURCES = \
\
session.cc \
journal.cc \
- parser.cc \
textual.cc \
binary.cc \
xmlparse.cc \
diff --git a/Makefile.in b/Makefile.in
index 31167ca4..68c1e35e 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -86,9 +86,9 @@ LTLIBRARIES = $(lib_LTLIBRARIES)
libledger_la_LIBADD =
am__libledger_la_SOURCES_DIST = utils.cc times.cc amount.cc quotes.cc \
balance.cc value.cc xml.cc xpath.cc mask.cc format.cc \
- session.cc journal.cc parser.cc textual.cc binary.cc \
- xmlparse.cc qif.cc report.cc transform.cc register.cc csv.cc \
- derive.cc emacs.cc reconcile.cc gnucash.cc ofx.cc
+ session.cc journal.cc textual.cc binary.cc xmlparse.cc qif.cc \
+ report.cc transform.cc register.cc csv.cc derive.cc emacs.cc \
+ reconcile.cc gnucash.cc ofx.cc
@HAVE_EXPAT_TRUE@am__objects_1 = libledger_la-gnucash.lo
@HAVE_XMLPARSE_TRUE@am__objects_2 = libledger_la-gnucash.lo
@HAVE_LIBOFX_TRUE@am__objects_3 = libledger_la-ofx.lo
@@ -97,14 +97,13 @@ am_libledger_la_OBJECTS = libledger_la-utils.lo libledger_la-times.lo \
libledger_la-balance.lo libledger_la-value.lo \
libledger_la-xml.lo libledger_la-xpath.lo libledger_la-mask.lo \
libledger_la-format.lo libledger_la-session.lo \
- libledger_la-journal.lo libledger_la-parser.lo \
- libledger_la-textual.lo libledger_la-binary.lo \
- libledger_la-xmlparse.lo libledger_la-qif.lo \
- libledger_la-report.lo libledger_la-transform.lo \
- libledger_la-register.lo libledger_la-csv.lo \
- libledger_la-derive.lo libledger_la-emacs.lo \
- libledger_la-reconcile.lo $(am__objects_1) $(am__objects_2) \
- $(am__objects_3)
+ libledger_la-journal.lo libledger_la-textual.lo \
+ libledger_la-binary.lo libledger_la-xmlparse.lo \
+ libledger_la-qif.lo libledger_la-report.lo \
+ libledger_la-transform.lo libledger_la-register.lo \
+ libledger_la-csv.lo libledger_la-derive.lo \
+ libledger_la-emacs.lo libledger_la-reconcile.lo \
+ $(am__objects_1) $(am__objects_2) $(am__objects_3)
nodist_libledger_la_OBJECTS =
libledger_la_OBJECTS = $(am_libledger_la_OBJECTS) \
$(nodist_libledger_la_OBJECTS)
@@ -356,10 +355,9 @@ libledger_la_CPPFLAGS = -I$(top_builddir)/gdtoa $(am__append_2) \
libledger_la_LDFLAGS = -release 3.0
libledger_la_SOURCES = utils.cc times.cc amount.cc quotes.cc \
balance.cc value.cc xml.cc xpath.cc mask.cc format.cc \
- session.cc journal.cc parser.cc textual.cc binary.cc \
- xmlparse.cc qif.cc report.cc transform.cc register.cc csv.cc \
- derive.cc emacs.cc reconcile.cc $(am__append_3) \
- $(am__append_5) $(am__append_7)
+ session.cc journal.cc textual.cc binary.cc xmlparse.cc qif.cc \
+ report.cc transform.cc register.cc csv.cc derive.cc emacs.cc \
+ reconcile.cc $(am__append_3) $(am__append_5) $(am__append_7)
@USE_PCH_TRUE@libledger_la_CXXFLAGS = $(WARNFLAGS)
@USE_PCH_TRUE@nodist_libledger_la_SOURCES = system.hh.gch
libpyledger_la_CPPFLAGS = $(libledger_la_CPPFLAGS)
@@ -598,7 +596,6 @@ distclean-compile:
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libledger_la-journal.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libledger_la-mask.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libledger_la-ofx.Plo@am__quote@
-@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libledger_la-parser.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libledger_la-qif.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libledger_la-quotes.Plo@am__quote@
@AMDEP_TRUE@@am__include@ @am__quote@./$(DEPDIR)/libledger_la-reconcile.Plo@am__quote@
@@ -722,13 +719,6 @@ libledger_la-journal.lo: journal.cc
@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libledger_la_CPPFLAGS) $(CPPFLAGS) $(libledger_la_CXXFLAGS) $(CXXFLAGS) -c -o libledger_la-journal.lo `test -f 'journal.cc' || echo '$(srcdir)/'`journal.cc
-libledger_la-parser.lo: parser.cc
-@am__fastdepCXX_TRUE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libledger_la_CPPFLAGS) $(CPPFLAGS) $(libledger_la_CXXFLAGS) $(CXXFLAGS) -MT libledger_la-parser.lo -MD -MP -MF $(DEPDIR)/libledger_la-parser.Tpo -c -o libledger_la-parser.lo `test -f 'parser.cc' || echo '$(srcdir)/'`parser.cc
-@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/libledger_la-parser.Tpo $(DEPDIR)/libledger_la-parser.Plo
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ source='parser.cc' object='libledger_la-parser.lo' libtool=yes @AMDEPBACKSLASH@
-@AMDEP_TRUE@@am__fastdepCXX_FALSE@ DEPDIR=$(DEPDIR) $(CXXDEPMODE) $(depcomp) @AMDEPBACKSLASH@
-@am__fastdepCXX_FALSE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libledger_la_CPPFLAGS) $(CPPFLAGS) $(libledger_la_CXXFLAGS) $(CXXFLAGS) -c -o libledger_la-parser.lo `test -f 'parser.cc' || echo '$(srcdir)/'`parser.cc
-
libledger_la-textual.lo: textual.cc
@am__fastdepCXX_TRUE@ $(LIBTOOL) --tag=CXX $(AM_LIBTOOLFLAGS) $(LIBTOOLFLAGS) --mode=compile $(CXX) $(DEFS) $(DEFAULT_INCLUDES) $(INCLUDES) $(libledger_la_CPPFLAGS) $(CPPFLAGS) $(libledger_la_CXXFLAGS) $(CXXFLAGS) -MT libledger_la-textual.lo -MD -MP -MF $(DEPDIR)/libledger_la-textual.Tpo -c -o libledger_la-textual.lo `test -f 'textual.cc' || echo '$(srcdir)/'`textual.cc
@am__fastdepCXX_TRUE@ mv -f $(DEPDIR)/libledger_la-textual.Tpo $(DEPDIR)/libledger_la-textual.Plo
diff --git a/balance.cc b/balance.cc
index 328e6382..487f749f 100644
--- a/balance.cc
+++ b/balance.cc
@@ -311,212 +311,3 @@ balance_t::operator amount_t() const
}
} // namespace ledger
-
-#if 0
-#ifdef USE_BOOST_PYTHON
-
-using namespace boost::python;
-using namespace ledger;
-
-unsigned int balance_len(balance_t& bal)
-{
- return bal.amounts.size();
-}
-
-amount_t balance_getitem(balance_t& bal, int i)
-{
- std::size_t len = bal.amounts.size();
-
- if (abs(i) >= len) {
- PyErr_SetString(PyExc_IndexError, "Index out of range");
- throw_error_already_set();
- }
-
- int x = i < 0 ? len + i : i;
- amounts_map::iterator elem = bal.amounts.begin();
- while (--x >= 0)
- elem++;
-
- return (*elem).second;
-}
-
-unsigned int balance_pair_len(balance_pair_t& bal_pair)
-{
- return balance_len(bal_pair.quantity);
-}
-
-amount_t balance_pair_getitem(balance_pair_t& bal_pair, int i)
-{
- return balance_getitem(bal_pair.quantity, i);
-}
-
-void export_balance()
-{
- class_< balance_t > ("Balance")
- .def(init<balance_t>())
- .def(init<amount_t>())
- .def(init<long>())
- .def(init<unsigned long>())
- .def(init<double>())
-
- .def(self += self)
- .def(self += other<amount_t>())
- .def(self += long())
- .def(self + self)
- .def(self + other<amount_t>())
- .def(self + long())
- .def(self -= self)
- .def(self -= other<amount_t>())
- .def(self -= long())
- .def(self - self)
- .def(self - other<amount_t>())
- .def(self - long())
- .def(self *= self)
- .def(self *= other<amount_t>())
- .def(self *= long())
- .def(self * self)
- .def(self * other<amount_t>())
- .def(self * long())
- .def(self /= self)
- .def(self /= other<amount_t>())
- .def(self /= long())
- .def(self / self)
- .def(self / other<amount_t>())
- .def(self / long())
- .def(- self)
-
- .def(self < self)
- .def(self < other<amount_t>())
- .def(self < long())
- .def(self <= self)
- .def(self <= other<amount_t>())
- .def(self <= long())
- .def(self > self)
- .def(self > other<amount_t>())
- .def(self > long())
- .def(self >= self)
- .def(self >= other<amount_t>())
- .def(self >= long())
- .def(self == self)
- .def(self == other<amount_t>())
- .def(self == long())
- .def(self != self)
- .def(self != other<amount_t>())
- .def(self != long())
- .def(! self)
-
- .def(self_ns::str(self))
-
- .def("__abs__", &balance_t::abs)
- .def("__len__", balance_len)
- .def("__getitem__", balance_getitem)
-
- .def("valid", &balance_t::valid)
-
- .def("realzero", &balance_t::realzero)
- .def("amount", &balance_t::amount)
- .def("value", &balance_t::value)
- .def("price", &balance_t::price)
- .def("date", &balance_t::date)
- .def("strip_annotations", &balance_t::strip_annotations)
- .def("write", &balance_t::write)
- .def("round", &balance_t::round)
- .def("negate", &balance_t::negate)
- .def("negated", &balance_t::negated)
- ;
-
- class_< balance_pair_t > ("BalancePair")
- .def(init<balance_pair_t>())
- .def(init<balance_t>())
- .def(init<amount_t>())
- .def(init<long>())
- .def(init<unsigned long>())
- .def(init<double>())
-
- .def(self += self)
- .def(self += other<balance_t>())
- .def(self += other<amount_t>())
- .def(self += long())
- .def(self + self)
- .def(self + other<balance_t>())
- .def(self + other<amount_t>())
- .def(self + long())
- .def(self -= self)
- .def(self -= other<balance_t>())
- .def(self -= other<amount_t>())
- .def(self -= long())
- .def(self - self)
- .def(self - other<balance_t>())
- .def(self - other<amount_t>())
- .def(self - long())
- .def(self *= self)
- .def(self *= other<balance_t>())
- .def(self *= other<amount_t>())
- .def(self *= long())
- .def(self * self)
- .def(self * other<balance_t>())
- .def(self * other<amount_t>())
- .def(self * long())
- .def(self /= self)
- .def(self /= other<balance_t>())
- .def(self /= other<amount_t>())
- .def(self /= long())
- .def(self / self)
- .def(self / other<balance_t>())
- .def(self / other<amount_t>())
- .def(self / long())
- .def(- self)
-
- .def(self < self)
- .def(self < other<balance_t>())
- .def(self < other<amount_t>())
- .def(self < long())
- .def(self <= self)
- .def(self <= other<balance_t>())
- .def(self <= other<amount_t>())
- .def(self <= long())
- .def(self > self)
- .def(self > other<balance_t>())
- .def(self > other<amount_t>())
- .def(self > long())
- .def(self >= self)
- .def(self >= other<balance_t>())
- .def(self >= other<amount_t>())
- .def(self >= long())
- .def(self == self)
- .def(self == other<balance_t>())
- .def(self == other<amount_t>())
- .def(self == long())
- .def(self != self)
- .def(self != other<balance_t>())
- .def(self != other<amount_t>())
- .def(self != long())
- .def(! self)
-
- .def(self_ns::str(self))
-
- .def("__abs__", &balance_pair_t::abs)
- .def("__len__", balance_pair_len)
- .def("__getitem__", balance_pair_getitem)
-
- .def("valid", &balance_pair_t::valid)
-
- .def("realzero", &balance_pair_t::realzero)
- .def("amount", &balance_pair_t::amount)
- .def("value", &balance_pair_t::value)
- .def("price", &balance_pair_t::price)
- .def("date", &balance_pair_t::date)
- .def("strip_annotations", &balance_pair_t::strip_annotations)
- .def("write", &balance_pair_t::write)
- .def("round", &balance_pair_t::round)
- .def("negate", &balance_pair_t::negate)
- .def("negated", &balance_pair_t::negated)
-
- .add_property("cost",
- make_getter(&balance_pair_t::cost,
- return_value_policy<reference_existing_object>()))
- ;
-}
-
-#endif // USE_BOOST_PYTHON
-#endif
diff --git a/format.cc b/format.cc
index 1b4be467..6a378823 100644
--- a/format.cc
+++ b/format.cc
@@ -237,21 +237,3 @@ int format_t::format(std::ostream& out, xml::node_t * context,
}
} // namespace ledger
-
-#if 0
-#ifdef USE_BOOST_PYTHON
-
-using namespace boost::python;
-using namespace ledger;
-
-void export_format()
-{
- class_< format_t > ("Format")
- .def(init<string>())
- .def("parse", &format_t::parse)
- .def("format", &format_t::format)
- ;
-}
-
-#endif // USE_BOOST_PYTHON
-#endif
diff --git a/journal.cc b/journal.cc
index 1867899f..1ae4be80 100644
--- a/journal.cc
+++ b/journal.cc
@@ -665,384 +665,3 @@ xact_context::xact_context(const ledger::transaction_t& _xact,
#endif
} // namespace ledger
-
-#if 0
-#ifdef USE_BOOST_PYTHON
-
-using namespace boost::python;
-using namespace ledger;
-
-entry_t& transaction_entry(const transaction_t& xact)
-{
- return *xact.entry;
-}
-
-unsigned int transactions_len(entry_base_t& entry)
-{
- return entry.transactions.size();
-}
-
-transaction_t& transactions_getitem(entry_base_t& entry, int i)
-{
- static int last_index = 0;
- static entry_base_t * last_entry = NULL;
- static transactions_list::iterator elem;
-
- std::size_t len = entry.transactions.size();
-
- if (abs(i) >= len) {
- PyErr_SetString(PyExc_IndexError, "Index out of range");
- throw_error_already_set();
- }
-
- if (&entry == last_entry && i == last_index + 1) {
- last_index = i;
- return **++elem;
- }
-
- int x = i < 0 ? len + i : i;
- elem = entry.transactions.begin();
- while (--x >= 0)
- elem++;
-
- last_entry = &entry;
- last_index = i;
-
- return **elem;
-}
-
-unsigned int entries_len(journal_t& journal)
-{
- return journal.entries.size();
-}
-
-entry_t& entries_getitem(journal_t& journal, int i)
-{
- static int last_index = 0;
- static journal_t * last_journal = NULL;
- static entries_list::iterator elem;
-
- std::size_t len = journal.entries.size();
-
- if (abs(i) >= len) {
- PyErr_SetString(PyExc_IndexError, "Index out of range");
- throw_error_already_set();
- }
-
- if (&journal == last_journal && i == last_index + 1) {
- last_index = i;
- return **++elem;
- }
-
- int x = i < 0 ? len + i : i;
- elem = journal.entries.begin();
- while (--x >= 0)
- elem++;
-
- last_journal = &journal;
- last_index = i;
-
- return **elem;
-}
-
-unsigned int accounts_len(account_t& account)
-{
- return account.accounts.size();
-}
-
-account_t& accounts_getitem(account_t& account, int i)
-{
- static int last_index = 0;
- static account_t * last_account = NULL;
- static accounts_map::iterator elem;
-
- std::size_t len = account.accounts.size();
-
- if (abs(i) >= len) {
- PyErr_SetString(PyExc_IndexError, "Index out of range");
- throw_error_already_set();
- }
-
- if (&account == last_account && i == last_index + 1) {
- last_index = i;
- return *(*++elem).second;
- }
-
- int x = i < 0 ? len + i : i;
- elem = account.accounts.begin();
- while (--x >= 0)
- elem++;
-
- last_account = &account;
- last_index = i;
-
- return *(*elem).second;
-}
-
-PyObject * py_account_get_data(account_t& account)
-{
- return (PyObject *) account.data;
-}
-
-void py_account_set_data(account_t& account, PyObject * obj)
-{
- account.data = obj;
-}
-
-account_t * py_find_account_1(journal_t& journal, const string& name)
-{
- return journal.find_account(name);
-}
-
-account_t * py_find_account_2(journal_t& journal, const string& name,
- const bool auto_create)
-{
- return journal.find_account(name, auto_create);
-}
-
-bool py_add_entry(journal_t& journal, entry_t * entry) {
- return journal.add_entry(new entry_t(*entry));
-}
-
-void py_add_transaction(entry_base_t& entry, transaction_t * xact) {
- return entry.add_transaction(new transaction_t(*xact));
-}
-
-struct entry_base_wrap : public entry_base_t
-{
- PyObject * self;
- entry_base_wrap(PyObject * self_) : self(self_) {}
-
- virtual bool valid() const {
- return call_method<bool>(self, "valid");
- }
-};
-
-struct py_entry_finalizer_t : public entry_finalizer_t {
- object pyobj;
- py_entry_finalizer_t() {}
- py_entry_finalizer_t(object obj) : pyobj(obj) {}
- py_entry_finalizer_t(const py_entry_finalizer_t& other)
- : pyobj(other.pyobj) {}
- virtual bool operator()(entry_t& entry, bool post) {
- return call<bool>(pyobj.ptr(), entry, post);
- }
-};
-
-std::list<py_entry_finalizer_t> py_finalizers;
-
-void py_add_entry_finalizer(journal_t& journal, object x)
-{
- py_finalizers.push_back(py_entry_finalizer_t(x));
- journal.add_entry_finalizer(&py_finalizers.back());
-}
-
-void py_remove_entry_finalizer(journal_t& journal, object x)
-{
- for (std::list<py_entry_finalizer_t>::iterator i = py_finalizers.begin();
- i != py_finalizers.end();
- i++)
- if ((*i).pyobj == x) {
- journal.remove_entry_finalizer(&(*i));
- py_finalizers.erase(i);
- return;
- }
-}
-
-void py_run_entry_finalizers(journal_t& journal, entry_t& entry, bool post)
-{
- run_hooks(journal.entry_finalize_hooks, entry, post);
-}
-
-#define EXC_TRANSLATOR(type) \
- void exc_translate_ ## type(const type& err) { \
- PyErr_SetString(PyExc_RuntimeError, err.what()); \
- }
-
-EXC_TRANSLATOR(balance_error)
-EXC_TRANSLATOR(interval_expr_error)
-EXC_TRANSLATOR(format_error)
-EXC_TRANSLATOR(parse_error)
-
-value_t py_transaction_amount(transaction_t * xact) {
- return value_t(xact->amount);
-}
-
-transaction_t::state_t py_entry_state(entry_t * entry) {
- transaction_t::state_t state;
- if (entry->get_state(&state))
- return state;
- else
- return transaction_t::UNCLEARED;
-}
-
-void export_journal()
-{
- scope().attr("TRANSACTION_NORMAL") = TRANSACTION_NORMAL;
- scope().attr("TRANSACTION_VIRTUAL") = TRANSACTION_VIRTUAL;
- scope().attr("TRANSACTION_BALANCE") = TRANSACTION_BALANCE;
- scope().attr("TRANSACTION_AUTO") = TRANSACTION_AUTO;
- scope().attr("TRANSACTION_BULK_ALLOC") = TRANSACTION_BULK_ALLOC;
- scope().attr("TRANSACTION_CALCULATED") = TRANSACTION_CALCULATED;
-
- enum_< transaction_t::state_t > ("State")
- .value("Uncleared", transaction_t::UNCLEARED)
- .value("Cleared", transaction_t::CLEARED)
- .value("Pending", transaction_t::PENDING)
- ;
-
- class_< transaction_t > ("Transaction")
- .def(init<optional<account_t *> >())
- .def(init<account_t *, amount_t, optional<unsigned int, const string&> >())
-
- .def(self == self)
- .def(self != self)
-
- .add_property("entry",
- make_getter(&transaction_t::entry,
- return_value_policy<reference_existing_object>()))
- .add_property("account",
- make_getter(&transaction_t::account,
- return_value_policy<reference_existing_object>()))
-
- .add_property("amount", &py_transaction_amount)
- .def_readonly("amount_expr", &transaction_t::amount_expr)
- .add_property("cost",
- make_getter(&transaction_t::cost,
- return_internal_reference<1>()))
- .def_readonly("cost_expr", &transaction_t::cost_expr)
-
- .def_readwrite("state", &transaction_t::state)
- .def_readwrite("flags", &transaction_t::flags)
- .def_readwrite("note", &transaction_t::note)
-
- .def_readonly("beg_pos", &transaction_t::beg_pos)
- .def_readonly("beg_line", &transaction_t::beg_line)
- .def_readonly("end_pos", &transaction_t::end_pos)
- .def_readonly("end_line", &transaction_t::end_line)
-
- .def("actual_date", &transaction_t::actual_date)
- .def("effective_date", &transaction_t::effective_date)
- .def("date", &transaction_t::date)
-
- .def("use_effective_date", &transaction_t::use_effective_date)
-
- .def("valid", &transaction_t::valid)
- ;
-
- class_< account_t >
- ("Account",
- init<optional<account_t *, string, string> >()
- [with_custodian_and_ward<1, 2>()])
- .def(self == self)
- .def(self != self)
-
- .def(self_ns::str(self))
-
- .def("__len__", accounts_len)
- .def("__getitem__", accounts_getitem, return_internal_reference<1>())
-
- .add_property("journal",
- make_getter(&account_t::journal,
- return_value_policy<reference_existing_object>()))
- .add_property("parent",
- make_getter(&account_t::parent,
- return_value_policy<reference_existing_object>()))
- .def_readwrite("name", &account_t::name)
- .def_readwrite("note", &account_t::note)
- .def_readonly("depth", &account_t::depth)
- .add_property("data", py_account_get_data, py_account_set_data)
- .def_readonly("ident", &account_t::ident)
-
- .def("fullname", &account_t::fullname)
-
- .def("add_account", &account_t::add_account)
- .def("remove_account", &account_t::remove_account)
-
- .def("find_account", &account_t::find_account,
- return_value_policy<reference_existing_object>())
-
- .def("valid", &account_t::valid)
- ;
-
- class_< journal_t > ("Journal")
- .def(self == self)
- .def(self != self)
-
- .def("__len__", entries_len)
- .def("__getitem__", entries_getitem, return_internal_reference<1>())
-
- .add_property("master", make_getter(&journal_t::master,
- return_internal_reference<1>()))
- .add_property("basket", make_getter(&journal_t::basket,
- return_internal_reference<1>()))
-
- .def_readonly("sources", &journal_t::sources)
-
- .def_readwrite("price_db", &journal_t::price_db)
-
- .def("add_account", &journal_t::add_account)
- .def("remove_account", &journal_t::remove_account)
-
- .def("find_account", py_find_account_1, return_internal_reference<1>())
- .def("find_account", py_find_account_2, return_internal_reference<1>())
- .def("find_account_re", &journal_t::find_account_re,
- return_internal_reference<1>())
-
- .def("add_entry", py_add_entry)
- .def("remove_entry", &journal_t::remove_entry)
-
- .def("add_entry_finalizer", py_add_entry_finalizer)
- .def("remove_entry_finalizer", py_remove_entry_finalizer)
- .def("run_entry_finalizers", py_run_entry_finalizers)
-
- .def("valid", &journal_t::valid)
- ;
-
- class_< entry_base_t, entry_base_wrap, boost::noncopyable > ("EntryBase")
- .def("__len__", transactions_len)
- .def("__getitem__", transactions_getitem,
- return_internal_reference<1>())
-
- .def_readonly("journal", &entry_base_t::journal)
-
- .def_readonly("src_idx", &entry_base_t::src_idx)
- .def_readonly("beg_pos", &entry_base_t::beg_pos)
- .def_readonly("beg_line", &entry_base_t::beg_line)
- .def_readonly("end_pos", &entry_base_t::end_pos)
- .def_readonly("end_line", &entry_base_t::end_line)
-
- .def("add_transaction", py_add_transaction)
- .def("remove_transaction", &entry_base_t::remove_transaction)
-
- .def(self == self)
- .def(self != self)
-
- .def("finalize", &entry_base_t::finalize)
- .def("valid", &entry_base_t::valid)
- ;
-
- class_< entry_t, bases<entry_base_t> > ("Entry")
- .add_property("date", &entry_t::date)
- .add_property("effective_date", &entry_t::effective_date)
- .add_property("actual_date", &entry_t::actual_date)
-
- .def_readwrite("code", &entry_t::code)
- .def_readwrite("payee", &entry_t::payee)
-
- .add_property("state", &py_entry_state)
-
- .def("valid", &entry_t::valid)
- ;
-
-#define EXC_TRANSLATE(type) \
- register_exception_translator<type>(&exc_translate_ ## type);
-
- EXC_TRANSLATE(balance_error);
- EXC_TRANSLATE(interval_expr_error);
- EXC_TRANSLATE(format_error);
- EXC_TRANSLATE(parse_error);
-}
-
-#endif // USE_BOOST_PYTHON
-#endif
diff --git a/main.cc b/main.cc
index 49a93586..2961953e 100644
--- a/main.cc
+++ b/main.cc
@@ -347,10 +347,6 @@ static int read_and_report(report_t * report, int argc, char * argv[],
TRACE_START(cleanup, 1, "Cleaning up allocated memory");
-#ifdef USE_BOOST_PYTHON
- shutdown_ledger_for_python();
-#endif
-
if (! report->output_file.empty())
delete out;
diff --git a/option.cc b/option.cc
index b8657cd5..f5b80016 100644
--- a/option.cc
+++ b/option.cc
@@ -222,83 +222,3 @@ void process_arguments(int argc, char ** argv, const bool anywhere,
}
} // namespace ledger
-
-#if 0
-#ifdef USE_BOOST_PYTHON
-
-using namespace boost::python;
-using namespace ledger;
-
-struct py_option_t : public option_t
-{
- PyObject * self;
-
- py_option_t(PyObject * self_,
- const string& long_opt,
- const bool wants_arg)
- : self(self_), option_t(long_opt, wants_arg) {}
-
- virtual ~py_option_t() {}
-
- virtual bool check(option_source_t source) {
- return call_method<bool>(self, "check", source);
- }
-
- virtual void select(report_t * report, const char * optarg = NULL) {
- if (optarg)
- return call_method<void>(self, "select", report, optarg);
- else
- return call_method<void>(self, "select", report);
- }
-};
-
-BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(option_select_overloads,
- py_option_t::select, 1, 2)
-
-typedef std::map<const string, object> options_map;
-typedef std::pair<const string, object> options_pair;
-
-options_map options;
-
-static option_t * find_option(const string& name)
-{
- options_map::const_iterator i = options.find(name);
- if (i != options.end())
- return extract<py_option_t *>((*i).second.ptr());
-
- return NULL;
-}
-
-void shutdown_option()
-{
- options.clear();
-}
-
-void export_option()
-{
- class_< option_t, py_option_t, boost::noncopyable >
- ("Option", init<const string&, bool>())
- .def_readonly("long_opt", &py_option_t::long_opt)
- .def_readonly("short_opt", &py_option_t::short_opt)
- .def_readonly("wants_arg", &py_option_t::wants_arg)
- .def_readwrite("handled", &py_option_t::handled)
- .def("check", &py_option_t::check)
- .def("select", &py_option_t::select, option_select_overloads())
- ;
-
- enum_< option_t::option_source_t > ("OptionSource")
- .value("InitFile", option_t::INIT_FILE)
- .value("Environment", option_t::ENVIRONMENT)
- .value("DataFile", option_t::DATA_FILE)
- .value("CommandLine", option_t::COMMAND_LINE)
- ;
-
- class_< options_map > ("OptionsMap")
- .def(map_indexing_suite<options_map>())
- ;
-
- scope().attr("options") = ptr(&options);
-}
-
-#endif // USE_BOOST_PYTHON
-#endif
diff --git a/py_balance.cc b/py_balance.cc
new file mode 100644
index 00000000..372bf1e9
--- /dev/null
+++ b/py_balance.cc
@@ -0,0 +1,202 @@
+using namespace boost::python;
+using namespace ledger;
+
+unsigned int balance_len(balance_t& bal)
+{
+ return bal.amounts.size();
+}
+
+amount_t balance_getitem(balance_t& bal, int i)
+{
+ std::size_t len = bal.amounts.size();
+
+ if (abs(i) >= len) {
+ PyErr_SetString(PyExc_IndexError, "Index out of range");
+ throw_error_already_set();
+ }
+
+ int x = i < 0 ? len + i : i;
+ amounts_map::iterator elem = bal.amounts.begin();
+ while (--x >= 0)
+ elem++;
+
+ return (*elem).second;
+}
+
+unsigned int balance_pair_len(balance_pair_t& bal_pair)
+{
+ return balance_len(bal_pair.quantity);
+}
+
+amount_t balance_pair_getitem(balance_pair_t& bal_pair, int i)
+{
+ return balance_getitem(bal_pair.quantity, i);
+}
+
+void export_balance()
+{
+ class_< balance_t > ("Balance")
+ .def(init<balance_t>())
+ .def(init<amount_t>())
+ .def(init<long>())
+ .def(init<unsigned long>())
+ .def(init<double>())
+
+ .def(self += self)
+ .def(self += other<amount_t>())
+ .def(self += long())
+ .def(self + self)
+ .def(self + other<amount_t>())
+ .def(self + long())
+ .def(self -= self)
+ .def(self -= other<amount_t>())
+ .def(self -= long())
+ .def(self - self)
+ .def(self - other<amount_t>())
+ .def(self - long())
+ .def(self *= self)
+ .def(self *= other<amount_t>())
+ .def(self *= long())
+ .def(self * self)
+ .def(self * other<amount_t>())
+ .def(self * long())
+ .def(self /= self)
+ .def(self /= other<amount_t>())
+ .def(self /= long())
+ .def(self / self)
+ .def(self / other<amount_t>())
+ .def(self / long())
+ .def(- self)
+
+ .def(self < self)
+ .def(self < other<amount_t>())
+ .def(self < long())
+ .def(self <= self)
+ .def(self <= other<amount_t>())
+ .def(self <= long())
+ .def(self > self)
+ .def(self > other<amount_t>())
+ .def(self > long())
+ .def(self >= self)
+ .def(self >= other<amount_t>())
+ .def(self >= long())
+ .def(self == self)
+ .def(self == other<amount_t>())
+ .def(self == long())
+ .def(self != self)
+ .def(self != other<amount_t>())
+ .def(self != long())
+ .def(! self)
+
+ .def(self_ns::str(self))
+
+ .def("__abs__", &balance_t::abs)
+ .def("__len__", balance_len)
+ .def("__getitem__", balance_getitem)
+
+ .def("valid", &balance_t::valid)
+
+ .def("realzero", &balance_t::realzero)
+ .def("amount", &balance_t::amount)
+ .def("value", &balance_t::value)
+ .def("price", &balance_t::price)
+ .def("date", &balance_t::date)
+ .def("strip_annotations", &balance_t::strip_annotations)
+ .def("write", &balance_t::write)
+ .def("round", &balance_t::round)
+ .def("negate", &balance_t::negate)
+ .def("negated", &balance_t::negated)
+ ;
+
+ class_< balance_pair_t > ("BalancePair")
+ .def(init<balance_pair_t>())
+ .def(init<balance_t>())
+ .def(init<amount_t>())
+ .def(init<long>())
+ .def(init<unsigned long>())
+ .def(init<double>())
+
+ .def(self += self)
+ .def(self += other<balance_t>())
+ .def(self += other<amount_t>())
+ .def(self += long())
+ .def(self + self)
+ .def(self + other<balance_t>())
+ .def(self + other<amount_t>())
+ .def(self + long())
+ .def(self -= self)
+ .def(self -= other<balance_t>())
+ .def(self -= other<amount_t>())
+ .def(self -= long())
+ .def(self - self)
+ .def(self - other<balance_t>())
+ .def(self - other<amount_t>())
+ .def(self - long())
+ .def(self *= self)
+ .def(self *= other<balance_t>())
+ .def(self *= other<amount_t>())
+ .def(self *= long())
+ .def(self * self)
+ .def(self * other<balance_t>())
+ .def(self * other<amount_t>())
+ .def(self * long())
+ .def(self /= self)
+ .def(self /= other<balance_t>())
+ .def(self /= other<amount_t>())
+ .def(self /= long())
+ .def(self / self)
+ .def(self / other<balance_t>())
+ .def(self / other<amount_t>())
+ .def(self / long())
+ .def(- self)
+
+ .def(self < self)
+ .def(self < other<balance_t>())
+ .def(self < other<amount_t>())
+ .def(self < long())
+ .def(self <= self)
+ .def(self <= other<balance_t>())
+ .def(self <= other<amount_t>())
+ .def(self <= long())
+ .def(self > self)
+ .def(self > other<balance_t>())
+ .def(self > other<amount_t>())
+ .def(self > long())
+ .def(self >= self)
+ .def(self >= other<balance_t>())
+ .def(self >= other<amount_t>())
+ .def(self >= long())
+ .def(self == self)
+ .def(self == other<balance_t>())
+ .def(self == other<amount_t>())
+ .def(self == long())
+ .def(self != self)
+ .def(self != other<balance_t>())
+ .def(self != other<amount_t>())
+ .def(self != long())
+ .def(! self)
+
+ .def(self_ns::str(self))
+
+ .def("__abs__", &balance_pair_t::abs)
+ .def("__len__", balance_pair_len)
+ .def("__getitem__", balance_pair_getitem)
+
+ .def("valid", &balance_pair_t::valid)
+
+ .def("realzero", &balance_pair_t::realzero)
+ .def("amount", &balance_pair_t::amount)
+ .def("value", &balance_pair_t::value)
+ .def("price", &balance_pair_t::price)
+ .def("date", &balance_pair_t::date)
+ .def("strip_annotations", &balance_pair_t::strip_annotations)
+ .def("write", &balance_pair_t::write)
+ .def("round", &balance_pair_t::round)
+ .def("negate", &balance_pair_t::negate)
+ .def("negated", &balance_pair_t::negated)
+
+ .add_property("cost",
+ make_getter(&balance_pair_t::cost,
+ return_value_policy<reference_existing_object>()))
+ ;
+}
diff --git a/py_eval.cc b/py_eval.cc
index 6113b693..d66f6188 100644
--- a/py_eval.cc
+++ b/py_eval.cc
@@ -18,7 +18,7 @@ void shutdown_option();
namespace ledger {
-void initialize_ledger_for_python()
+void initialize_for_python()
{
export_amount();
#if 0
@@ -35,7 +35,7 @@ void initialize_ledger_for_python()
#endif
}
-void shutdown_ledger_for_python()
+void shutdown_for_python()
{
#if 0
shutdown_option();
@@ -61,7 +61,7 @@ python_interpreter_t::python_interpreter_t(xml::xpath_t::scope_t * parent)
nspace(handle<>(borrowed(PyModule_GetDict(mmodule.get()))))
{
Py_Initialize();
- detail::init_module("ledger", &initialize_ledger_for_python);
+ detail::init_module("ledger", &initialize_for_python);
}
object python_interpreter_t::import(const string& str)
diff --git a/py_eval.h b/py_eval.h
index e024108e..4712fe23 100644
--- a/py_eval.h
+++ b/py_eval.h
@@ -16,8 +16,8 @@ using namespace boost::python;
namespace ledger {
-void initialize_ledger_for_python();
-void shutdown_ledger_for_python();
+void initialize_for_python();
+void shutdown_for_python();
class python_interpreter_t : public xml::xpath_t::scope_t
{
diff --git a/py_format.cc b/py_format.cc
new file mode 100644
index 00000000..e2faf5dc
--- /dev/null
+++ b/py_format.cc
@@ -0,0 +1,11 @@
+using namespace boost::python;
+using namespace ledger;
+
+void export_format()
+{
+ class_< format_t > ("Format")
+ .def(init<string>())
+ .def("parse", &format_t::parse)
+ .def("format", &format_t::format)
+ ;
+}
diff --git a/py_journal.cc b/py_journal.cc
new file mode 100644
index 00000000..d309cf95
--- /dev/null
+++ b/py_journal.cc
@@ -0,0 +1,374 @@
+using namespace boost::python;
+using namespace ledger;
+
+entry_t& transaction_entry(const transaction_t& xact)
+{
+ return *xact.entry;
+}
+
+unsigned int transactions_len(entry_base_t& entry)
+{
+ return entry.transactions.size();
+}
+
+transaction_t& transactions_getitem(entry_base_t& entry, int i)
+{
+ static int last_index = 0;
+ static entry_base_t * last_entry = NULL;
+ static transactions_list::iterator elem;
+
+ std::size_t len = entry.transactions.size();
+
+ if (abs(i) >= len) {
+ PyErr_SetString(PyExc_IndexError, "Index out of range");
+ throw_error_already_set();
+ }
+
+ if (&entry == last_entry && i == last_index + 1) {
+ last_index = i;
+ return **++elem;
+ }
+
+ int x = i < 0 ? len + i : i;
+ elem = entry.transactions.begin();
+ while (--x >= 0)
+ elem++;
+
+ last_entry = &entry;
+ last_index = i;
+
+ return **elem;
+}
+
+unsigned int entries_len(journal_t& journal)
+{
+ return journal.entries.size();
+}
+
+entry_t& entries_getitem(journal_t& journal, int i)
+{
+ static int last_index = 0;
+ static journal_t * last_journal = NULL;
+ static entries_list::iterator elem;
+
+ std::size_t len = journal.entries.size();
+
+ if (abs(i) >= len) {
+ PyErr_SetString(PyExc_IndexError, "Index out of range");
+ throw_error_already_set();
+ }
+
+ if (&journal == last_journal && i == last_index + 1) {
+ last_index = i;
+ return **++elem;
+ }
+
+ int x = i < 0 ? len + i : i;
+ elem = journal.entries.begin();
+ while (--x >= 0)
+ elem++;
+
+ last_journal = &journal;
+ last_index = i;
+
+ return **elem;
+}
+
+unsigned int accounts_len(account_t& account)
+{
+ return account.accounts.size();
+}
+
+account_t& accounts_getitem(account_t& account, int i)
+{
+ static int last_index = 0;
+ static account_t * last_account = NULL;
+ static accounts_map::iterator elem;
+
+ std::size_t len = account.accounts.size();
+
+ if (abs(i) >= len) {
+ PyErr_SetString(PyExc_IndexError, "Index out of range");
+ throw_error_already_set();
+ }
+
+ if (&account == last_account && i == last_index + 1) {
+ last_index = i;
+ return *(*++elem).second;
+ }
+
+ int x = i < 0 ? len + i : i;
+ elem = account.accounts.begin();
+ while (--x >= 0)
+ elem++;
+
+ last_account = &account;
+ last_index = i;
+
+ return *(*elem).second;
+}
+
+PyObject * py_account_get_data(account_t& account)
+{
+ return (PyObject *) account.data;
+}
+
+void py_account_set_data(account_t& account, PyObject * obj)
+{
+ account.data = obj;
+}
+
+account_t * py_find_account_1(journal_t& journal, const string& name)
+{
+ return journal.find_account(name);
+}
+
+account_t * py_find_account_2(journal_t& journal, const string& name,
+ const bool auto_create)
+{
+ return journal.find_account(name, auto_create);
+}
+
+bool py_add_entry(journal_t& journal, entry_t * entry) {
+ return journal.add_entry(new entry_t(*entry));
+}
+
+void py_add_transaction(entry_base_t& entry, transaction_t * xact) {
+ return entry.add_transaction(new transaction_t(*xact));
+}
+
+struct entry_base_wrap : public entry_base_t
+{
+ PyObject * self;
+ entry_base_wrap(PyObject * self_) : self(self_) {}
+
+ virtual bool valid() const {
+ return call_method<bool>(self, "valid");
+ }
+};
+
+struct py_entry_finalizer_t : public entry_finalizer_t {
+ object pyobj;
+ py_entry_finalizer_t() {}
+ py_entry_finalizer_t(object obj) : pyobj(obj) {}
+ py_entry_finalizer_t(const py_entry_finalizer_t& other)
+ : pyobj(other.pyobj) {}
+ virtual bool operator()(entry_t& entry, bool post) {
+ return call<bool>(pyobj.ptr(), entry, post);
+ }
+};
+
+std::list<py_entry_finalizer_t> py_finalizers;
+
+void py_add_entry_finalizer(journal_t& journal, object x)
+{
+ py_finalizers.push_back(py_entry_finalizer_t(x));
+ journal.add_entry_finalizer(&py_finalizers.back());
+}
+
+void py_remove_entry_finalizer(journal_t& journal, object x)
+{
+ for (std::list<py_entry_finalizer_t>::iterator i = py_finalizers.begin();
+ i != py_finalizers.end();
+ i++)
+ if ((*i).pyobj == x) {
+ journal.remove_entry_finalizer(&(*i));
+ py_finalizers.erase(i);
+ return;
+ }
+}
+
+void py_run_entry_finalizers(journal_t& journal, entry_t& entry, bool post)
+{
+ run_hooks(journal.entry_finalize_hooks, entry, post);
+}
+
+#define EXC_TRANSLATOR(type) \
+ void exc_translate_ ## type(const type& err) { \
+ PyErr_SetString(PyExc_RuntimeError, err.what()); \
+ }
+
+EXC_TRANSLATOR(balance_error)
+EXC_TRANSLATOR(interval_expr_error)
+EXC_TRANSLATOR(format_error)
+EXC_TRANSLATOR(parse_error)
+
+value_t py_transaction_amount(transaction_t * xact) {
+ return value_t(xact->amount);
+}
+
+transaction_t::state_t py_entry_state(entry_t * entry) {
+ transaction_t::state_t state;
+ if (entry->get_state(&state))
+ return state;
+ else
+ return transaction_t::UNCLEARED;
+}
+
+void export_journal()
+{
+ scope().attr("TRANSACTION_NORMAL") = TRANSACTION_NORMAL;
+ scope().attr("TRANSACTION_VIRTUAL") = TRANSACTION_VIRTUAL;
+ scope().attr("TRANSACTION_BALANCE") = TRANSACTION_BALANCE;
+ scope().attr("TRANSACTION_AUTO") = TRANSACTION_AUTO;
+ scope().attr("TRANSACTION_BULK_ALLOC") = TRANSACTION_BULK_ALLOC;
+ scope().attr("TRANSACTION_CALCULATED") = TRANSACTION_CALCULATED;
+
+ enum_< transaction_t::state_t > ("State")
+ .value("Uncleared", transaction_t::UNCLEARED)
+ .value("Cleared", transaction_t::CLEARED)
+ .value("Pending", transaction_t::PENDING)
+ ;
+
+ class_< transaction_t > ("Transaction")
+ .def(init<optional<account_t *> >())
+ .def(init<account_t *, amount_t, optional<unsigned int, const string&> >())
+
+ .def(self == self)
+ .def(self != self)
+
+ .add_property("entry",
+ make_getter(&transaction_t::entry,
+ return_value_policy<reference_existing_object>()))
+ .add_property("account",
+ make_getter(&transaction_t::account,
+ return_value_policy<reference_existing_object>()))
+
+ .add_property("amount", &py_transaction_amount)
+ .def_readonly("amount_expr", &transaction_t::amount_expr)
+ .add_property("cost",
+ make_getter(&transaction_t::cost,
+ return_internal_reference<1>()))
+ .def_readonly("cost_expr", &transaction_t::cost_expr)
+
+ .def_readwrite("state", &transaction_t::state)
+ .def_readwrite("flags", &transaction_t::flags)
+ .def_readwrite("note", &transaction_t::note)
+
+ .def_readonly("beg_pos", &transaction_t::beg_pos)
+ .def_readonly("beg_line", &transaction_t::beg_line)
+ .def_readonly("end_pos", &transaction_t::end_pos)
+ .def_readonly("end_line", &transaction_t::end_line)
+
+ .def("actual_date", &transaction_t::actual_date)
+ .def("effective_date", &transaction_t::effective_date)
+ .def("date", &transaction_t::date)
+
+ .def("use_effective_date", &transaction_t::use_effective_date)
+
+ .def("valid", &transaction_t::valid)
+ ;
+
+ class_< account_t >
+ ("Account",
+ init<optional<account_t *, string, string> >()
+ [with_custodian_and_ward<1, 2>()])
+ .def(self == self)
+ .def(self != self)
+
+ .def(self_ns::str(self))
+
+ .def("__len__", accounts_len)
+ .def("__getitem__", accounts_getitem, return_internal_reference<1>())
+
+ .add_property("journal",
+ make_getter(&account_t::journal,
+ return_value_policy<reference_existing_object>()))
+ .add_property("parent",
+ make_getter(&account_t::parent,
+ return_value_policy<reference_existing_object>()))
+ .def_readwrite("name", &account_t::name)
+ .def_readwrite("note", &account_t::note)
+ .def_readonly("depth", &account_t::depth)
+ .add_property("data", py_account_get_data, py_account_set_data)
+ .def_readonly("ident", &account_t::ident)
+
+ .def("fullname", &account_t::fullname)
+
+ .def("add_account", &account_t::add_account)
+ .def("remove_account", &account_t::remove_account)
+
+ .def("find_account", &account_t::find_account,
+ return_value_policy<reference_existing_object>())
+
+ .def("valid", &account_t::valid)
+ ;
+
+ class_< journal_t > ("Journal")
+ .def(self == self)
+ .def(self != self)
+
+ .def("__len__", entries_len)
+ .def("__getitem__", entries_getitem, return_internal_reference<1>())
+
+ .add_property("master", make_getter(&journal_t::master,
+ return_internal_reference<1>()))
+ .add_property("basket", make_getter(&journal_t::basket,
+ return_internal_reference<1>()))
+
+ .def_readonly("sources", &journal_t::sources)
+
+ .def_readwrite("price_db", &journal_t::price_db)
+
+ .def("add_account", &journal_t::add_account)
+ .def("remove_account", &journal_t::remove_account)
+
+ .def("find_account", py_find_account_1, return_internal_reference<1>())
+ .def("find_account", py_find_account_2, return_internal_reference<1>())
+ .def("find_account_re", &journal_t::find_account_re,
+ return_internal_reference<1>())
+
+ .def("add_entry", py_add_entry)
+ .def("remove_entry", &journal_t::remove_entry)
+
+ .def("add_entry_finalizer", py_add_entry_finalizer)
+ .def("remove_entry_finalizer", py_remove_entry_finalizer)
+ .def("run_entry_finalizers", py_run_entry_finalizers)
+
+ .def("valid", &journal_t::valid)
+ ;
+
+ class_< entry_base_t, entry_base_wrap, boost::noncopyable > ("EntryBase")
+ .def("__len__", transactions_len)
+ .def("__getitem__", transactions_getitem,
+ return_internal_reference<1>())
+
+ .def_readonly("journal", &entry_base_t::journal)
+
+ .def_readonly("src_idx", &entry_base_t::src_idx)
+ .def_readonly("beg_pos", &entry_base_t::beg_pos)
+ .def_readonly("beg_line", &entry_base_t::beg_line)
+ .def_readonly("end_pos", &entry_base_t::end_pos)
+ .def_readonly("end_line", &entry_base_t::end_line)
+
+ .def("add_transaction", py_add_transaction)
+ .def("remove_transaction", &entry_base_t::remove_transaction)
+
+ .def(self == self)
+ .def(self != self)
+
+ .def("finalize", &entry_base_t::finalize)
+ .def("valid", &entry_base_t::valid)
+ ;
+
+ class_< entry_t, bases<entry_base_t> > ("Entry")
+ .add_property("date", &entry_t::date)
+ .add_property("effective_date", &entry_t::effective_date)
+ .add_property("actual_date", &entry_t::actual_date)
+
+ .def_readwrite("code", &entry_t::code)
+ .def_readwrite("payee", &entry_t::payee)
+
+ .add_property("state", &py_entry_state)
+
+ .def("valid", &entry_t::valid)
+ ;
+
+#define EXC_TRANSLATE(type) \
+ register_exception_translator<type>(&exc_translate_ ## type);
+
+ EXC_TRANSLATE(balance_error);
+ EXC_TRANSLATE(interval_expr_error);
+ EXC_TRANSLATE(format_error);
+ EXC_TRANSLATE(parse_error);
+}
diff --git a/py_option.cc b/py_option.cc
new file mode 100644
index 00000000..877d92a7
--- /dev/null
+++ b/py_option.cc
@@ -0,0 +1,73 @@
+using namespace boost::python;
+using namespace ledger;
+
+struct py_option_t : public option_t
+{
+ PyObject * self;
+
+ py_option_t(PyObject * self_,
+ const string& long_opt,
+ const bool wants_arg)
+ : self(self_), option_t(long_opt, wants_arg) {}
+
+ virtual ~py_option_t() {}
+
+ virtual bool check(option_source_t source) {
+ return call_method<bool>(self, "check", source);
+ }
+
+ virtual void select(report_t * report, const char * optarg = NULL) {
+ if (optarg)
+ return call_method<void>(self, "select", report, optarg);
+ else
+ return call_method<void>(self, "select", report);
+ }
+};
+
+BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(option_select_overloads,
+ py_option_t::select, 1, 2)
+
+typedef std::map<const string, object> options_map;
+typedef std::pair<const string, object> options_pair;
+
+options_map options;
+
+static option_t * find_option(const string& name)
+{
+ options_map::const_iterator i = options.find(name);
+ if (i != options.end())
+ return extract<py_option_t *>((*i).second.ptr());
+
+ return NULL;
+}
+
+void shutdown_option()
+{
+ options.clear();
+}
+
+void export_option()
+{
+ class_< option_t, py_option_t, boost::noncopyable >
+ ("Option", init<const string&, bool>())
+ .def_readonly("long_opt", &py_option_t::long_opt)
+ .def_readonly("short_opt", &py_option_t::short_opt)
+ .def_readonly("wants_arg", &py_option_t::wants_arg)
+ .def_readwrite("handled", &py_option_t::handled)
+ .def("check", &py_option_t::check)
+ .def("select", &py_option_t::select, option_select_overloads())
+ ;
+
+ enum_< option_t::option_source_t > ("OptionSource")
+ .value("InitFile", option_t::INIT_FILE)
+ .value("Environment", option_t::ENVIRONMENT)
+ .value("DataFile", option_t::DATA_FILE)
+ .value("CommandLine", option_t::COMMAND_LINE)
+ ;
+
+ class_< options_map > ("OptionsMap")
+ .def(map_indexing_suite<options_map>())
+ ;
+
+ scope().attr("options") = ptr(&options);
+}
diff --git a/parser.cc b/py_parser.cc
index f119a0ef..f119a0ef 100644
--- a/parser.cc
+++ b/py_parser.cc
diff --git a/py_report.cc b/py_report.cc
new file mode 100644
index 00000000..0bc36857
--- /dev/null
+++ b/py_report.cc
@@ -0,0 +1,13 @@
+using namespace boost::python;
+using namespace ledger;
+
+void export_report()
+{
+ class_< report_t > ("Report")
+ .add_property("session",
+ make_getter(&report_t::session,
+ return_value_policy<reference_existing_object>()))
+
+ .def("apply_transforms", &report_t::apply_transforms)
+ ;
+}
diff --git a/py_session.cc b/py_session.cc
new file mode 100644
index 00000000..f249c54e
--- /dev/null
+++ b/py_session.cc
@@ -0,0 +1,36 @@
+using namespace boost::python;
+using namespace ledger;
+
+void export_session()
+{
+ class_< session_t > ("Session")
+ .def_readwrite("init_file", &session_t::init_file)
+ .def_readwrite("data_file", &session_t::data_file)
+ .def_readwrite("cache_file", &session_t::cache_file)
+ .def_readwrite("price_db", &session_t::price_db)
+
+ .def_readwrite("balance_format", &session_t::balance_format)
+ .def_readwrite("register_format", &session_t::register_format)
+ .def_readwrite("wide_register_format", &session_t::wide_register_format)
+ .def_readwrite("plot_amount_format", &session_t::plot_amount_format)
+ .def_readwrite("plot_total_format", &session_t::plot_total_format)
+ .def_readwrite("print_format", &session_t::print_format)
+ .def_readwrite("write_hdr_format", &session_t::write_hdr_format)
+ .def_readwrite("write_xact_format", &session_t::write_xact_format)
+ .def_readwrite("equity_format", &session_t::equity_format)
+ .def_readwrite("prices_format", &session_t::prices_format)
+ .def_readwrite("pricesdb_format", &session_t::pricesdb_format)
+
+ .def_readwrite("pricing_leeway", &session_t::pricing_leeway)
+
+ .def_readwrite("download_quotes", &session_t::download_quotes)
+ .def_readwrite("use_cache", &session_t::use_cache)
+ .def_readwrite("cache_dirty", &session_t::cache_dirty)
+ .def_readwrite("debug_mode", &session_t::debug_mode)
+ .def_readwrite("verbose_mode", &session_t::verbose_mode)
+ .def_readwrite("trace_alloc_mode", &session_t::trace_alloc_mode)
+ .def_readwrite("trace_class_mode", &session_t::trace_class_mode)
+
+ .def_readwrite("journals", &session_t::journals)
+ ;
+}
diff --git a/py_transform.cc b/py_transform.cc
new file mode 100644
index 00000000..a0ba31d4
--- /dev/null
+++ b/py_transform.cc
@@ -0,0 +1,8 @@
+using namespace boost::python;
+using namespace ledger;
+
+void export_transform()
+{
+ class_< repitem_t > ("Transform")
+ ;
+}
diff --git a/py_value.cc b/py_value.cc
new file mode 100644
index 00000000..1a43ebc1
--- /dev/null
+++ b/py_value.cc
@@ -0,0 +1,337 @@
+using namespace boost::python;
+using namespace ledger;
+
+long balance_len(balance_t& bal);
+amount_t balance_getitem(balance_t& bal, int i);
+long balance_pair_len(balance_pair_t& bal_pair);
+amount_t balance_pair_getitem(balance_pair_t& bal_pair, int i);
+
+long value_len(value_t& val)
+{
+ switch (val.type) {
+ case value_t::BOOLEAN:
+ case value_t::INTEGER:
+ case value_t::DATETIME:
+ case value_t::AMOUNT:
+ return 1;
+
+ case value_t::BALANCE:
+ return balance_len(*((balance_t *) val.data));
+
+ case value_t::BALANCE_PAIR:
+ return balance_pair_len(*((balance_pair_t *) val.data));
+
+ case value_t::STRING:
+ case value_t::XML_NODE:
+ case value_t::POINTER:
+ return 1;
+
+ case value_t::SEQUENCE:
+ return (*(value_t::sequence_t **) val.data)->size();
+
+ default:
+ assert(0);
+ break;
+ }
+ assert(0);
+ return 0;
+}
+
+amount_t value_getitem(value_t& val, int i)
+{
+ std::size_t len = value_len(val);
+
+ if (abs(i) >= len) {
+ PyErr_SetString(PyExc_IndexError, "Index out of range");
+ throw_error_already_set();
+ }
+
+ switch (val.type) {
+ case value_t::BOOLEAN:
+ throw_(value_exception, "Cannot cast a boolean to an amount");
+
+ case value_t::INTEGER:
+ return long(val);
+
+ case value_t::DATETIME:
+ throw_(value_exception, "Cannot cast a date/time to an amount");
+
+ case value_t::AMOUNT:
+ return *((amount_t *) val.data);
+
+ case value_t::BALANCE:
+ return balance_getitem(*((balance_t *) val.data), i);
+
+ case value_t::BALANCE_PAIR:
+ return balance_pair_getitem(*((balance_pair_t *) val.data), i);
+
+ case value_t::STRING:
+ throw_(value_exception, "Cannot cast a string to an amount");
+
+ case value_t::XML_NODE:
+ return (*(xml::node_t **) data)->to_value();
+
+ case value_t::POINTER:
+ throw_(value_exception, "Cannot cast a pointer to an amount");
+
+ case value_t::SEQUENCE:
+ return (*(value_t::sequence_t **) val.data)[i];
+
+ default:
+ assert(0);
+ break;
+ }
+ assert(0);
+ return 0L;
+}
+
+double py_to_float(value_t& val)
+{
+ return double(val);
+}
+
+void export_value()
+{
+ class_< value_t > ("value")
+ .def(init<value_t>())
+ .def(init<balance_pair_t>())
+ .def(init<balance_t>())
+ .def(init<amount_t>())
+ .def(init<string>())
+ .def(init<double>())
+ .def(init<long>())
+ .def(initmoment_t())
+
+ .def(self + self)
+ .def(self + other<string>())
+ .def(self + other<balance_pair_t>())
+ .def(self + other<balance_t>())
+ .def(self + other<amount_t>())
+ .def(self + long())
+ .def(self + double())
+
+ .def(other<string>() + self)
+ .def(other<balance_pair_t>() + self)
+ .def(other<balance_t>() + self)
+ .def(other<amount_t>() + self)
+ .def(long() + self)
+ .def(double() + self)
+
+ .def(self - self)
+ .def(self - other<string>())
+ .def(self - other<balance_pair_t>())
+ .def(self - other<balance_t>())
+ .def(self - other<amount_t>())
+ .def(self - long())
+ .def(self - double())
+
+ .def(other<string>() - self)
+ .def(other<balance_pair_t>() - self)
+ .def(other<balance_t>() - self)
+ .def(other<amount_t>() - self)
+ .def(long() - self)
+ .def(double() - self)
+
+ .def(self * self)
+ .def(self * other<string>())
+ .def(self * other<balance_pair_t>())
+ .def(self * other<balance_t>())
+ .def(self * other<amount_t>())
+ .def(self * long())
+ .def(self * double())
+
+ .def(other<string>() * self)
+ .def(other<balance_pair_t>() * self)
+ .def(other<balance_t>() * self)
+ .def(other<amount_t>() * self)
+ .def(long() * self)
+ .def(double() * self)
+
+ .def(self / self)
+ .def(self / other<string>())
+ .def(self / other<balance_pair_t>())
+ .def(self / other<balance_t>())
+ .def(self / other<amount_t>())
+ .def(self / long())
+ .def(self / double())
+
+ .def(other<string>() / self)
+ .def(other<balance_pair_t>() / self)
+ .def(other<balance_t>() / self)
+ .def(other<amount_t>() / self)
+ .def(long() / self)
+ .def(double() / self)
+
+ .def(- self)
+
+ .def(self += self)
+ .def(self += other<string>())
+ .def(self += other<balance_pair_t>())
+ .def(self += other<balance_t>())
+ .def(self += other<amount_t>())
+ .def(self += long())
+ .def(self += double())
+
+ .def(self -= self)
+ .def(self -= other<string>())
+ .def(self -= other<balance_pair_t>())
+ .def(self -= other<balance_t>())
+ .def(self -= other<amount_t>())
+ .def(self -= long())
+ .def(self -= double())
+
+ .def(self *= self)
+ .def(self *= other<string>())
+ .def(self *= other<balance_pair_t>())
+ .def(self *= other<balance_t>())
+ .def(self *= other<amount_t>())
+ .def(self *= long())
+ .def(self *= double())
+
+ .def(self /= self)
+ .def(self /= other<string>())
+ .def(self /= other<balance_pair_t>())
+ .def(self /= other<balance_t>())
+ .def(self /= other<amount_t>())
+ .def(self /= long())
+ .def(self /= double())
+
+ .def(self < self)
+ .def(self < other<string>())
+ .def(self < other<balance_pair_t>())
+ .def(self < other<balance_t>())
+ .def(self < other<amount_t>())
+ .def(self < long())
+ .def(self < othermoment_t())
+ .def(self < double())
+
+ .def(other<string>() < self)
+ .def(other<balance_pair_t>() < self)
+ .def(other<balance_t>() < self)
+ .def(other<amount_t>() < self)
+ .def(long() < self)
+ .def(othermoment_t() < self)
+ .def(double() < self)
+
+ .def(self <= self)
+ .def(self <= other<string>())
+ .def(self <= other<balance_pair_t>())
+ .def(self <= other<balance_t>())
+ .def(self <= other<amount_t>())
+ .def(self <= long())
+ .def(self <= othermoment_t())
+ .def(self <= double())
+
+ .def(other<string>() <= self)
+ .def(other<balance_pair_t>() <= self)
+ .def(other<balance_t>() <= self)
+ .def(other<amount_t>() <= self)
+ .def(long() <= self)
+ .def(othermoment_t() <= self)
+ .def(double() <= self)
+
+ .def(self > self)
+ .def(self > other<string>())
+ .def(self > other<balance_pair_t>())
+ .def(self > other<balance_t>())
+ .def(self > other<amount_t>())
+ .def(self > long())
+ .def(self > othermoment_t())
+ .def(self > double())
+
+ .def(other<string>() > self)
+ .def(other<balance_pair_t>() > self)
+ .def(other<balance_t>() > self)
+ .def(other<amount_t>() > self)
+ .def(long() > self)
+ .def(othermoment_t() > self)
+ .def(double() > self)
+
+ .def(self >= self)
+ .def(self >= other<string>())
+ .def(self >= other<balance_pair_t>())
+ .def(self >= other<balance_t>())
+ .def(self >= other<amount_t>())
+ .def(self >= long())
+ .def(self >= othermoment_t())
+ .def(self >= double())
+
+ .def(other<string>() >= self)
+ .def(other<balance_pair_t>() >= self)
+ .def(other<balance_t>() >= self)
+ .def(other<amount_t>() >= self)
+ .def(long() >= self)
+ .def(othermoment_t() >= self)
+ .def(double() >= self)
+
+ .def(self == self)
+ .def(self == other<string>())
+ .def(self == other<balance_pair_t>())
+ .def(self == other<balance_t>())
+ .def(self == other<amount_t>())
+ .def(self == long())
+ .def(self == othermoment_t())
+ .def(self == double())
+
+ .def(other<string>() == self)
+ .def(other<balance_pair_t>() == self)
+ .def(other<balance_t>() == self)
+ .def(other<amount_t>() == self)
+ .def(long() == self)
+ .def(othermoment_t() == self)
+ .def(double() == self)
+
+ .def(self != self)
+ .def(self != other<string>())
+ .def(self != other<balance_pair_t>())
+ .def(self != other<balance_t>())
+ .def(self != other<amount_t>())
+ .def(self != long())
+ .def(self != othermoment_t())
+ .def(self != double())
+
+ .def(other<string>() != self)
+ .def(other<balance_pair_t>() != self)
+ .def(other<balance_t>() != self)
+ .def(other<amount_t>() != self)
+ .def(long() != self)
+ .def(othermoment_t() != self)
+ .def(double() != self)
+
+ .def(! self)
+
+ .def(self_ns::int_(self))
+ .def(self_ns::float_(self))
+ .def(self_ns::str(self))
+
+ .def_readonly("type", &value_t::type)
+
+ .def("__abs__", &value_t::abs)
+ .def("__len__", value_len)
+ .def("__getitem__", value_getitem)
+
+ .def("cast", &value_t::cast)
+ .def("cost", &value_t::cost)
+ .def("price", &value_t::price)
+ .def("date", &value_t::date)
+ .def("strip_annotations", &value_t::strip_annotations)
+ .def("add", &value_t::add, return_internal_reference<>())
+ .def("value", &value_t::value)
+ .def("round", &value_t::round)
+ .def("negate", &value_t::negate)
+ .def("write", &value_t::write)
+ ;
+
+ enum_< value_t::type_t > ("ValueType")
+ .value("Boolean", value_t::BOOLEAN)
+ .value("Integer", value_t::INTEGER)
+ .value("DateTime", value_t::DATETIME)
+ .value("Amount", value_t::AMOUNT)
+ .value("Balance", value_t::BALANCE)
+ .value("BalancePair", value_t::BALANCE_PAIR)
+ .value("String", value_t::STRING)
+ .value("XmlNode", value_t::XML_NODE)
+ .value("Pointer", value_t::POINTER)
+ .value("Sequence", value_t::SEQUENCE)
+ ;
+}
diff --git a/py_xpath.cc b/py_xpath.cc
new file mode 100644
index 00000000..6569ce7b
--- /dev/null
+++ b/py_xpath.cc
@@ -0,0 +1,79 @@
+using namespace boost::python;
+using namespace ledger;
+
+value_t py_calc_1(xpath_t::op_t& xpath_t, const details_t& item)
+{
+ value_t result;
+ xpath_t.calc(result, item);
+ return result;
+}
+
+template <typename T>
+value_t py_calc(xpath_t::op_t& xpath_t, const T& item)
+{
+ value_t result;
+ xpath_t.calc(result, details_t(item));
+ return result;
+}
+
+xpath_t::op_t * py_parse_xpath_t_1(const string& str)
+{
+ return parse_xpath_t(str);
+}
+
+#define EXC_TRANSLATOR(type) \
+ void exc_translate_ ## type(const type& err) { \
+ PyErr_SetString(PyExc_RuntimeError, err.what()); \
+ }
+
+EXC_TRANSLATOR(xpath_t_error)
+EXC_TRANSLATOR(calc_error)
+#if 0
+EXC_TRANSLATOR(mask_error)
+#endif
+
+void export_xpath()
+{
+ class_< details_t > ("Details", init<const entry_t&>())
+ .def(init<const transaction_t&>())
+ .def(init<const account_t&>())
+ .add_property("entry",
+ make_getter(&details_t::entry,
+ return_value_policy<reference_existing_object>()))
+ .add_property("xact",
+ make_getter(&details_t::xact,
+ return_value_policy<reference_existing_object>()))
+ .add_property("account",
+ make_getter(&details_t::account,
+ return_value_policy<reference_existing_object>()))
+ ;
+
+ class_< xpath_t::op_t > ("ValueExpr", init<xpath_t::op_t::kind_t>())
+ .def("calc", py_calc_1)
+ .def("calc", py_calc<account_t>)
+ .def("calc", py_calc<entry_t>)
+ .def("calc", py_calc<transaction_t>)
+ ;
+
+ def("parse_xpath_t", py_parse_xpath_t_1,
+ return_value_policy<manage_new_object>());
+
+ class_< item_predicate<transaction_t> >
+ ("TransactionPredicate", init<string>())
+ .def("__call__", &item_predicate<transaction_t>::operator())
+ ;
+
+ class_< item_predicate<account_t> >
+ ("AccountPredicate", init<string>())
+ .def("__call__", &item_predicate<account_t>::operator())
+ ;
+
+#define EXC_TRANSLATE(type) \
+ register_exception_translator<type>(&exc_translate_ ## type);
+
+ EXC_TRANSLATE(xpath_t_error);
+ EXC_TRANSLATE(calc_error);
+#if 0
+ EXC_TRANSLATE(mask_error);
+#endif
+}
diff --git a/pyledger.cc b/pyledger.cc
index 81112d1a..08b69590 100644
--- a/pyledger.cc
+++ b/pyledger.cc
@@ -1,8 +1,10 @@
#include "py_eval.h"
+#include "session.h"
using namespace boost::python;
BOOST_PYTHON_MODULE(ledger)
{
- ledger::initialize_ledger_for_python();
+ ledger::initialize();
+ ledger::initialize_for_python();
}
diff --git a/quotes.cc b/quotes.cc
index 204e6fdc..1463c9bc 100644
--- a/quotes.cc
+++ b/quotes.cc
@@ -8,7 +8,7 @@ void quotes_by_script::operator()(commodity_base_t& commodity,
const ptime& last,
amount_t& price)
{
- logger("quotes.download");
+ LOGGER("quotes.download");
DEBUG("commodity: " << commodity.symbol);
DEBUG(" now: " << now);
diff --git a/report.cc b/report.cc
index 019bc669..116747ef 100644
--- a/report.cc
+++ b/report.cc
@@ -187,23 +187,3 @@ xml::xpath_t::op_t * report_t::lookup(const string& name)
}
} // namespace ledger
-
-#if 0
-#ifdef USE_BOOST_PYTHON
-
-using namespace boost::python;
-using namespace ledger;
-
-void export_report()
-{
- class_< report_t > ("Report")
- .add_property("session",
- make_getter(&report_t::session,
- return_value_policy<reference_existing_object>()))
-
- .def("apply_transforms", &report_t::apply_transforms)
- ;
-}
-
-#endif // USE_BOOST_PYTHON
-#endif
diff --git a/session.cc b/session.cc
index 6d6215e8..25d040ff 100644
--- a/session.cc
+++ b/session.cc
@@ -1,4 +1,7 @@
#include "session.h"
+#if defined(USE_BOOST_PYTHON)
+#include "py_eval.h"
+#endif
namespace ledger {
@@ -194,50 +197,10 @@ void initialize()
void shutdown()
{
+#if defined(USE_BOOST_PYTHON)
+ shutdown_for_python();
+#endif
amount_t::shutdown();
}
} // namespace ledger
-
-#if 0
-#ifdef USE_BOOST_PYTHON
-
-using namespace boost::python;
-using namespace ledger;
-
-void export_session()
-{
- class_< session_t > ("Session")
- .def_readwrite("init_file", &session_t::init_file)
- .def_readwrite("data_file", &session_t::data_file)
- .def_readwrite("cache_file", &session_t::cache_file)
- .def_readwrite("price_db", &session_t::price_db)
-
- .def_readwrite("balance_format", &session_t::balance_format)
- .def_readwrite("register_format", &session_t::register_format)
- .def_readwrite("wide_register_format", &session_t::wide_register_format)
- .def_readwrite("plot_amount_format", &session_t::plot_amount_format)
- .def_readwrite("plot_total_format", &session_t::plot_total_format)
- .def_readwrite("print_format", &session_t::print_format)
- .def_readwrite("write_hdr_format", &session_t::write_hdr_format)
- .def_readwrite("write_xact_format", &session_t::write_xact_format)
- .def_readwrite("equity_format", &session_t::equity_format)
- .def_readwrite("prices_format", &session_t::prices_format)
- .def_readwrite("pricesdb_format", &session_t::pricesdb_format)
-
- .def_readwrite("pricing_leeway", &session_t::pricing_leeway)
-
- .def_readwrite("download_quotes", &session_t::download_quotes)
- .def_readwrite("use_cache", &session_t::use_cache)
- .def_readwrite("cache_dirty", &session_t::cache_dirty)
- .def_readwrite("debug_mode", &session_t::debug_mode)
- .def_readwrite("verbose_mode", &session_t::verbose_mode)
- .def_readwrite("trace_alloc_mode", &session_t::trace_alloc_mode)
- .def_readwrite("trace_class_mode", &session_t::trace_class_mode)
-
- .def_readwrite("journals", &session_t::journals)
- ;
-}
-
-#endif // USE_BOOST_PYTHON
-#endif
diff --git a/session.h b/session.h
index a848c126..8f5a77b2 100644
--- a/session.h
+++ b/session.h
@@ -177,7 +177,7 @@ class session_t : public xml::xpath_t::scope_t
}
#if 0
-#ifdef USE_BOOST_PYTHON
+#if defined(USE_BOOST_PYTHON)
void option_import(value_t&) {
python_import(optarg);
}
diff --git a/tests/python/corelib/numerics/BasicAmount.py b/tests/python/corelib/numerics/BasicAmount.py
index bfb67cf2..2ce532d9 100644
--- a/tests/python/corelib/numerics/BasicAmount.py
+++ b/tests/python/corelib/numerics/BasicAmount.py
@@ -4,12 +4,6 @@ import exceptions
from ledger import amount
class BasicAmountTestCase(unittest.TestCase):
- def setUp(self):
- amount.initialize()
-
- def tearDown(self):
- amount.shutdown()
-
def testConstructors(self):
x0 = amount()
x1 = amount(123456)
diff --git a/tests/python/corelib/numerics/CommodityAmount.py b/tests/python/corelib/numerics/CommodityAmount.py
index 923fab69..80f58b21 100644
--- a/tests/python/corelib/numerics/CommodityAmount.py
+++ b/tests/python/corelib/numerics/CommodityAmount.py
@@ -10,8 +10,6 @@ internalAmount = amount.exact
class CommodityAmountTestCase(unittest.TestCase):
def setUp(self):
- amount.initialize()
-
# Cause the display precision for dollars to be initialized to 2.
x1 = amount("$1.00")
self.assertTrue(x1)
@@ -19,7 +17,6 @@ class CommodityAmountTestCase(unittest.TestCase):
def tearDown(self):
amount.full_strings = False
- amount.shutdown()
def assertValid(self, amt):
self.assertTrue(amt.valid())
diff --git a/transform.cc b/transform.cc
index 5552d334..b6a25cee 100644
--- a/transform.cc
+++ b/transform.cc
@@ -324,18 +324,3 @@ void remove_transform::execute(xml::document_t * document)
#endif
} // namespace ledger
-
-#if 0
-#ifdef USE_BOOST_PYTHON
-
-using namespace boost::python;
-using namespace ledger;
-
-void export_transform()
-{
- class_< repitem_t > ("Transform")
- ;
-}
-
-#endif // USE_BOOST_PYTHON
-#endif
diff --git a/utils.h b/utils.h
index c6654828..9a26d40f 100644
--- a/utils.h
+++ b/utils.h
@@ -209,7 +209,7 @@ extern std::ostringstream _log_buffer;
bool logger_func(log_level_t level);
-#define logger(cat) \
+#define LOGGER(cat) \
static const char * const _this_category = cat
#define SHOW_TRACE(lvl) \
@@ -266,7 +266,7 @@ bool logger_func(log_level_t level);
#else // ! LOGGING_ON
-#define logger(cat)
+#define LOGGER(cat)
#define SHOW_TRACE(lvl) false
#define SHOW_DEBUG_(cat) false
diff --git a/value.cc b/value.cc
index 49d4ff09..914a49e2 100644
--- a/value.cc
+++ b/value.cc
@@ -2309,347 +2309,3 @@ void value_context::describe(std::ostream& out) const throw()
#endif
} // namespace ledger
-
-#if 0
-#ifdef USE_BOOST_PYTHON
-
-using namespace boost::python;
-using namespace ledger;
-
-long balance_len(balance_t& bal);
-amount_t balance_getitem(balance_t& bal, int i);
-long balance_pair_len(balance_pair_t& bal_pair);
-amount_t balance_pair_getitem(balance_pair_t& bal_pair, int i);
-
-long value_len(value_t& val)
-{
- switch (val.type) {
- case value_t::BOOLEAN:
- case value_t::INTEGER:
- case value_t::DATETIME:
- case value_t::AMOUNT:
- return 1;
-
- case value_t::BALANCE:
- return balance_len(*((balance_t *) val.data));
-
- case value_t::BALANCE_PAIR:
- return balance_pair_len(*((balance_pair_t *) val.data));
-
- case value_t::STRING:
- case value_t::XML_NODE:
- case value_t::POINTER:
- return 1;
-
- case value_t::SEQUENCE:
- return (*(value_t::sequence_t **) val.data)->size();
-
- default:
- assert(0);
- break;
- }
- assert(0);
- return 0;
-}
-
-amount_t value_getitem(value_t& val, int i)
-{
- std::size_t len = value_len(val);
-
- if (abs(i) >= len) {
- PyErr_SetString(PyExc_IndexError, "Index out of range");
- throw_error_already_set();
- }
-
- switch (val.type) {
- case value_t::BOOLEAN:
- throw_(value_exception, "Cannot cast a boolean to an amount");
-
- case value_t::INTEGER:
- return long(val);
-
- case value_t::DATETIME:
- throw_(value_exception, "Cannot cast a date/time to an amount");
-
- case value_t::AMOUNT:
- return *((amount_t *) val.data);
-
- case value_t::BALANCE:
- return balance_getitem(*((balance_t *) val.data), i);
-
- case value_t::BALANCE_PAIR:
- return balance_pair_getitem(*((balance_pair_t *) val.data), i);
-
- case value_t::STRING:
- throw_(value_exception, "Cannot cast a string to an amount");
-
- case value_t::XML_NODE:
- return (*(xml::node_t **) data)->to_value();
-
- case value_t::POINTER:
- throw_(value_exception, "Cannot cast a pointer to an amount");
-
- case value_t::SEQUENCE:
- return (*(value_t::sequence_t **) val.data)[i];
-
- default:
- assert(0);
- break;
- }
- assert(0);
- return 0L;
-}
-
-double py_to_float(value_t& val)
-{
- return double(val);
-}
-
-void export_value()
-{
- class_< value_t > ("value")
- .def(init<value_t>())
- .def(init<balance_pair_t>())
- .def(init<balance_t>())
- .def(init<amount_t>())
- .def(init<string>())
- .def(init<double>())
- .def(init<long>())
- .def(initmoment_t())
-
- .def(self + self)
- .def(self + other<string>())
- .def(self + other<balance_pair_t>())
- .def(self + other<balance_t>())
- .def(self + other<amount_t>())
- .def(self + long())
- .def(self + double())
-
- .def(other<string>() + self)
- .def(other<balance_pair_t>() + self)
- .def(other<balance_t>() + self)
- .def(other<amount_t>() + self)
- .def(long() + self)
- .def(double() + self)
-
- .def(self - self)
- .def(self - other<string>())
- .def(self - other<balance_pair_t>())
- .def(self - other<balance_t>())
- .def(self - other<amount_t>())
- .def(self - long())
- .def(self - double())
-
- .def(other<string>() - self)
- .def(other<balance_pair_t>() - self)
- .def(other<balance_t>() - self)
- .def(other<amount_t>() - self)
- .def(long() - self)
- .def(double() - self)
-
- .def(self * self)
- .def(self * other<string>())
- .def(self * other<balance_pair_t>())
- .def(self * other<balance_t>())
- .def(self * other<amount_t>())
- .def(self * long())
- .def(self * double())
-
- .def(other<string>() * self)
- .def(other<balance_pair_t>() * self)
- .def(other<balance_t>() * self)
- .def(other<amount_t>() * self)
- .def(long() * self)
- .def(double() * self)
-
- .def(self / self)
- .def(self / other<string>())
- .def(self / other<balance_pair_t>())
- .def(self / other<balance_t>())
- .def(self / other<amount_t>())
- .def(self / long())
- .def(self / double())
-
- .def(other<string>() / self)
- .def(other<balance_pair_t>() / self)
- .def(other<balance_t>() / self)
- .def(other<amount_t>() / self)
- .def(long() / self)
- .def(double() / self)
-
- .def(- self)
-
- .def(self += self)
- .def(self += other<string>())
- .def(self += other<balance_pair_t>())
- .def(self += other<balance_t>())
- .def(self += other<amount_t>())
- .def(self += long())
- .def(self += double())
-
- .def(self -= self)
- .def(self -= other<string>())
- .def(self -= other<balance_pair_t>())
- .def(self -= other<balance_t>())
- .def(self -= other<amount_t>())
- .def(self -= long())
- .def(self -= double())
-
- .def(self *= self)
- .def(self *= other<string>())
- .def(self *= other<balance_pair_t>())
- .def(self *= other<balance_t>())
- .def(self *= other<amount_t>())
- .def(self *= long())
- .def(self *= double())
-
- .def(self /= self)
- .def(self /= other<string>())
- .def(self /= other<balance_pair_t>())
- .def(self /= other<balance_t>())
- .def(self /= other<amount_t>())
- .def(self /= long())
- .def(self /= double())
-
- .def(self < self)
- .def(self < other<string>())
- .def(self < other<balance_pair_t>())
- .def(self < other<balance_t>())
- .def(self < other<amount_t>())
- .def(self < long())
- .def(self < othermoment_t())
- .def(self < double())
-
- .def(other<string>() < self)
- .def(other<balance_pair_t>() < self)
- .def(other<balance_t>() < self)
- .def(other<amount_t>() < self)
- .def(long() < self)
- .def(othermoment_t() < self)
- .def(double() < self)
-
- .def(self <= self)
- .def(self <= other<string>())
- .def(self <= other<balance_pair_t>())
- .def(self <= other<balance_t>())
- .def(self <= other<amount_t>())
- .def(self <= long())
- .def(self <= othermoment_t())
- .def(self <= double())
-
- .def(other<string>() <= self)
- .def(other<balance_pair_t>() <= self)
- .def(other<balance_t>() <= self)
- .def(other<amount_t>() <= self)
- .def(long() <= self)
- .def(othermoment_t() <= self)
- .def(double() <= self)
-
- .def(self > self)
- .def(self > other<string>())
- .def(self > other<balance_pair_t>())
- .def(self > other<balance_t>())
- .def(self > other<amount_t>())
- .def(self > long())
- .def(self > othermoment_t())
- .def(self > double())
-
- .def(other<string>() > self)
- .def(other<balance_pair_t>() > self)
- .def(other<balance_t>() > self)
- .def(other<amount_t>() > self)
- .def(long() > self)
- .def(othermoment_t() > self)
- .def(double() > self)
-
- .def(self >= self)
- .def(self >= other<string>())
- .def(self >= other<balance_pair_t>())
- .def(self >= other<balance_t>())
- .def(self >= other<amount_t>())
- .def(self >= long())
- .def(self >= othermoment_t())
- .def(self >= double())
-
- .def(other<string>() >= self)
- .def(other<balance_pair_t>() >= self)
- .def(other<balance_t>() >= self)
- .def(other<amount_t>() >= self)
- .def(long() >= self)
- .def(othermoment_t() >= self)
- .def(double() >= self)
-
- .def(self == self)
- .def(self == other<string>())
- .def(self == other<balance_pair_t>())
- .def(self == other<balance_t>())
- .def(self == other<amount_t>())
- .def(self == long())
- .def(self == othermoment_t())
- .def(self == double())
-
- .def(other<string>() == self)
- .def(other<balance_pair_t>() == self)
- .def(other<balance_t>() == self)
- .def(other<amount_t>() == self)
- .def(long() == self)
- .def(othermoment_t() == self)
- .def(double() == self)
-
- .def(self != self)
- .def(self != other<string>())
- .def(self != other<balance_pair_t>())
- .def(self != other<balance_t>())
- .def(self != other<amount_t>())
- .def(self != long())
- .def(self != othermoment_t())
- .def(self != double())
-
- .def(other<string>() != self)
- .def(other<balance_pair_t>() != self)
- .def(other<balance_t>() != self)
- .def(other<amount_t>() != self)
- .def(long() != self)
- .def(othermoment_t() != self)
- .def(double() != self)
-
- .def(! self)
-
- .def(self_ns::int_(self))
- .def(self_ns::float_(self))
- .def(self_ns::str(self))
-
- .def_readonly("type", &value_t::type)
-
- .def("__abs__", &value_t::abs)
- .def("__len__", value_len)
- .def("__getitem__", value_getitem)
-
- .def("cast", &value_t::cast)
- .def("cost", &value_t::cost)
- .def("price", &value_t::price)
- .def("date", &value_t::date)
- .def("strip_annotations", &value_t::strip_annotations)
- .def("add", &value_t::add, return_internal_reference<>())
- .def("value", &value_t::value)
- .def("round", &value_t::round)
- .def("negate", &value_t::negate)
- .def("write", &value_t::write)
- ;
-
- enum_< value_t::type_t > ("ValueType")
- .value("Boolean", value_t::BOOLEAN)
- .value("Integer", value_t::INTEGER)
- .value("DateTime", value_t::DATETIME)
- .value("Amount", value_t::AMOUNT)
- .value("Balance", value_t::BALANCE)
- .value("BalancePair", value_t::BALANCE_PAIR)
- .value("String", value_t::STRING)
- .value("XmlNode", value_t::XML_NODE)
- .value("Pointer", value_t::POINTER)
- .value("Sequence", value_t::SEQUENCE)
- ;
-}
-
-#endif // USE_BOOST_PYTHON
-#endif
diff --git a/xpath.cc b/xpath.cc
index 70f924e6..39e1d091 100644
--- a/xpath.cc
+++ b/xpath.cc
@@ -2398,89 +2398,3 @@ void xpath_t::op_t::dump(std::ostream& out, const int depth) const
} // namespace xml
} // namespace ledger
-
-#if 0
-#ifdef USE_BOOST_PYTHON
-
-using namespace boost::python;
-using namespace ledger;
-
-value_t py_calc_1(xpath_t::op_t& xpath_t, const details_t& item)
-{
- value_t result;
- xpath_t.calc(result, item);
- return result;
-}
-
-template <typename T>
-value_t py_calc(xpath_t::op_t& xpath_t, const T& item)
-{
- value_t result;
- xpath_t.calc(result, details_t(item));
- return result;
-}
-
-xpath_t::op_t * py_parse_xpath_t_1(const string& str)
-{
- return parse_xpath_t(str);
-}
-
-#define EXC_TRANSLATOR(type) \
- void exc_translate_ ## type(const type& err) { \
- PyErr_SetString(PyExc_RuntimeError, err.what()); \
- }
-
-EXC_TRANSLATOR(xpath_t_error)
-EXC_TRANSLATOR(calc_error)
-#if 0
-EXC_TRANSLATOR(mask_error)
-#endif
-
-void export_xpath()
-{
- class_< details_t > ("Details", init<const entry_t&>())
- .def(init<const transaction_t&>())
- .def(init<const account_t&>())
- .add_property("entry",
- make_getter(&details_t::entry,
- return_value_policy<reference_existing_object>()))
- .add_property("xact",
- make_getter(&details_t::xact,
- return_value_policy<reference_existing_object>()))
- .add_property("account",
- make_getter(&details_t::account,
- return_value_policy<reference_existing_object>()))
- ;
-
- class_< xpath_t::op_t > ("ValueExpr", init<xpath_t::op_t::kind_t>())
- .def("calc", py_calc_1)
- .def("calc", py_calc<account_t>)
- .def("calc", py_calc<entry_t>)
- .def("calc", py_calc<transaction_t>)
- ;
-
- def("parse_xpath_t", py_parse_xpath_t_1,
- return_value_policy<manage_new_object>());
-
- class_< item_predicate<transaction_t> >
- ("TransactionPredicate", init<string>())
- .def("__call__", &item_predicate<transaction_t>::operator())
- ;
-
- class_< item_predicate<account_t> >
- ("AccountPredicate", init<string>())
- .def("__call__", &item_predicate<account_t>::operator())
- ;
-
-#define EXC_TRANSLATE(type) \
- register_exception_translator<type>(&exc_translate_ ## type);
-
- EXC_TRANSLATE(xpath_t_error);
- EXC_TRANSLATE(calc_error);
-#if 0
- EXC_TRANSLATE(mask_error);
-#endif
-}
-
-#endif // USE_BOOST_PYTHON
-#endif