diff --git a/ChangeLog b/ChangeLog index e1868314..81e033df 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,19 @@ +2008-04-22 Tatsuhiro Tsujikawa + + 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 Add HTTP tag to --header option. Removed ADVANCED tag instead. diff --git a/src/HelpItemFactory.cc b/src/HelpItemFactory.cc index 89f456be..4c80b189 100644 --- a/src/HelpItemFactory.cc +++ b/src/HelpItemFactory.cc @@ -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]; diff --git a/src/LogFactory.cc b/src/LogFactory.cc index a17c5be3..8ee9df62 100644 --- a/src/LogFactory.cc +++ b/src/LogFactory.cc @@ -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; diff --git a/src/LogFactory.h b/src/LogFactory.h index 6ec4197c..804f6958 100644 --- a/src/LogFactory.h +++ b/src/LogFactory.h @@ -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 */ diff --git a/src/Makefile.am b/src/Makefile.am index 5c025d7e..708f4457 100644 --- a/src/Makefile.am +++ b/src/Makefile.am @@ -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\ diff --git a/src/Makefile.in b/src/Makefile.in index 330afe31..1748ebe0 100644 --- a/src/Makefile.in +++ b/src/Makefile.in @@ -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) \ diff --git a/src/MultiUrlRequestInfo.cc b/src/MultiUrlRequestInfo.cc index 455004a7..ac394af9 100644 --- a/src/MultiUrlRequestInfo.cc +++ b/src/MultiUrlRequestInfo.cc @@ -44,9 +44,10 @@ #include "message.h" #include "DNSCache.h" #include "Util.h" -#include "ConsoleStatCalc.h" +#include "Option.h" +#include "StatCalc.h" #include -#include +#include 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, + 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(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()) { diff --git a/src/MultiUrlRequestInfo.h b/src/MultiUrlRequestInfo.h index fdc44d20..a66dc9bb 100644 --- a/src/MultiUrlRequestInfo.h +++ b/src/MultiUrlRequestInfo.h @@ -38,12 +38,14 @@ #include "common.h" #include "SharedHandle.h" #include +#include namespace aria2 { class RequestGroup; class Option; class Logger; +class StatCalc; class MultiUrlRequestInfo { private: @@ -51,12 +53,20 @@ private: Option* _option; + SharedHandle _statCalc; + + std::ostream& _summaryOut; + const Logger* _logger; void printMessageForContinue(); public: - MultiUrlRequestInfo(const std::deque >& requestGroups, Option* op); + MultiUrlRequestInfo + (const std::deque >& requestGroups, + Option* op, + const SharedHandle& statCalc, + std::ostream& summaryOut); virtual ~MultiUrlRequestInfo(); diff --git a/src/NullStatCalc.h b/src/NullStatCalc.h new file mode 100644 index 00000000..375fe6bd --- /dev/null +++ b/src/NullStatCalc.h @@ -0,0 +1,54 @@ +/* */ +#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, + const SharedHandle& fileAllocationMan, + const SharedHandle& checkIntegrityMan) {} +}; + +} // namespace aria2 + +#endif // _D_NULL_STAT_CALC_H_ diff --git a/src/OptionHandlerFactory.cc b/src/OptionHandlerFactory.cc index a8e0ce3e..89c34336 100644 --- a/src/OptionHandlerFactory.cc +++ b/src/OptionHandlerFactory.cc @@ -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; } diff --git a/src/main.cc b/src/main.cc index 43ba7585..ad46d475 100644 --- a/src/main.cc +++ b/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 unfoldURI(const std::deque& args) { std::deque nargs; @@ -119,6 +124,26 @@ RequestGroupHandle createRequestGroup(const Option* op, const std::deque getStatCalc(const Option* op) +{ + SharedHandle 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& 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& 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(); diff --git a/src/option_processing.cc b/src/option_processing.cc index 74cb0044..fb5143b3 100644 --- a/src/option_processing.cc +++ b/src/option_processing.cc @@ -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); diff --git a/src/prefs.h b/src/prefs.h index 96c5e351..66e034ff 100644 --- a/src/prefs.h +++ b/src/prefs.h @@ -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 diff --git a/src/usage_text.h b/src/usage_text.h index af3b1d20..dd7f7770 100644 --- a/src/usage_text.h +++ b/src/usage_text.h @@ -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).")