diff options
author | John Wiegley <johnw@newartisans.com> | 2012-03-05 21:48:45 -0600 |
---|---|---|
committer | John Wiegley <johnw@newartisans.com> | 2012-03-05 21:48:45 -0600 |
commit | 59a16e59ee2e684f1d5292fe78ef94464a935d73 (patch) | |
tree | d12112cf3a6c739a411366f44dd8da71d26a03c8 | |
parent | 97dbf379d5e44c80c748483a688502b1cec8f075 (diff) | |
download | fork-ledger-59a16e59ee2e684f1d5292fe78ef94464a935d73.tar.gz fork-ledger-59a16e59ee2e684f1d5292fe78ef94464a935d73.tar.bz2 fork-ledger-59a16e59ee2e684f1d5292fe78ef94464a935d73.zip |
Simplified Python import in a journal file
-rw-r--r-- | src/textual.cc | 35 | ||||
-rw-r--r-- | test/baseline/dir-import_py.test | 23 |
2 files changed, 51 insertions, 7 deletions
diff --git a/src/textual.cc b/src/textual.cc index 7bf67347..b1df1fb8 100644 --- a/src/textual.cc +++ b/src/textual.cc @@ -164,9 +164,8 @@ namespace { void assert_directive(char * line); void check_directive(char * line); -#if defined(HAVE_BOOST_PYTHON) + void import_directive(char * line); void python_directive(char * line); -#endif post_t * parse_post(char * line, std::streamsize len, @@ -1114,6 +1113,14 @@ void instance_t::comment_directive(char * line) } #if defined(HAVE_BOOST_PYTHON) + +void instance_t::import_directive(char * line) +{ + string module_name(line); + trim(module_name); + python_session->import_option(module_name); +} + void instance_t::python_directive(char * line) { std::ostringstream script; @@ -1153,6 +1160,21 @@ void instance_t::python_directive(char * line) ("journal", python::object(python::ptr(context.journal))); python_session->eval(script.str(), python_interpreter_t::PY_EVAL_MULTI); } + +#else + +void instance_t::import_directive(char *) +{ + throw_(parse_error, + _("'python' directive seen, but Python support is missing")); +} + +void instance_t::python_directive(char *) +{ + throw_(parse_error, + _("'import' directive seen, but Python support is missing")); +} + #endif // HAVE_BOOST_PYTHON bool instance_t::general_directive(char * line) @@ -1232,6 +1254,10 @@ bool instance_t::general_directive(char * line) include_directive(arg); return true; } + else if (std::strcmp(p, "import") == 0) { + import_directive(arg); + return true; + } break; case 'p': @@ -1240,12 +1266,7 @@ bool instance_t::general_directive(char * line) return true; } else if (std::strcmp(p, "python") == 0) { -#if defined(HAVE_BOOST_PYTHON) python_directive(arg); -#else - throw_(parse_error, - _("'python' directive seen, but Python support is missing")); -#endif return true; } break; diff --git a/test/baseline/dir-import_py.test b/test/baseline/dir-import_py.test new file mode 100644 index 00000000..ee9f6001 --- /dev/null +++ b/test/baseline/dir-import_py.test @@ -0,0 +1,23 @@ +import os + +tag PATH + check os.path.isfile(value) + +2012-02-29 KFC + ; PATH: test/baseline/feat-import_py.test + Expenses:Food $20 + Assets:Cash + +2012-02-29 KFC + ; PATH: test/baseline/feat-import_noexist.test + Expenses:Food $20 + Assets:Cash + +test reg +12-Feb-29 KFC Expenses:Food $20 $20 + Assets:Cash $-20 0 +12-Feb-29 KFC Expenses:Food $20 $20 + Assets:Cash $-20 0 +__ERROR__ +Warning: "$sourcepath/test/baseline/dir-import_py.test", line 14: Metadata check failed for (PATH: test/baseline/feat-import_noexist.test): ((os.path).isfile(value)) +end test |