The --download option is now fully restored

This commit is contained in:
John Wiegley 2009-06-26 16:52:41 +01:00
parent 1fad2ec7c1
commit 4574c30fcf
11 changed files with 46 additions and 35 deletions

View file

@ -30,6 +30,7 @@ libledger_util_la_LDFLAGS = -release $(VERSION).0
libledger_math_la_SOURCES = \ libledger_math_la_SOURCES = \
src/value.cc \ src/value.cc \
src/balance.cc \ src/balance.cc \
src/quotes.cc \
src/pool.cc \ src/pool.cc \
src/annotate.cc \ src/annotate.cc \
src/commodity.cc \ src/commodity.cc \
@ -67,7 +68,6 @@ libledger_data_la_CPPFLAGS = $(lib_cppflags)
libledger_data_la_LDFLAGS = -release $(VERSION).0 libledger_data_la_LDFLAGS = -release $(VERSION).0
libledger_report_la_SOURCES = \ libledger_report_la_SOURCES = \
src/quotes.cc \
src/stats.cc \ src/stats.cc \
src/generate.cc \ src/generate.cc \
src/derive.cc \ src/derive.cc \
@ -98,6 +98,7 @@ pkginclude_HEADERS = \
src/commodity.h \ src/commodity.h \
src/annotate.h \ src/annotate.h \
src/pool.h \ src/pool.h \
src/quotes.h \
src/balance.h \ src/balance.h \
src/value.h \ src/value.h \
\ \
@ -130,7 +131,6 @@ pkginclude_HEADERS = \
src/stats.h \ src/stats.h \
src/output.h \ src/output.h \
src/emacs.h \ src/emacs.h \
src/quotes.h \
\ \
src/global.h \ src/global.h \
\ \

View file

@ -390,8 +390,8 @@ void related_posts::flush()
void changed_value_posts::flush() void changed_value_posts::flush()
{ {
if (last_post && last_post->date() <= report.terminus) { if (last_post && last_post->date() <= report.terminus.date()) {
output_revaluation(last_post, report.terminus); output_revaluation(last_post, report.terminus.date());
last_post = NULL; last_post = NULL;
} }
item_handler<post_t>::flush(); item_handler<post_t>::flush();

View file

@ -507,8 +507,8 @@ void global_scope_t::normalize_report_options(const string& verb)
// settings that may be there. // settings that may be there.
if (rep.HANDLED(exchange_) && if (rep.HANDLED(exchange_) &&
rep.HANDLER(exchange_).str().find('=') != string::npos) { rep.HANDLER(exchange_).str().find('=') != string::npos) {
value_t(0L).exchange_commodities(rep.HANDLER(exchange_).str(), value_t(0L).exchange_commodities(rep.HANDLER(exchange_).str(), true,
true, datetime_t(rep.terminus)); rep.terminus);
} }
long cols = 0; long cols = 0;

View file

@ -75,7 +75,13 @@ void interactive_t::verify_arguments() const
break; break;
case 'd': case 'd':
label = _("a date"); label = _("a date");
wrong_arg = ! next_arg->is_date(); wrong_arg = (! next_arg->is_date() &&
! next_arg->is_datetime());
break;
case 't':
label = _("a date/time");
wrong_arg = (! next_arg->is_date() &&
! next_arg->is_datetime());
break; break;
case 'i': case 'i':
case 'l': case 'l':
@ -106,11 +112,6 @@ void interactive_t::verify_arguments() const
label = _("a string"); label = _("a string");
wrong_arg = ! next_arg->is_string(); wrong_arg = ! next_arg->is_string();
break; break;
case 't':
label = _("a date or time");
wrong_arg = (! next_arg->is_date() &&
! next_arg->is_datetime());
break;
case 'v': case 'v':
label = _("any value"); label = _("any value");
wrong_arg = false; wrong_arg = false;

View file

@ -35,12 +35,14 @@
#include "commodity.h" #include "commodity.h"
#include "annotate.h" #include "annotate.h"
#include "pool.h" #include "pool.h"
#include "quotes.h"
namespace ledger { namespace ledger {
commodity_pool_t::commodity_pool_t() commodity_pool_t::commodity_pool_t()
: default_commodity(NULL), keep_base(false), : default_commodity(NULL), keep_base(false),
quote_leeway(86400), get_quotes(false) quote_leeway(86400), get_quotes(false),
get_commodity_quote(commodity_quote_from_script)
{ {
TRACE_CTOR(commodity_pool_t, ""); TRACE_CTOR(commodity_pool_t, "");
null_commodity = create(""); null_commodity = create("");
@ -311,8 +313,11 @@ optional<price_point_t> commodity_pool_t::parse_price_directive(char * line)
point.price.parse(symbol_and_price); point.price.parse(symbol_and_price);
VERIFY(point.price.valid()); VERIFY(point.price.valid());
DEBUG("commodity.download", "Looking up symbol: " << symbol);
if (commodity_t * commodity = if (commodity_t * commodity =
amount_t::current_pool->find_or_create(symbol)) { amount_t::current_pool->find_or_create(symbol)) {
DEBUG("commodity.download", "Adding price for " << symbol << ": "
<< point.when << " " << point.price);
commodity->add_price(point.when, point.price, true); commodity->add_price(point.when, point.price, true);
commodity->add_flags(COMMODITY_KNOWN); commodity->add_flags(COMMODITY_KNOWN);
return point; return point;

View file

@ -86,10 +86,9 @@ public:
long quote_leeway; // --leeway= long quote_leeway; // --leeway=
bool get_quotes; // --download bool get_quotes; // --download
public:
function<optional<price_point_t> function<optional<price_point_t>
(const commodity_t& commodity, (commodity_t& commodity, const optional<commodity_t&>& in_terms_of)>
const optional<commodity_t&>& in_terms_of)> get_commodity_quote; get_commodity_quote;
explicit commodity_pool_t(); explicit commodity_pool_t();

View file

@ -94,10 +94,17 @@ commodity_quote_from_script(commodity_t& commodity,
return point; return point;
} }
} else { } else {
throw_(std::runtime_error, DEBUG("commodity.download",
_("Failed to download price for '%1' (command: \"getquote %2 %3\")") "Failed to download price for '" << commodity.symbol() <<
<< commodity.symbol() << commodity.symbol() "' (command: \"getquote " << commodity.symbol() <<
<< (exchange_commodity ? exchange_commodity->symbol() : "''")); " " << (exchange_commodity ?
exchange_commodity->symbol() : "''") << "\")");
// Don't try to download this commodity again.
// jww (2009-06-24): This flag should be removed in order to try again
// when using a GUI.
commodity.add_flags(COMMODITY_NOMARKET);
} }
return none; return none;
} }

View file

@ -49,7 +49,8 @@
namespace ledger { namespace ledger {
optional<price_point_t> optional<price_point_t>
commodity_quote_from_script(const optional<commodity_t&>& exchange_commodity); commodity_quote_from_script(commodity_t& commodity,
const optional<commodity_t&>& exchange_commodity);
} // namespace ledger } // namespace ledger

View file

@ -259,9 +259,11 @@ value_t report_t::fn_join(call_scope_t& args)
return string_value(out.str()); return string_value(out.str());
} }
value_t report_t::fn_format_date(call_scope_t& args) value_t report_t::fn_format_date(call_scope_t& scope)
{ {
return string_value(format_date(args[0].to_date(), args[1].to_string())); interactive_t args(scope, "ds");
return string_value(format_date(args.get<date_t>(0),
args.get<string>(1)));
} }
value_t report_t::fn_ansify_if(call_scope_t& scope) value_t report_t::fn_ansify_if(call_scope_t& scope)
@ -752,7 +754,7 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
else if (is_eq(p, "display_total")) else if (is_eq(p, "display_total"))
return MAKE_FUNCTOR(report_t::fn_display_total); return MAKE_FUNCTOR(report_t::fn_display_total);
else if (is_eq(p, "date")) else if (is_eq(p, "date"))
return MAKE_FUNCTOR(report_t::fn_today); return MAKE_FUNCTOR(report_t::fn_now);
break; break;
case 'f': case 'f':
@ -789,10 +791,8 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
case 'n': case 'n':
if (is_eq(p, "null")) if (is_eq(p, "null"))
return WRAP_FUNCTOR(fn_null); return WRAP_FUNCTOR(fn_null);
#if 0
else if (is_eq(p, "now")) else if (is_eq(p, "now"))
return MAKE_FUNCTOR(report_t::fn_now); return MAKE_FUNCTOR(report_t::fn_now);
#endif
break; break;
case 'o': case 'o':

View file

@ -121,11 +121,11 @@ public:
#define BUDGET_BUDGETED 0x01 #define BUDGET_BUDGETED 0x01
#define BUDGET_UNBUDGETED 0x02 #define BUDGET_UNBUDGETED 0x02
date_t terminus; datetime_t terminus;
uint_least8_t budget_flags; uint_least8_t budget_flags;
explicit report_t(session_t& _session) explicit report_t(session_t& _session)
: session(_session), terminus(CURRENT_DATE()), : session(_session), terminus(CURRENT_TIME()),
budget_flags(BUDGET_NO_BUDGET) {} budget_flags(BUDGET_NO_BUDGET) {}
virtual ~report_t() { virtual ~report_t() {
@ -159,14 +159,12 @@ public:
value_t fn_ansify_if(call_scope_t& scope); value_t fn_ansify_if(call_scope_t& scope);
value_t fn_percent(call_scope_t& scope); value_t fn_percent(call_scope_t& scope);
#if 0
value_t fn_now(call_scope_t&) { value_t fn_now(call_scope_t&) {
return CURRENT_TIME();
}
#endif
value_t fn_today(call_scope_t&) {
return terminus; return terminus;
} }
value_t fn_today(call_scope_t&) {
return terminus.date();
}
value_t fn_options(call_scope_t&) { value_t fn_options(call_scope_t&) {
return value_t(static_cast<scope_t *>(this)); return value_t(static_cast<scope_t *>(this));
@ -484,7 +482,7 @@ public:
"date<[" + to_iso_extended_string(*interval.start) + "]"; "date<[" + to_iso_extended_string(*interval.start) + "]";
parent->HANDLER(limit_).on(string("--end"), predicate); parent->HANDLER(limit_).on(string("--end"), predicate);
parent->terminus = *interval.start; parent->terminus = datetime_t(*interval.start);
}); });
OPTION(report_t, equity); OPTION(report_t, equity);

View file

@ -1,4 +1,4 @@
bal --end 2008/12/31 -JV bal Equities bal --end 2008/12/31 -JV Equities
<<< <<<
2008/01/01 * Purchase Apple shares 2008/01/01 * Purchase Apple shares
Equities 1000 AAPL @ $2 Equities 1000 AAPL @ $2