mirror of https://github.com/aria2/aria2
2008-04-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
Added --quiet option to make aria2 quiet (no console output). --quiet option is tagged with ADVANCED. * src/HelpItemFactory.cc * src/LogFactory.cc * src/LogFactory.h * src/MultiUrlRequestInfo.cc * src/MultiUrlRequestInfo.h * src/NullStatCalc.h: New class. This class prints nothing. * src/OptionHandlerFactory.cc * src/main.cc * src/option_processing.cc * src/prefs.h * src/usage_text.hpull/1/head
parent
9c6904f8d4
commit
c87fe0022d
16
ChangeLog
16
ChangeLog
|
@ -1,3 +1,19 @@
|
|||
2008-04-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Added --quiet option to make aria2 quiet (no console output).
|
||||
--quiet option is tagged with ADVANCED.
|
||||
* src/HelpItemFactory.cc
|
||||
* src/LogFactory.cc
|
||||
* src/LogFactory.h
|
||||
* src/MultiUrlRequestInfo.cc
|
||||
* src/MultiUrlRequestInfo.h
|
||||
* src/NullStatCalc.h: New class. This class prints nothing.
|
||||
* src/OptionHandlerFactory.cc
|
||||
* src/main.cc
|
||||
* src/option_processing.cc
|
||||
* src/prefs.h
|
||||
* src/usage_text.h
|
||||
|
||||
2008-04-22 Tatsuhiro Tsujikawa <tujikawa at rednoah dot com>
|
||||
|
||||
Add HTTP tag to --header option. Removed ADVANCED tag instead.
|
||||
|
|
|
@ -437,6 +437,11 @@ TagContainerHandle HelpItemFactory::createHelpItems()
|
|||
item->addTag(TAG_HTTP);
|
||||
tc->addItem(item);
|
||||
}
|
||||
{
|
||||
HelpItemHandle item(new HelpItem(PREF_QUIET, TEXT_QUIET, V_FALSE));
|
||||
item->addTag(TAG_ADVANCED);
|
||||
tc->addItem(item);
|
||||
}
|
||||
{
|
||||
HelpItemHandle item(new HelpItem("help", TEXT_HELP, TAG_BASIC));
|
||||
char buf[64];
|
||||
|
|
|
@ -40,14 +40,17 @@ namespace aria2 {
|
|||
|
||||
std::string LogFactory::filename = DEV_NULL;
|
||||
Logger* LogFactory::logger = 0;
|
||||
bool LogFactory::_consoleOutput = true;
|
||||
|
||||
Logger* LogFactory::getInstance() {
|
||||
if(logger == NULL) {
|
||||
SimpleLogger* slogger = new SimpleLogger();
|
||||
slogger->openFile(filename);
|
||||
slogger->setStdout(Logger::NOTICE, true);
|
||||
slogger->setStdout(Logger::WARN, true);
|
||||
slogger->setStdout(Logger::ERROR, true);
|
||||
if(_consoleOutput) {
|
||||
slogger->setStdout(Logger::NOTICE, true);
|
||||
slogger->setStdout(Logger::WARN, true);
|
||||
slogger->setStdout(Logger::ERROR, true);
|
||||
}
|
||||
logger = slogger;
|
||||
}
|
||||
return logger;
|
||||
|
|
|
@ -46,6 +46,7 @@ class LogFactory {
|
|||
private:
|
||||
static std::string filename;
|
||||
static Logger* logger;
|
||||
static bool _consoleOutput;
|
||||
public:
|
||||
/**
|
||||
* Get logger instance. Returned logger is singleton.
|
||||
|
@ -60,6 +61,14 @@ public:
|
|||
filename = name;
|
||||
}
|
||||
|
||||
/**
|
||||
* Set flag whether the log is printed in console.
|
||||
* If f is false, log is not printed in console.
|
||||
*/
|
||||
static void setConsoleOutput(bool f) {
|
||||
_consoleOutput = f;
|
||||
}
|
||||
|
||||
/**
|
||||
* Releases used resources
|
||||
*/
|
||||
|
|
|
@ -181,7 +181,8 @@ SRCS = Socket.h\
|
|||
help_tags.h\
|
||||
prefs.h\
|
||||
usage_text.h\
|
||||
ProtocolDetector.cc ProtocolDetector.h
|
||||
ProtocolDetector.cc ProtocolDetector.h\
|
||||
NullStatCalc.h
|
||||
|
||||
if ENABLE_MESSAGE_DIGEST
|
||||
SRCS += IteratableChunkChecksumValidator.cc IteratableChunkChecksumValidator.h\
|
||||
|
|
|
@ -404,7 +404,7 @@ am__libaria2c_a_SOURCES_DIST = Socket.h SocketCore.cc SocketCore.h \
|
|||
TrueRequestGroupCriteria.h a2algo.h a2functional.h a2io.h \
|
||||
a2netcompat.h a2time.h array_fun.h help_tags.h prefs.h \
|
||||
usage_text.h ProtocolDetector.cc ProtocolDetector.h \
|
||||
IteratableChunkChecksumValidator.cc \
|
||||
NullStatCalc.h IteratableChunkChecksumValidator.cc \
|
||||
IteratableChunkChecksumValidator.h \
|
||||
IteratableChecksumValidator.cc IteratableChecksumValidator.h \
|
||||
CheckIntegrityCommand.cc CheckIntegrityCommand.h \
|
||||
|
@ -1119,7 +1119,7 @@ SRCS = Socket.h SocketCore.cc SocketCore.h BinaryStream.h Command.cc \
|
|||
TrueRequestGroupCriteria.h a2algo.h a2functional.h a2io.h \
|
||||
a2netcompat.h a2time.h array_fun.h help_tags.h prefs.h \
|
||||
usage_text.h ProtocolDetector.cc ProtocolDetector.h \
|
||||
$(am__append_1) $(am__append_2) $(am__append_3) \
|
||||
NullStatCalc.h $(am__append_1) $(am__append_2) $(am__append_3) \
|
||||
$(am__append_4) $(am__append_5) $(am__append_6) \
|
||||
$(am__append_7) $(am__append_8) $(am__append_9) \
|
||||
$(am__append_10) $(am__append_11) $(am__append_12) \
|
||||
|
|
|
@ -44,9 +44,10 @@
|
|||
#include "message.h"
|
||||
#include "DNSCache.h"
|
||||
#include "Util.h"
|
||||
#include "ConsoleStatCalc.h"
|
||||
#include "Option.h"
|
||||
#include "StatCalc.h"
|
||||
#include <signal.h>
|
||||
#include <iostream>
|
||||
#include <ostream>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
|
@ -64,9 +65,16 @@ static void handler(int signal) {
|
|||
}
|
||||
}
|
||||
|
||||
MultiUrlRequestInfo::MultiUrlRequestInfo(const RequestGroups& requestGroups, Option* op):
|
||||
MultiUrlRequestInfo::MultiUrlRequestInfo
|
||||
(const RequestGroups& requestGroups,
|
||||
Option* op,
|
||||
const SharedHandle<StatCalc>& statCalc,
|
||||
std::ostream& summaryOut)
|
||||
:
|
||||
_requestGroups(requestGroups),
|
||||
_option(op),
|
||||
_statCalc(statCalc),
|
||||
_summaryOut(summaryOut),
|
||||
_logger(LogFactory::getInstance())
|
||||
{}
|
||||
|
||||
|
@ -74,11 +82,11 @@ MultiUrlRequestInfo::~MultiUrlRequestInfo() {}
|
|||
|
||||
void MultiUrlRequestInfo::printMessageForContinue()
|
||||
{
|
||||
std::cout << "\n"
|
||||
<< _("aria2 will resume download if the transfer is restarted.")
|
||||
<< "\n"
|
||||
<< _("If there are any errors, then see the log file. See '-l' option in help/man page for details.")
|
||||
<< "\n";
|
||||
_summaryOut << "\n"
|
||||
<< _("aria2 will resume download if the transfer is restarted.")
|
||||
<< "\n"
|
||||
<< _("If there are any errors, then see the log file. See '-l' option in help/man page for details.")
|
||||
<< "\n";
|
||||
}
|
||||
|
||||
int MultiUrlRequestInfo::execute()
|
||||
|
@ -91,9 +99,8 @@ int MultiUrlRequestInfo::execute()
|
|||
try {
|
||||
DownloadEngineHandle e =
|
||||
DownloadEngineFactory().newDownloadEngine(_option, _requestGroups);
|
||||
SharedHandle<StatCalc> statCalc(new ConsoleStatCalc());
|
||||
e->setStatCalc(statCalc);
|
||||
|
||||
e->setStatCalc(_statCalc);
|
||||
e->fillCommand();
|
||||
|
||||
// The number of simultaneous download is specified by PREF_MAX_CONCURRENT_DOWNLOADS.
|
||||
|
@ -108,8 +115,8 @@ int MultiUrlRequestInfo::execute()
|
|||
|
||||
e->run();
|
||||
|
||||
e->_requestGroupMan->showDownloadResults(std::cout);
|
||||
std::cout << std::flush;
|
||||
e->_requestGroupMan->showDownloadResults(_summaryOut);
|
||||
_summaryOut << std::flush;
|
||||
|
||||
RequestGroupMan::DownloadStat s = e->_requestGroupMan->getDownloadStat();
|
||||
if(!s.allCompleted()) {
|
||||
|
|
|
@ -38,12 +38,14 @@
|
|||
#include "common.h"
|
||||
#include "SharedHandle.h"
|
||||
#include <deque>
|
||||
#include <iosfwd>
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class RequestGroup;
|
||||
class Option;
|
||||
class Logger;
|
||||
class StatCalc;
|
||||
|
||||
class MultiUrlRequestInfo {
|
||||
private:
|
||||
|
@ -51,12 +53,20 @@ private:
|
|||
|
||||
Option* _option;
|
||||
|
||||
SharedHandle<StatCalc> _statCalc;
|
||||
|
||||
std::ostream& _summaryOut;
|
||||
|
||||
const Logger* _logger;
|
||||
|
||||
void printMessageForContinue();
|
||||
|
||||
public:
|
||||
MultiUrlRequestInfo(const std::deque<SharedHandle<RequestGroup> >& requestGroups, Option* op);
|
||||
MultiUrlRequestInfo
|
||||
(const std::deque<SharedHandle<RequestGroup> >& requestGroups,
|
||||
Option* op,
|
||||
const SharedHandle<StatCalc>& statCalc,
|
||||
std::ostream& summaryOut);
|
||||
|
||||
virtual ~MultiUrlRequestInfo();
|
||||
|
||||
|
|
|
@ -0,0 +1,54 @@
|
|||
/* <!-- copyright */
|
||||
/*
|
||||
* aria2 - The high speed download utility
|
||||
*
|
||||
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU General Public License
|
||||
* along with this program; if not, write to the Free Software
|
||||
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
||||
*
|
||||
* In addition, as a special exception, the copyright holders give
|
||||
* permission to link the code of portions of this program with the
|
||||
* OpenSSL library under certain conditions as described in each
|
||||
* individual source file, and distribute linked combinations
|
||||
* including the two.
|
||||
* You must obey the GNU General Public License in all respects
|
||||
* for all of the code used other than OpenSSL. If you modify
|
||||
* file(s) with this exception, you may extend this exception to your
|
||||
* version of the file(s), but you are not obligated to do so. If you
|
||||
* do not wish to do so, delete this exception statement from your
|
||||
* version. If you delete this exception statement from all source
|
||||
* files in the program, then also delete it here.
|
||||
*/
|
||||
/* copyright --> */
|
||||
#ifndef _D_NULL_STAT_CALC_H_
|
||||
#define _D_NULL_STAT_CALC_H_
|
||||
|
||||
#include "StatCalc.h"
|
||||
|
||||
namespace aria2 {
|
||||
|
||||
class NullStatCalc:public StatCalc {
|
||||
public:
|
||||
virtual ~NullStatCalc() {}
|
||||
|
||||
virtual void
|
||||
calculateStat(const SharedHandle<RequestGroupMan>& requestGroupMan,
|
||||
const SharedHandle<FileAllocationMan>& fileAllocationMan,
|
||||
const SharedHandle<CheckIntegrityMan>& checkIntegrityMan) {}
|
||||
};
|
||||
|
||||
} // namespace aria2
|
||||
|
||||
#endif // _D_NULL_STAT_CALC_H_
|
|
@ -127,6 +127,7 @@ OptionHandlers OptionHandlerFactory::createOptionHandlers()
|
|||
handlers.push_back(SH(new ParameterOptionHandler(PREF_BT_MIN_CRYPTO_LEVEL, V_PLAIN, V_ARC4)));
|
||||
handlers.push_back(SH(new BooleanOptionHandler(PREF_BT_REQUIRE_CRYPTO)));
|
||||
handlers.push_back(SH(new CumulativeOptionHandler(PREF_HEADER, "\n")));
|
||||
handlers.push_back(SH(new BooleanOptionHandler(PREF_QUIET)));
|
||||
return handlers;
|
||||
}
|
||||
|
||||
|
|
36
src/main.cc
36
src/main.cc
|
@ -62,6 +62,8 @@
|
|||
#include "FileEntry.h"
|
||||
#include "RequestGroup.h"
|
||||
#include "ProtocolDetector.h"
|
||||
#include "ConsoleStatCalc.h"
|
||||
#include "NullStatCalc.h"
|
||||
#ifdef ENABLE_METALINK
|
||||
# include "MetalinkHelper.h"
|
||||
# include "Metalink2RequestGroup.h"
|
||||
|
@ -91,6 +93,9 @@ extern int optind, opterr, optopt;
|
|||
|
||||
namespace aria2 {
|
||||
|
||||
// output stream to /dev/null
|
||||
std::ofstream nullout(DEV_NULL);
|
||||
|
||||
std::deque<std::string> unfoldURI(const std::deque<std::string>& args)
|
||||
{
|
||||
std::deque<std::string> nargs;
|
||||
|
@ -119,6 +124,26 @@ RequestGroupHandle createRequestGroup(const Option* op, const std::deque<std::st
|
|||
return rg;
|
||||
}
|
||||
|
||||
SharedHandle<StatCalc> getStatCalc(const Option* op)
|
||||
{
|
||||
SharedHandle<StatCalc> statCalc;
|
||||
if(op->getAsBool(PREF_QUIET)) {
|
||||
statCalc.reset(new NullStatCalc());
|
||||
} else {
|
||||
statCalc.reset(new ConsoleStatCalc());
|
||||
}
|
||||
return statCalc;
|
||||
}
|
||||
|
||||
std::ostream& getSummaryOut(const Option* op)
|
||||
{
|
||||
if(op->getAsBool(PREF_QUIET)) {
|
||||
return nullout;
|
||||
} else {
|
||||
return std::cout;
|
||||
}
|
||||
}
|
||||
|
||||
extern Option* option_processing(int argc, char* const argv[]);
|
||||
|
||||
#ifdef ENABLE_BITTORRENT
|
||||
|
@ -157,7 +182,7 @@ int32_t downloadBitTorrent(Option* op, const std::deque<std::string>& uri)
|
|||
|
||||
RequestGroups groups;
|
||||
groups.push_back(rg);
|
||||
return MultiUrlRequestInfo(groups, op).execute();
|
||||
return MultiUrlRequestInfo(groups, op, getStatCalc(op), getSummaryOut(op)).execute();
|
||||
}
|
||||
#endif // ENABLE_BITTORRENT
|
||||
|
||||
|
@ -168,7 +193,7 @@ int32_t downloadMetalink(Option* op)
|
|||
if(groups.empty()) {
|
||||
throw new FatalException("No files to download.");
|
||||
}
|
||||
return MultiUrlRequestInfo(groups, op).execute();
|
||||
return MultiUrlRequestInfo(groups, op, getStatCalc(op), getSummaryOut(op)).execute();
|
||||
}
|
||||
#endif // ENABLE_METALINK
|
||||
|
||||
|
@ -248,7 +273,7 @@ int32_t downloadUriList(Option* op, std::istream& in)
|
|||
groups.push_back(rg);
|
||||
}
|
||||
}
|
||||
return MultiUrlRequestInfo(groups, op).execute();
|
||||
return MultiUrlRequestInfo(groups, op, getStatCalc(op), getSummaryOut(op)).execute();
|
||||
}
|
||||
|
||||
int32_t downloadUriList(Option* op)
|
||||
|
@ -284,7 +309,7 @@ int32_t downloadUri(Option* op, const std::deque<std::string>& uris)
|
|||
RequestGroupHandle rg = createRequestGroup(op, xargs, op->get(PREF_OUT));
|
||||
groups.push_back(rg);
|
||||
}
|
||||
return MultiUrlRequestInfo(groups, op).execute();
|
||||
return MultiUrlRequestInfo(groups, op, getStatCalc(op), getSummaryOut(op)).execute();
|
||||
}
|
||||
|
||||
int main(int argc, char* argv[])
|
||||
|
@ -301,6 +326,9 @@ int main(int argc, char* argv[])
|
|||
} else {
|
||||
LogFactory::setLogFile(DEV_NULL);
|
||||
}
|
||||
if(op->getAsBool(PREF_QUIET)) {
|
||||
LogFactory::setConsoleOutput(false);
|
||||
}
|
||||
int32_t exitStatus = EXIT_SUCCESS;
|
||||
try {
|
||||
Logger* logger = LogFactory::getInstance();
|
||||
|
|
|
@ -143,6 +143,7 @@ Option* option_processing(int argc, char* const argv[])
|
|||
op->put(PREF_DHT_FILE_PATH, Util::getHomeDir()+"/.aria2/dht.dat");
|
||||
op->put(PREF_BT_MIN_CRYPTO_LEVEL, V_PLAIN);
|
||||
op->put(PREF_BT_REQUIRE_CRYPTO, V_FALSE);
|
||||
op->put(PREF_QUIET, V_FALSE);
|
||||
|
||||
// following options are not parsed by OptionHandler and not stored in Option.
|
||||
bool noConf = false;
|
||||
|
@ -205,6 +206,7 @@ Option* option_processing(int argc, char* const argv[])
|
|||
{ PREF_CONF_PATH, required_argument, &lopt, 213 },
|
||||
{ PREF_STOP, required_argument, &lopt, 214 },
|
||||
{ PREF_HEADER, required_argument, &lopt, 215 },
|
||||
{ PREF_QUIET, optional_argument, 0, 'q' },
|
||||
#if defined ENABLE_BITTORRENT || ENABLE_METALINK
|
||||
{ PREF_SHOW_FILES, no_argument, NULL, 'S' },
|
||||
{ PREF_SELECT_FILE, required_argument, &lopt, 21 },
|
||||
|
@ -243,7 +245,7 @@ Option* option_processing(int argc, char* const argv[])
|
|||
{ "help", optional_argument, NULL, 'h' },
|
||||
{ 0, 0, 0, 0 }
|
||||
};
|
||||
c = getopt_long(argc, argv, "Dd:o:l:s:pt:m:vh::ST:M:C:a:cU:ni:j:Z::P::", longOpts, &optIndex);
|
||||
c = getopt_long(argc, argv, "Dd:o:l:s:pt:m:vh::ST:M:C:a:cU:ni:j:Z::P::q::", longOpts, &optIndex);
|
||||
if(c == -1) {
|
||||
break;
|
||||
}
|
||||
|
@ -471,6 +473,9 @@ Option* option_processing(int argc, char* const argv[])
|
|||
case 'P':
|
||||
cmdstream << PREF_PARAMETERIZED_URI << "=" << toBoolArg(optarg) << "\n";
|
||||
break;
|
||||
case 'q':
|
||||
cmdstream << PREF_QUIET << "=" << toBoolArg(optarg) << "\n";
|
||||
break;
|
||||
case 'v':
|
||||
showVersion();
|
||||
exit(EXIT_SUCCESS);
|
||||
|
|
|
@ -126,6 +126,8 @@
|
|||
#define PREF_CONF_PATH "conf-path"
|
||||
// value: 1*digit
|
||||
#define PREF_STOP "stop"
|
||||
// value: true | false
|
||||
#define PREF_QUIET "quiet"
|
||||
|
||||
/**
|
||||
* FTP related preferences
|
||||
|
|
|
@ -336,3 +336,5 @@ _(" --header=HEADER Append HEADER to HTTP request header. You can u
|
|||
" header:\n"\
|
||||
" aria2c --header=\"X-A: b78\" --header=\"X-B: 9J1\"\n"\
|
||||
" http://host/file")
|
||||
#define TEXT_QUIET \
|
||||
_(" -q, --quiet[=true|false] Make aria2 quite (no console output).")
|
||||
|
|
Loading…
Reference in New Issue