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;
|
use_cache = false;
|
||||||
cache_dirty = false;
|
cache_dirty = false;
|
||||||
sort_order = NULL;
|
sort_order = NULL;
|
||||||
output_stream = NULL;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
static void
|
static void
|
||||||
|
|
@ -219,11 +218,6 @@ void config_t::process_options(const std::string& command,
|
||||||
pricing_leeway,
|
pricing_leeway,
|
||||||
cache_dirty);
|
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
|
// Parse the interval specifier, if provided
|
||||||
|
|
||||||
if (! report_interval && ! interval_text.empty()) {
|
if (! report_interval && ! interval_text.empty()) {
|
||||||
|
|
|
||||||
3
config.h
3
config.h
|
|
@ -61,7 +61,6 @@ struct config_t
|
||||||
format_t nformat;
|
format_t nformat;
|
||||||
|
|
||||||
value_expr_t * sort_order;
|
value_expr_t * sort_order;
|
||||||
std::ostream * output_stream;
|
|
||||||
|
|
||||||
config_t();
|
config_t();
|
||||||
config_t(const config_t&) {
|
config_t(const config_t&) {
|
||||||
|
|
@ -71,8 +70,6 @@ struct config_t
|
||||||
~config_t() {
|
~config_t() {
|
||||||
if (sort_order)
|
if (sort_order)
|
||||||
delete sort_order;
|
delete sort_order;
|
||||||
if (output_stream)
|
|
||||||
delete output_stream;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void process_options(const std::string& command,
|
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;
|
return 1;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Walk the entries based on the report type and the options
|
// Configure the output stream
|
||||||
|
|
||||||
TIMER_START(report_gen);
|
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;
|
item_handler<transaction_t> * formatter;
|
||||||
std::list<item_handler<transaction_t> *> formatter_ptrs;
|
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 = new set_account_value;
|
||||||
formatter = chain_formatters(command, formatter, formatter_ptrs);
|
formatter = chain_formatters(command, formatter, formatter_ptrs);
|
||||||
} else {
|
} else {
|
||||||
std::ostream& out(config.output_stream ?
|
formatter = new format_transactions(*out, config.format, config.nformat);
|
||||||
*config.output_stream : std::cout);
|
|
||||||
formatter = new format_transactions(out, config.format, config.nformat);
|
|
||||||
formatter = chain_formatters(command, formatter, formatter_ptrs);
|
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.
|
// For the balance and equity reports, output the sum totals.
|
||||||
|
|
||||||
std::ostream& out(config.output_stream ?
|
|
||||||
*config.output_stream : std::cout);
|
|
||||||
|
|
||||||
if (command == "b") {
|
if (command == "b") {
|
||||||
format_account acct_formatter(out, config.format,
|
format_account acct_formatter(*out, config.format,
|
||||||
config.display_predicate);
|
config.display_predicate);
|
||||||
sum_accounts(*journal->master);
|
sum_accounts(*journal->master);
|
||||||
walk_accounts(*journal->master, acct_formatter, config.sort_order);
|
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;
|
ACCT_DATA(journal->master)->value = ACCT_DATA(journal->master)->total;
|
||||||
|
|
||||||
if (ACCT_DATA(journal->master)->dflags & ACCOUNT_TO_DISPLAY) {
|
if (ACCT_DATA(journal->master)->dflags & ACCOUNT_TO_DISPLAY) {
|
||||||
out << "--------------------\n";
|
*out << "--------------------\n";
|
||||||
config.format.format(out, details_t(*journal->master));
|
config.format.format(*out, details_t(*journal->master));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else if (command == "E") {
|
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);
|
config.display_predicate);
|
||||||
sum_accounts(*journal->master);
|
sum_accounts(*journal->master);
|
||||||
walk_accounts(*journal->master, acct_formatter, config.sort_order);
|
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 DEBUG_LEVEL >= BETA
|
||||||
|
if (! config.output_file.empty())
|
||||||
|
delete out;
|
||||||
|
|
||||||
for (std::list<item_handler<transaction_t> *>::iterator i
|
for (std::list<item_handler<transaction_t> *>::iterator i
|
||||||
= formatter_ptrs.begin();
|
= formatter_ptrs.begin();
|
||||||
i != formatter_ptrs.end();
|
i != formatter_ptrs.end();
|
||||||
|
|
|
||||||
46
main.py
46
main.py
|
|
@ -1,9 +1,21 @@
|
||||||
#!/usr/bin/env python
|
#!/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 sys
|
||||||
import os
|
import os
|
||||||
import time
|
|
||||||
import re
|
|
||||||
|
|
||||||
from ledger import *
|
from ledger import *
|
||||||
|
|
||||||
|
|
@ -12,7 +24,7 @@ journal = Journal ()
|
||||||
add_config_option_handlers ()
|
add_config_option_handlers ()
|
||||||
|
|
||||||
args = process_arguments (sys.argv[1:])
|
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_")
|
process_environment (os.environ, "LEDGER_")
|
||||||
|
|
||||||
if os.environ.has_key ("LEDGER"):
|
if os.environ.has_key ("LEDGER"):
|
||||||
|
|
@ -100,7 +112,10 @@ class FormatTransaction (TransactionHandler):
|
||||||
self.output.write(self.formatter.format(xact))
|
self.output.write(self.formatter.format(xact))
|
||||||
self.last_entry = xact.entry
|
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 not (command == "b" or command == "E"):
|
||||||
if config.display_predicate:
|
if config.display_predicate:
|
||||||
|
|
@ -140,5 +155,28 @@ else:
|
||||||
|
|
||||||
handler.flush ()
|
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:
|
if config.use_cache and config.cache_dirty and config.cache_file:
|
||||||
write_binary_journal(config.cache_file, journal);
|
write_binary_journal(config.cache_file, journal);
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue