summaryrefslogtreecommitdiff
path: root/config.cc
diff options
context:
space:
mode:
authorJohn Wiegley <johnw@newartisans.com>2004-09-14 17:34:48 -0400
committerJohn Wiegley <johnw@newartisans.com>2004-09-14 17:34:48 -0400
commit0c890de44bfd33060c36c7b1f182079982232cf7 (patch)
treeaa64bc10c7c36d0900e3f34558f34353c1402ea1 /config.cc
parentf2162bf7ee556c5d46a3a48a4d93bb892041b067 (diff)
downloadfork-ledger-0c890de44bfd33060c36c7b1f182079982232cf7.tar.gz
fork-ledger-0c890de44bfd33060c36c7b1f182079982232cf7.tar.bz2
fork-ledger-0c890de44bfd33060c36c7b1f182079982232cf7.zip
main.py now implements nearly all the functionality of main.cc
Diffstat (limited to 'config.cc')
-rw-r--r--config.cc73
1 files changed, 73 insertions, 0 deletions
diff --git a/config.cc b/config.cc
index 108a9e5d..a92d6ab2 100644
--- a/config.cc
+++ b/config.cc
@@ -284,6 +284,69 @@ void config_t::process_options(const std::string& command,
nformat.reset(next_lines_format);
}
+void parse_ledger_data(journal_t * journal,
+ parser_t * text_parser,
+ parser_t * cache_parser)
+{
+ int entry_count = 0;
+
+ if (! config.init_file.empty()) {
+ if (parse_journal_file(config.init_file, journal))
+ throw error("Entries not allowed in initialization file");
+ journal->sources.pop_front(); // remove init file
+ }
+
+ if (cache_parser && config.use_cache &&
+ ! config.cache_file.empty() && ! config.data_file.empty()) {
+ config.cache_dirty = true;
+ if (access(config.cache_file.c_str(), R_OK) != -1) {
+ std::ifstream stream(config.cache_file.c_str());
+ if (cache_parser->test(stream)) {
+ entry_count += cache_parser->parse(stream, journal, NULL,
+ &config.data_file);
+ if (entry_count > 0)
+ config.cache_dirty = false;
+ }
+ }
+ }
+
+ if (entry_count == 0 && ! config.data_file.empty()) {
+ account_t * account = NULL;
+ if (! config.account.empty())
+ account = journal->find_account(config.account);
+
+ if (config.data_file == "-") {
+ config.use_cache = false;
+ entry_count += parse_journal(std::cin, journal, account);
+ } else {
+ entry_count += parse_journal_file(config.data_file, journal, account);
+ }
+
+ if (! config.price_db.empty())
+ if (parse_journal_file(config.price_db, journal))
+ throw error("Entries not allowed in price history file");
+ }
+
+ for (strings_list::iterator i = config.price_settings.begin();
+ i != config.price_settings.end();
+ i++) {
+ std::string conversion = "C ";
+ conversion += *i;
+ int i = conversion.find('=');
+ if (i != -1) {
+ conversion[i] = ' ';
+ std::istringstream stream(conversion);
+ text_parser->parse(stream, journal, journal->master);
+ }
+ }
+
+ if (entry_count == 0)
+ throw error("Please specify ledger file using -f,"
+ " or LEDGER_FILE environment variable.");
+
+ VALIDATE(journal->valid());
+}
+
static void show_version(std::ostream& out)
{
out
@@ -644,6 +707,14 @@ void py_add_config_option_handlers()
add_other_option_handlers(config_options);
}
+BOOST_PYTHON_FUNCTION_OVERLOADS(parse_ledger_data_overloads,
+ parse_ledger_data, 2, 3)
+
+void py_option_help()
+{
+ option_help(std::cout);
+}
+
void export_config()
{
class_< config_t > ("Config")
@@ -691,6 +762,8 @@ void export_config()
scope().attr("config") = ptr(&config);
+ def("option_help", py_option_help);
+ def("parse_ledger_data", parse_ledger_data, parse_ledger_data_overloads());
def("add_config_option_handlers", py_add_config_option_handlers);
}