summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rwxr-xr-xacprep5
-rw-r--r--binary.cc9
-rw-r--r--config.cc3
-rwxr-xr-x[-rw-r--r--]main.py43
-rwxr-xr-xsetup.py20
5 files changed, 57 insertions, 23 deletions
diff --git a/acprep b/acprep
index f95ca98f..2d40b341 100755
--- a/acprep
+++ b/acprep
@@ -22,9 +22,10 @@ if [ "$1" = "--debug" ]; then
CXXFLAGS="-g" --enable-debug --disable-shared
elif [ "$1" = "--opt" ]; then
./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" \
- CXXFLAGS="-fomit-frame-pointer -fastf -mcpu=7450" --disable-shared
+ CXXFLAGS="-fomit-frame-pointer -fastf -mcpu=7450 -fPIC" --disable-shared
elif [ "$1" = "--perf" ]; then
- ./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" CXXFLAGS="-g -pg"
+ ./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" CXXFLAGS="-g -pg" \
+ --disable-shared
fi
rm AUTHORS ChangeLog
diff --git a/binary.cc b/binary.cc
index 98e3be16..c328dfe8 100644
--- a/binary.cc
+++ b/binary.cc
@@ -1,6 +1,7 @@
#include "ledger.h"
#include "binary.h"
+#include <fstream>
#include <ctime>
#include <sys/stat.h>
@@ -612,11 +613,19 @@ using namespace ledger;
BOOST_PYTHON_MEMBER_FUNCTION_OVERLOADS(binary_parse_overloads,
binary_parser_t::parse, 2, 4)
+void py_write_binary_journal(const std::string& path, journal_t * journal)
+{
+ std::ofstream out(path.c_str());
+ write_binary_journal(out, journal, &journal->sources);
+}
+
void export_binary() {
class_< binary_parser_t, bases<parser_t> > ("BinaryParser")
.def("test", &binary_parser_t::test)
.def("parse", &binary_parser_t::parse, binary_parse_overloads())
;
+
+ def("write_binary_journal", py_write_binary_journal);
}
#endif // USE_BOOST_PYTHON
diff --git a/config.cc b/config.cc
index a92d6ab2..d22c1c34 100644
--- a/config.cc
+++ b/config.cc
@@ -753,9 +753,6 @@ void export_config()
.add_property("sort_order",
make_getter(&config_t::sort_order,
return_value_policy<reference_existing_object>()))
- .add_property("output_stream",
- make_getter(&config_t::output_stream,
- return_value_policy<reference_existing_object>()))
.def("process_options", py_process_options)
;
diff --git a/main.py b/main.py
index 60c3e5ee..e514bd1a 100644..100755
--- a/main.py
+++ b/main.py
@@ -1,6 +1,9 @@
+#!/usr/bin/env python
+
import sys
import os
import time
+import re
from ledger import *
@@ -59,23 +62,42 @@ if command == "e":
class FormatTransaction (TransactionHandler):
last_entry = None
+ output = None
def __init__ (self, fmt = None):
if fmt is None:
self.formatter = config.format
self.nformatter = config.nformat
else:
- self.formatter = Format (fmt)
+ try:
+ i = string.index (fmt, '%/')
+ self.formatter = Format (fmt[: i])
+ self.nformatter = Format (fmt[i + 2 :])
+ except ValueError:
+ self.formatter = Format (fmt)
+ self.nformatter = None
self.last_entry = None
+ if config.output_file:
+ self.output = open(config.output_file, "w")
+ else:
+ self.output = sys.stdout
+
TransactionHandler.__init__ (self)
+ def __del__ (self):
+ if config.output_file:
+ self.output.close ()
+
+ def flush (self):
+ self.output.flush ()
+
def __call__ (self, xact):
- if xact.entry is self.last_entry:
- print self.nformatter.format(xact),
+ if self.nformatter and xact.entry is self.last_entry:
+ self.output.write(self.nformatter.format(xact))
else:
- print self.formatter.format(xact),
+ self.output.write(self.formatter.format(xact))
self.last_entry = xact.entry
handler = FormatTransaction()
@@ -108,10 +130,15 @@ if config.show_related:
if config.predicate:
handler = FilterTransactions(handler, config.predicate)
-for entry in journal:
- for xact in entry:
- handler (xact)
+if 1:
+ walk_entries (journal, handler)
+else:
+ # These for loops are equivalent to `walk_entries', but far slower
+ for entry in journal:
+ for xact in entry:
+ handler (xact)
handler.flush ()
-# jww (2004-09-14): still need to write out the cache
+if config.use_cache and config.cache_dirty and config.cache_file:
+ write_binary_journal(config.cache_file, journal);
diff --git a/setup.py b/setup.py
index 5cb1e67e..2f76281d 100755
--- a/setup.py
+++ b/setup.py
@@ -2,16 +2,16 @@
from distutils.core import setup, Extension
-setup(name = "Amounts",
- version = "2.0b",
- description = "Amounts Library",
- author = "John Wiegley",
- author_email = "johnw@newartisans.com",
- url = "http://www.newartisans.com/johnw/",
- ext_modules = [
- Extension("amounts", ["pyamounts.cc"],
- define_macros = [('PYTHON_MODULE', None)],
- libraries = ["ledger_bpy", "boost_python", "gmp"])])
+#setup(name = "Amounts",
+# version = "2.0b",
+# description = "Amounts Library",
+# author = "John Wiegley",
+# author_email = "johnw@newartisans.com",
+# url = "http://www.newartisans.com/johnw/",
+# ext_modules = [
+# Extension("amounts", ["pyamounts.cc"],
+# define_macros = [('PYTHON_MODULE', None)],
+# libraries = ["ledger_bpy", "boost_python", "gmp"])])
setup(name = "Ledger",
version = "2.0b",