diff options
author | John Wiegley <johnw@newartisans.com> | 2004-09-20 04:07:02 -0400 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2004-09-20 04:07:02 -0400 |
commit | a7ea33a8ecc9886dd7a94906ae30c861b4da3540 (patch) | |
tree | 6c2c4df6620f25de5505694c1c8b6d9424b13381 | |
parent | 5429792edc077d8c65d7bbf0f98c3d0e59837775 (diff) | |
download | fork-ledger-a7ea33a8ecc9886dd7a94906ae30c861b4da3540.tar.gz fork-ledger-a7ea33a8ecc9886dd7a94906ae30c861b4da3540.tar.bz2 fork-ledger-a7ea33a8ecc9886dd7a94906ae30c861b4da3540.zip |
passing --enable-python to configure is now required for python support
-rwxr-xr-x | acprep | 2 | ||||
-rw-r--r-- | amounts.py | 25 | ||||
-rw-r--r-- | config.cc | 36 | ||||
-rw-r--r-- | config.h | 2 | ||||
-rw-r--r-- | configure.in | 62 | ||||
-rw-r--r-- | format.cc | 14 | ||||
-rw-r--r-- | format.h | 10 | ||||
-rw-r--r-- | ledger.texi | 23 | ||||
-rw-r--r-- | pyamounts.cc | 13 | ||||
-rw-r--r-- | sample.dat | 15 | ||||
-rwxr-xr-x | setup.py | 11 | ||||
-rw-r--r-- | valexpr.cc | 4 |
12 files changed, 97 insertions, 120 deletions
@@ -19,7 +19,7 @@ LIBDIRS="-L/sw/lib -L/sw/lib/python2.3/config" if [ "$1" = "--debug" ]; then ./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" CXXFLAGS="-g" \ - --enable-debug --disable-shared + --enable-debug --enable-python --disable-shared elif [ "$1" = "--opt" ]; then ./configure CPPFLAGS="$INCDIRS" LDFLAGS="$LIBDIRS" \ CXXFLAGS="-fomit-frame-pointer -fastf -mcpu=7450 -fPIC" diff --git a/amounts.py b/amounts.py deleted file mode 100644 index 1d556a1c..00000000 --- a/amounts.py +++ /dev/null @@ -1,25 +0,0 @@ -from amounts import * - -x = Amount ("$123.45") -print x -x = x * 2 -print x - -y = Amount ("$1000.45") -print x + y - -y = Amount ("$1000.45") -print x * y - -z = Value ("$1000.45") -#print z + Value(y) - -z += Value(x) -print z - -bal = Balance (x) -bal += Amount ("100.8 DM") - -print "balance:", bal -for amt in bal: - print " amount:", amt @@ -18,7 +18,7 @@ config_t::config_t() cache_file += "/.ledger"; price_db += "/.pricedb"; - value_expr = "a"; + amount_expr = "a"; total_expr = "O"; pricing_leeway = 24 * 3600; balance_format = "%20T %2_%-n\n"; @@ -168,11 +168,11 @@ void config_t::process_options(const std::string& command, // Setup the values of %t and %T, used in format strings try { - if (! format_t::value_expr) - format_t::value_expr = parse_value_expr(value_expr); - if (! format_t::value_expr) + if (! format_t::amount_expr) + format_t::amount_expr = parse_value_expr(amount_expr); + if (! format_t::amount_expr) throw value_expr_error(std::string("Failed to parse '") + - value_expr + "'"); + amount_expr + "'"); } catch (const value_expr_error& err) { throw error(std::string("In value expression to -t: ") + err.what()); @@ -514,16 +514,16 @@ OPT_BEGIN(display, "d:") { config.display_predicate += ")"; } OPT_END(display); -OPT_BEGIN(value_expr, "t:") { - config.value_expr = optarg; -} OPT_END(value_expr); +OPT_BEGIN(amount_expr, "t:") { + config.amount_expr = optarg; +} OPT_END(amount_expr); OPT_BEGIN(total_expr, "T:") { config.total_expr = optarg; } OPT_END(total_expr); OPT_BEGIN(value_data, "j") { - config.value_expr = "S" + config.value_expr; + config.amount_expr = "S" + config.amount_expr; config.format_string = config.plot_value_format; } OPT_END(value_data); @@ -549,19 +549,19 @@ OPT_BEGIN(download, "Q") { } OPT_END(download); OPT_BEGIN(quantity, "O") { - config.value_expr = "a"; + config.amount_expr = "a"; config.total_expr = "O"; } OPT_END(quantity); OPT_BEGIN(basis, "B") { - config.value_expr = "c"; + config.amount_expr = "c"; config.total_expr = "C"; } OPT_END(basis); OPT_BEGIN(market, "V") { config.show_revalued = true; - config.value_expr = "v"; + config.amount_expr = "v"; config.total_expr = "V"; } OPT_END(market); @@ -569,27 +569,27 @@ OPT_BEGIN(gain, "G") { config.show_revalued = config.show_revalued_only = true; - config.value_expr = "a"; + config.amount_expr = "a"; config.total_expr = "G"; } OPT_END(gain); OPT_BEGIN(average, "A") { - config.value_expr = "a"; + config.amount_expr = "a"; config.total_expr = "MO"; } OPT_END(average); OPT_BEGIN(deviation, "D") { - config.value_expr = "a"; + config.amount_expr = "a"; config.total_expr = "DMO"; } OPT_END(deviation); OPT_BEGIN(trend, "X") { - config.value_expr = "a"; + config.amount_expr = "a"; config.total_expr = "MDMO"; } OPT_END(trend); OPT_BEGIN(weighted_trend, "Z") { - config.value_expr = "a"; + config.amount_expr = "a"; config.total_expr = "MD(MO/(1+(((m-d)/(30*86400))<0?0:((m-d)/(30*86400)))))"; } OPT_END(weighted_trend); @@ -653,7 +653,7 @@ void export_config() .def_readwrite("equity_format", &config_t::equity_format) .def_readwrite("date_format", &config_t::date_format) .def_readwrite("sort_string", &config_t::sort_string) - .def_readwrite("value_expr", &config_t::value_expr) + .def_readwrite("amount_expr", &config_t::amount_expr) .def_readwrite("total_expr", &config_t::total_expr) .def_readwrite("pricing_leeway", &config_t::pricing_leeway) .def_readwrite("show_collapsed", &config_t::show_collapsed) @@ -44,7 +44,7 @@ struct config_t std::string equity_format; std::string date_format; std::string sort_string; - std::string value_expr; + std::string amount_expr; std::string total_expr; unsigned long pricing_leeway; bool show_collapsed; diff --git a/configure.in b/configure.in index d295b3f8..7788528a 100644 --- a/configure.in +++ b/configure.in @@ -12,6 +12,7 @@ AC_PROG_CXX AC_PROG_MAKE_SET AC_PROG_LIBTOOL AM_PROG_LIBTOOL +#AC_PROG_RANLIB # Checks for libraries. AC_CHECK_LIB([gmp], [__gmpz_add], [], @@ -26,31 +27,48 @@ AC_CHECK_LIB([xmlparse], [XML_ParserCreate], AM_CONDITIONAL(READ_GNUCASH, false)], [-lxmltok]) -AM_PATH_PYTHON(2.2,, :) -AM_CONDITIONAL(HAVE_PYTHON, [test "$PYTHON" != :]) -AC_CACHE_CHECK( - [if boost_python is available], - [boost_python_cpplib_avail], - [boost_python_save_libs=$LIBS - LIBS="-lboost_python $LIBS" - AC_LANG_PUSH(C++) - AC_TRY_COMPILE( - [#include <boost/python.hpp> - using namespace boost::python; - class foo {}; - BOOST_PYTHON_MODULE(samp) { - class_< foo > ("foo") ; - }], - [return 0], - [boost_python_cpplib_avail=true], - [boost_python_cpplib_avail=false]) - AC_LANG_POP - LIBS=$boost_python_save_libs]) -AM_CONDITIONAL(HAVE_BOOST_PYTHON, test x$boost_python_cpplib_avail = xtrue) +AC_ARG_ENABLE(python, + [ --enable-python Turn on Python support], + [case "${enableval}" in + yes) python=true ;; + no) python=false ;; + *) AC_MSG_ERROR(bad value ${enableval} for --enable-python) ;; + esac],[python=false]) +AM_CONDITIONAL(USE_PYTHON, test x$python = xtrue) + +if [test x$python = xtrue ]; then + AM_PATH_PYTHON(2.2,, :) + if [test "$PYTHON" != :]; then + AC_CACHE_CHECK( + [if boost_python is available], + [boost_python_cpplib_avail], + [boost_python_save_libs=$LIBS + LIBS="-lboost_python $LIBS" + AC_LANG_PUSH(C++) + AC_TRY_COMPILE( + [#include <boost/python.hpp> + using namespace boost::python; + class foo {}; + BOOST_PYTHON_MODULE(samp) { + class_< foo > ("foo") ; + }], + [return 0], + [boost_python_cpplib_avail=true], + [boost_python_cpplib_avail=false]) + AC_LANG_POP + LIBS=$boost_python_save_libs]) + AM_CONDITIONAL(HAVE_BOOST_PYTHON, + test x$boost_python_cpplib_avail = xtrue) + else + AM_CONDITIONAL(HAVE_BOOST_PYTHON, false) + fi +else + AM_CONDITIONAL(HAVE_BOOST_PYTHON, false) +fi # Check for options AC_ARG_ENABLE(debug, - [ --enable-debug Turn on debugging], + [ --enable-debug Turn on debugging], [case "${enableval}" in yes) debug=true ;; no) debug=false ;; @@ -35,7 +35,7 @@ std::string partial_account_name(const account_t& account) } std::string format_t::date_format = "%Y/%m/%d"; -value_expr_t * format_t::value_expr = NULL; +value_expr_t * format_t::amount_expr = NULL; value_expr_t * format_t::total_expr = NULL; static struct _init_format { @@ -44,8 +44,8 @@ static struct _init_format { _init_format::~_init_format() { - if (format_t::value_expr) - delete format_t::value_expr; + if (format_t::amount_expr) + delete format_t::amount_expr; if (format_t::total_expr) delete format_t::total_expr; } @@ -164,7 +164,7 @@ element_t * format_t::parse_elements(const std::string& fmt) case 'n': current->type = element_t::ACCOUNT_NAME; break; case 'N': current->type = element_t::ACCOUNT_FULLNAME; break; case 'o': current->type = element_t::OPT_AMOUNT; break; - case 't': current->type = element_t::VALUE; break; + case 't': current->type = element_t::AMOUNT; break; case 'T': current->type = element_t::TOTAL; break; case '|': current->type = element_t::SPACER; break; case '_': current->type = element_t::DEPTH_SPACER; break; @@ -202,13 +202,13 @@ void format_t::format(std::ostream& out, const details_t& details) const out << elem->chars; break; - case element_t::VALUE: + case element_t::AMOUNT: case element_t::TOTAL: case element_t::VALUE_EXPR: { value_expr_t * expr = NULL; switch (elem->type) { - case element_t::VALUE: expr = value_expr; break; - case element_t::TOTAL: expr = total_expr; break; + case element_t::AMOUNT: expr = amount_expr; break; + case element_t::TOTAL: expr = total_expr; break; case element_t::VALUE_EXPR: expr = elem->val_expr; break; default: @@ -24,7 +24,7 @@ struct element_t ACCOUNT_NAME, ACCOUNT_FULLNAME, OPT_AMOUNT, - VALUE, + AMOUNT, TOTAL, SPACER, DEPTH_SPACER @@ -55,7 +55,7 @@ struct format_t element_t * elements; static std::string date_format; - static value_expr_t * value_expr; + static value_expr_t * amount_expr; static value_expr_t * total_expr; format_t() : elements(NULL) {} @@ -77,9 +77,9 @@ struct format_t void format(std::ostream& out, const details_t& details) const; - static void compute_value(value_t& result, const details_t& details) { - if (value_expr) - value_expr->compute(result, details); + static void compute_amount(value_t& result, const details_t& details) { + if (amount_expr) + amount_expr->compute(result, details); } static void compute_total(value_t& result, const details_t& details) { diff --git a/ledger.texi b/ledger.texi index b83bcbf0..bf0dc6a7 100644 --- a/ledger.texi +++ b/ledger.texi @@ -2115,6 +2115,29 @@ Using the ledger library as a Python module Setting up custom initialization using Python @end enumerate +Note that this feature, while functional, is still under development. +It will not be documented until it has been fully proven, probably in +the next version of ledger. For now, if you wish to make this of this +functionality and are willing to debug problems that come up, pass the +option @samp{--enable-python} to configure, and contact the author via +email. + +Here is a quick example of text that could be pasted into a ledger +file, to generate a customized amount's column in the register report: + +@example +;; If Python support is enabled, then the following code may be +;; uncomment to demonstrate a rather useless example. + +!python +from ledger import * +def foo(d, val): + return d.xact.amount + val +!end + +--amount-expr 'foo'@{$100@} +@end example + @c Page published by Emacs Muse ends here @contents @bye diff --git a/pyamounts.cc b/pyamounts.cc deleted file mode 100644 index a8b982cc..00000000 --- a/pyamounts.cc +++ /dev/null @@ -1,13 +0,0 @@ -#include <boost/python.hpp> - -using namespace boost::python; - -void export_amount(); -void export_balance(); -void export_value(); - -BOOST_PYTHON_MODULE(amounts) { - export_amount(); - export_balance(); - export_value(); -} @@ -1,14 +1,3 @@ -;; If Python support is enabled, then the following code may be -;; uncomment to demonstrate a rather useless example. - -; !python -; from ledger import * -; def foo(d, val): -; return d.xact.amount + val -; !end -; -; --value-expr 'foo'{$100} - 2004/05/01 Checking balance Assets:Checking $500.00 Equity:Opening Balances @@ -20,7 +9,3 @@ 2004/05/29 Restaurant Expenses:Food $50.00 Liabilities:MasterCard - -2004/09/16 Foo - Assets:Foo $50 - Income:Bar @@ -4,17 +4,6 @@ from distutils.core import setup, Extension libs = ["ledger", "boost_python", "gmp", "pcre", "xmlparse", "xmltok"] -#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', 1)], -# libraries = libs)]) - setup(name = "Ledger", version = "2.0b", description = "Ledger Accounting Tool", @@ -114,8 +114,8 @@ void value_expr_t::compute(value_t& result, const details_t& details) const break; case VALUE_EXPR: - assert(format_t::value_expr); - format_t::value_expr->compute(result, details); + assert(format_t::amount_expr); + format_t::amount_expr->compute(result, details); break; case TOTAL_EXPR: assert(format_t::total_expr); |