summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--format.cc22
-rw-r--r--format.h14
-rw-r--r--main.cc2
-rw-r--r--main.py7
4 files changed, 27 insertions, 18 deletions
diff --git a/format.cc b/format.cc
index e6086b44..0f39b423 100644
--- a/format.cc
+++ b/format.cc
@@ -185,8 +185,7 @@ element_t * format_t::parse_elements(const std::string& fmt)
return result.release();
}
-void format_t::format_elements(std::ostream& out,
- const details_t& details) const
+void format_t::format(std::ostream& out, const details_t& details) const
{
for (const element_t * elem = elements; elem; elem = elem->next) {
if (elem->align_left)
@@ -439,15 +438,22 @@ bool format_account::display_account(const account_t& account,
using namespace boost::python;
using namespace ledger;
+template <typename T>
+std::string py_format(format_t& format, T& item) {
+ std::ostringstream out;
+ format.format(out, details_t(item));
+ return out.str();
+}
+
void export_format()
{
-#if 0
- class_< format_transactions > ("FormatTransactions")
- .def(init<item_handler<transaction_t> *>())
- .def("flush", &format_transactions::flush)
- .def("__call__", &format_transactions::operator());
+ class_< format_t > ("Format")
+ .def(init<std::string>())
+ .def("reset", &format_t::reset)
+ .def("format", py_format<account_t>)
+ .def("format", py_format<entry_t>)
+ .def("format", py_format<transaction_t>)
;
-#endif
}
#endif // USE_BOOST_PYTHON
diff --git a/format.h b/format.h
index e6a10133..1e959931 100644
--- a/format.h
+++ b/format.h
@@ -73,7 +73,7 @@ struct format_t
static element_t * parse_elements(const std::string& fmt);
- void format_elements(std::ostream& out, const details_t& details) const;
+ void format(std::ostream& out, const details_t& details) const;
static void compute_value(value_t& result, const details_t& details) {
if (value_expr)
@@ -109,10 +109,10 @@ class format_transactions : public item_handler<transaction_t>
if (! xact.data ||
! (XACT_DATA_(xact)->dflags & TRANSACTION_DISPLAYED)) {
if (last_entry != xact.entry) {
- first_line_format.format_elements(output_stream, details_t(xact));
+ first_line_format.format(output_stream, details_t(xact));
last_entry = xact.entry;
} else {
- next_lines_format.format_elements(output_stream, details_t(xact));
+ next_lines_format.format(output_stream, details_t(xact));
}
if (! xact.data)
xact.data = new transaction_data_t;
@@ -157,7 +157,7 @@ class format_account : public item_handler<account_t>
account.data = new account_data_t;
ACCT_DATA_(account)->dflags |= ACCOUNT_TO_DISPLAY;
} else {
- format.format_elements(output_stream, details_t(account));
+ format.format(output_stream, details_t(account));
if (! account.data)
account.data = new account_data_t;
ACCT_DATA_(account)->dflags |= ACCOUNT_DISPLAYED;
@@ -188,7 +188,7 @@ class format_equity : public item_handler<account_t>
entry_t header_entry;
header_entry.payee = "Opening Balances";
header_entry.date = std::time(NULL);
- first_line_format.format_elements(output_stream, details_t(header_entry));
+ first_line_format.format(output_stream, details_t(header_entry));
}
virtual void flush() {
@@ -197,13 +197,13 @@ class format_equity : public item_handler<account_t>
summary.data = acct_data.get();
((account_data_t *) summary.data)->value = total;
((account_data_t *) summary.data)->value.negate();
- next_lines_format.format_elements(output_stream, details_t(summary));
+ next_lines_format.format(output_stream, details_t(summary));
output_stream.flush();
}
virtual void operator()(account_t& account) {
if (format_account::display_account(account, disp_pred)) {
- next_lines_format.format_elements(output_stream, details_t(account));
+ next_lines_format.format(output_stream, details_t(account));
if (! account.data)
account.data = new account_data_t;
else
diff --git a/main.cc b/main.cc
index 861a252c..cbdf7bed 100644
--- a/main.cc
+++ b/main.cc
@@ -347,7 +347,7 @@ int parse_and_report(int argc, char * argv[], char * envp[])
if (ACCT_DATA(journal->master)->dflags & ACCOUNT_TO_DISPLAY) {
out << "--------------------\n";
- config.format.format_elements(out, details_t(*journal->master));
+ config.format.format(out, details_t(*journal->master));
}
}
}
diff --git a/main.py b/main.py
index 4b74307c..1e25b7ed 100644
--- a/main.py
+++ b/main.py
@@ -21,8 +21,11 @@ journal = Journal ()
parse_journal_file (args[0], journal)
class OutputTransaction (TransactionHandler):
+ def __init__ (self):
+ self.formatter = Format ("%D %-20P %N")
+ TransactionHandler.__init__ (self)
def __call__ (self, xact):
- print xact.entry.payee
+ print self.formatter.format(xact)
handler = OutputTransaction()
handler = FilterTransactions (handler, "/Checking/")
@@ -31,6 +34,6 @@ for entry in journal:
for xact in entry:
handler (xact)
-span = Interval ("monthly last year")
+span = Interval ("weekly last month")
for date in span:
print time.strftime ("%c", time.localtime (date))