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

View file

@ -390,8 +390,8 @@ void related_posts::flush()
void changed_value_posts::flush()
{
if (last_post && last_post->date() <= report.terminus) {
output_revaluation(last_post, report.terminus);
if (last_post && last_post->date() <= report.terminus.date()) {
output_revaluation(last_post, report.terminus.date());
last_post = NULL;
}
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.
if (rep.HANDLED(exchange_) &&
rep.HANDLER(exchange_).str().find('=') != string::npos) {
value_t(0L).exchange_commodities(rep.HANDLER(exchange_).str(),
true, datetime_t(rep.terminus));
value_t(0L).exchange_commodities(rep.HANDLER(exchange_).str(), true,
rep.terminus);
}
long cols = 0;

View file

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

View file

@ -35,12 +35,14 @@
#include "commodity.h"
#include "annotate.h"
#include "pool.h"
#include "quotes.h"
namespace ledger {
commodity_pool_t::commodity_pool_t()
: 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, "");
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);
VERIFY(point.price.valid());
DEBUG("commodity.download", "Looking up symbol: " << symbol);
if (commodity_t * commodity =
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_flags(COMMODITY_KNOWN);
return point;

View file

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

View file

@ -94,10 +94,17 @@ commodity_quote_from_script(commodity_t& commodity,
return point;
}
} else {
throw_(std::runtime_error,
_("Failed to download price for '%1' (command: \"getquote %2 %3\")")
<< commodity.symbol() << commodity.symbol()
<< (exchange_commodity ? exchange_commodity->symbol() : "''"));
DEBUG("commodity.download",
"Failed to download price for '" << commodity.symbol() <<
"' (command: \"getquote " << 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;
}

View file

@ -49,7 +49,8 @@
namespace ledger {
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

View file

@ -259,9 +259,11 @@ value_t report_t::fn_join(call_scope_t& args)
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)
@ -752,7 +754,7 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
else if (is_eq(p, "display_total"))
return MAKE_FUNCTOR(report_t::fn_display_total);
else if (is_eq(p, "date"))
return MAKE_FUNCTOR(report_t::fn_today);
return MAKE_FUNCTOR(report_t::fn_now);
break;
case 'f':
@ -789,10 +791,8 @@ expr_t::ptr_op_t report_t::lookup(const string& name)
case 'n':
if (is_eq(p, "null"))
return WRAP_FUNCTOR(fn_null);
#if 0
else if (is_eq(p, "now"))
return MAKE_FUNCTOR(report_t::fn_now);
#endif
break;
case 'o':

View file

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