using main.py is now only 50% slower than using main.cc
This commit is contained in:
parent
23799b5f4e
commit
5d99b1e241
4 changed files with 57 additions and 24 deletions
|
|
@ -45,7 +45,6 @@ config_t::config_t()
|
|||
use_cache = false;
|
||||
cache_dirty = false;
|
||||
sort_order = NULL;
|
||||
output_stream = NULL;
|
||||
}
|
||||
|
||||
static void
|
||||
|
|
@ -219,11 +218,6 @@ void config_t::process_options(const std::string& command,
|
|||
pricing_leeway,
|
||||
cache_dirty);
|
||||
|
||||
// Configure the output stream
|
||||
|
||||
if (! output_stream && ! output_file.empty())
|
||||
output_stream = new std::ofstream(output_file.c_str());
|
||||
|
||||
// Parse the interval specifier, if provided
|
||||
|
||||
if (! report_interval && ! interval_text.empty()) {
|
||||
|
|
|
|||
3
config.h
3
config.h
|
|
@ -61,7 +61,6 @@ struct config_t
|
|||
format_t nformat;
|
||||
|
||||
value_expr_t * sort_order;
|
||||
std::ostream * output_stream;
|
||||
|
||||
config_t();
|
||||
config_t(const config_t&) {
|
||||
|
|
@ -71,8 +70,6 @@ struct config_t
|
|||
~config_t() {
|
||||
if (sort_order)
|
||||
delete sort_order;
|
||||
if (output_stream)
|
||||
delete output_stream;
|
||||
}
|
||||
|
||||
void process_options(const std::string& command,
|
||||
|
|
|
|||
26
main.cc
26
main.cc
|
|
@ -237,10 +237,16 @@ int parse_and_report(int argc, char * argv[], char * envp[])
|
|||
return 1;
|
||||
}
|
||||
|
||||
// Walk the entries based on the report type and the options
|
||||
// Configure the output stream
|
||||
|
||||
TIMER_START(report_gen);
|
||||
|
||||
std::ostream * out = &std::cout;
|
||||
if (! config.output_file.empty())
|
||||
out = new std::ofstream(config.output_file.c_str());
|
||||
|
||||
// Walk the entries based on the report type and the options
|
||||
|
||||
item_handler<transaction_t> * formatter;
|
||||
std::list<item_handler<transaction_t> *> formatter_ptrs;
|
||||
|
||||
|
|
@ -248,9 +254,7 @@ int parse_and_report(int argc, char * argv[], char * envp[])
|
|||
formatter = new set_account_value;
|
||||
formatter = chain_formatters(command, formatter, formatter_ptrs);
|
||||
} else {
|
||||
std::ostream& out(config.output_stream ?
|
||||
*config.output_stream : std::cout);
|
||||
formatter = new format_transactions(out, config.format, config.nformat);
|
||||
formatter = new format_transactions(*out, config.format, config.nformat);
|
||||
formatter = chain_formatters(command, formatter, formatter_ptrs);
|
||||
}
|
||||
|
||||
|
|
@ -263,11 +267,8 @@ int parse_and_report(int argc, char * argv[], char * envp[])
|
|||
|
||||
// For the balance and equity reports, output the sum totals.
|
||||
|
||||
std::ostream& out(config.output_stream ?
|
||||
*config.output_stream : std::cout);
|
||||
|
||||
if (command == "b") {
|
||||
format_account acct_formatter(out, config.format,
|
||||
format_account acct_formatter(*out, config.format,
|
||||
config.display_predicate);
|
||||
sum_accounts(*journal->master);
|
||||
walk_accounts(*journal->master, acct_formatter, config.sort_order);
|
||||
|
|
@ -277,13 +278,13 @@ int parse_and_report(int argc, char * argv[], char * envp[])
|
|||
ACCT_DATA(journal->master)->value = ACCT_DATA(journal->master)->total;
|
||||
|
||||
if (ACCT_DATA(journal->master)->dflags & ACCOUNT_TO_DISPLAY) {
|
||||
out << "--------------------\n";
|
||||
config.format.format(out, details_t(*journal->master));
|
||||
*out << "--------------------\n";
|
||||
config.format.format(*out, details_t(*journal->master));
|
||||
}
|
||||
}
|
||||
}
|
||||
else if (command == "E") {
|
||||
format_equity acct_formatter(out, config.format, config.nformat,
|
||||
format_equity acct_formatter(*out, config.format, config.nformat,
|
||||
config.display_predicate);
|
||||
sum_accounts(*journal->master);
|
||||
walk_accounts(*journal->master, acct_formatter, config.sort_order);
|
||||
|
|
@ -291,6 +292,9 @@ int parse_and_report(int argc, char * argv[], char * envp[])
|
|||
}
|
||||
|
||||
#if DEBUG_LEVEL >= BETA
|
||||
if (! config.output_file.empty())
|
||||
delete out;
|
||||
|
||||
for (std::list<item_handler<transaction_t> *>::iterator i
|
||||
= formatter_ptrs.begin();
|
||||
i != formatter_ptrs.end();
|
||||
|
|
|
|||
46
main.py
46
main.py
|
|
@ -1,9 +1,21 @@
|
|||
#!/usr/bin/env python
|
||||
|
||||
# Ledger, the command-line accounting tool
|
||||
#
|
||||
# Copyright (c) 2003-2004, New Artisans LLC. All rights reserved.
|
||||
#
|
||||
# This program is made available under the terms of the BSD Public
|
||||
# License. See the LICENSE file included with the distribution for
|
||||
# details and disclaimer.
|
||||
#
|
||||
# This script provides a Python front-end to the ledger library, which
|
||||
# replicates the functionality of the C++ front-end found in main.cc.
|
||||
# It is provided as an alternative to main.cc, or as a starting point
|
||||
# for creating custom front-ends based on the Ledger module. See the
|
||||
# documentation for API references, and how to use that module.
|
||||
|
||||
import sys
|
||||
import os
|
||||
import time
|
||||
import re
|
||||
|
||||
from ledger import *
|
||||
|
||||
|
|
@ -12,7 +24,7 @@ journal = Journal ()
|
|||
add_config_option_handlers ()
|
||||
|
||||
args = process_arguments (sys.argv[1:])
|
||||
config.use_cache = len (config.data_file) > 0
|
||||
config.use_cache = not config.data_file
|
||||
process_environment (os.environ, "LEDGER_")
|
||||
|
||||
if os.environ.has_key ("LEDGER"):
|
||||
|
|
@ -100,7 +112,10 @@ class FormatTransaction (TransactionHandler):
|
|||
self.output.write(self.formatter.format(xact))
|
||||
self.last_entry = xact.entry
|
||||
|
||||
handler = FormatTransaction()
|
||||
if command == "b" or command == "E":
|
||||
handler = SetAccountValue()
|
||||
else:
|
||||
handler = FormatTransaction()
|
||||
|
||||
if not (command == "b" or command == "E"):
|
||||
if config.display_predicate:
|
||||
|
|
@ -140,5 +155,28 @@ else:
|
|||
|
||||
handler.flush ()
|
||||
|
||||
#if command == "b":
|
||||
# format_account acct_formatter(out, config.format,
|
||||
# config.display_predicate);
|
||||
# sum_accounts(*journal->master);
|
||||
# walk_accounts(*journal->master, acct_formatter, config.sort_order);
|
||||
# acct_formatter.flush();
|
||||
#
|
||||
# if (journal->master->data) {
|
||||
# ACCT_DATA(journal->master)->value = ACCT_DATA(journal->master)->total;
|
||||
#
|
||||
# if (ACCT_DATA(journal->master)->dflags & ACCOUNT_TO_DISPLAY) {
|
||||
# out << "--------------------\n";
|
||||
# config.format.format(out, details_t(*journal->master));
|
||||
# }
|
||||
# }
|
||||
#elif command == "E":
|
||||
# format_equity acct_formatter(out, config.format, config.nformat,
|
||||
# config.display_predicate);
|
||||
# sum_accounts(*journal->master);
|
||||
# walk_accounts(*journal->master, acct_formatter, config.sort_order);
|
||||
# acct_formatter.flush();
|
||||
# }
|
||||
|
||||
if config.use_cache and config.cache_dirty and config.cache_file:
|
||||
write_binary_journal(config.cache_file, journal);
|
||||
|
|
|
|||
Loading…
Add table
Reference in a new issue