Browse Source

use the same code to detect quiet setting in all tools

Git-Dch: Ignore
David Kalnischkies 11 years ago
parent
commit
d9e518c6f7

+ 4 - 4
apt-private/private-output.cc

@@ -52,14 +52,14 @@ static void SigWinch(int)
 #endif
 }
 									/*}}}*/
-bool InitOutput()							/*{{{*/
+bool InitOutput(std::basic_streambuf<char> * const out)			/*{{{*/
 {
    if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1)
       _config->Set("quiet","1");
 
-   c0out.rdbuf(cout.rdbuf());
-   c1out.rdbuf(cout.rdbuf());
-   c2out.rdbuf(cout.rdbuf());
+   c0out.rdbuf(out);
+   c1out.rdbuf(out);
+   c2out.rdbuf(out);
    if (_config->FindI("quiet",0) > 0)
       c0out.rdbuf(devnull.rdbuf());
    if (_config->FindI("quiet",0) > 1)

+ 2 - 1
apt-private/private-output.h

@@ -6,6 +6,7 @@
 
 #include <fstream>
 #include <string>
+#include <iostream>
 
 // forward declaration
 class pkgCacheFile;
@@ -20,7 +21,7 @@ APT_PUBLIC extern std::ostream c2out;
 APT_PUBLIC extern std::ofstream devnull;
 APT_PUBLIC extern unsigned int ScreenWidth;
 
-APT_PUBLIC bool InitOutput();
+APT_PUBLIC bool InitOutput(std::basic_streambuf<char> * const out = std::cout.rdbuf());
 
 void ListSingleVersion(pkgCacheFile &CacheFile, pkgRecords &records,
                        pkgCache::VerIterator const &V, std::ostream &out,

+ 1 - 3
cmdline/apt-cache.cc

@@ -1899,9 +1899,7 @@ int main(int argc,const char *argv[])					/*{{{*/
    CommandLine CmdL;
    ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
 
-   // Deal with stdout not being a tty
-   if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1)
-      _config->Set("quiet","1");
+   InitOutput();
 
    if (_config->Exists("APT::Cache::Generate") == true)
       _config->Set("pkgCacheFile::Generate", _config->FindB("APT::Cache::Generate", true));

+ 3 - 4
cmdline/apt-cdrom.cc

@@ -31,6 +31,7 @@
 #include <unistd.h>
 
 #include <apt-private/private-cmndline.h>
+#include <apt-private/private-output.h>
 
 #include <apti18n.h>
 									/*}}}*/
@@ -252,10 +253,8 @@ int main(int argc,const char *argv[])					/*{{{*/
    CommandLine CmdL;
    ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
 
-   // Deal with stdout not being a tty
-   if (isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1)
-      _config->Set("quiet","1");
-   
+   InitOutput();
+
    // Match the operation
    bool returned = CmdL.DispatchArg(Cmds);
 

+ 2 - 16
cmdline/apt-mark.cc

@@ -22,6 +22,7 @@
 #include <apt-pkg/pkgcache.h>
 
 #include <apt-private/private-cmndline.h>
+#include <apt-private/private-output.h>
 
 #include <errno.h>
 #include <fcntl.h>
@@ -41,10 +42,6 @@
 									/*}}}*/
 using namespace std;
 
-ostream c0out(0);
-ostream c1out(0);
-ostream c2out(0);
-ofstream devnull("/dev/null");
 /* DoAuto - mark packages as automatically/manually installed		{{{*/
 static bool DoAuto(CommandLine &CmdL)
 {
@@ -444,18 +441,7 @@ int main(int argc,const char *argv[])					/*{{{*/
    CommandLine CmdL;
    ParseCommandLine(CmdL, Cmds, Args.data(), &_config, &_system, argc, argv, ShowHelp);
 
-   // Deal with stdout not being a tty
-   if (!isatty(STDOUT_FILENO) && _config->FindI("quiet", -1) == -1)
-      _config->Set("quiet","1");
-
-   // Setup the output streams
-   c0out.rdbuf(cout.rdbuf());
-   c1out.rdbuf(cout.rdbuf());
-   c2out.rdbuf(cout.rdbuf());
-   if (_config->FindI("quiet",0) > 0)
-      c0out.rdbuf(devnull.rdbuf());
-   if (_config->FindI("quiet",0) > 1)
-      c1out.rdbuf(devnull.rdbuf());
+   InitOutput();
 
    // Match the operation
    CmdL.DispatchArg(Cmds);

+ 5 - 14
ftparchive/apt-ftparchive.cc

@@ -20,6 +20,7 @@
 #include <apt-pkg/fileutl.h>
 
 #include <apt-private/private-cmndline.h>
+#include <apt-private/private-output.h>
 
 #include <algorithm>
 #include <climits>
@@ -42,11 +43,7 @@
 #include <apti18n.h>
 									/*}}}*/
 
-using namespace std;    
-ostream c0out(0);
-ostream c1out(0);
-ostream c2out(0);
-ofstream devnull("/dev/null");
+using namespace std;
 unsigned Quiet = 0;
 
 // struct PackageMap - List of all package files in the config file	/*{{{*/
@@ -1064,16 +1061,10 @@ int main(int argc, const char *argv[])
    CommandLine CmdL(Args,_config);
    ParseCommandLine(CmdL, Cmds, Args, &_config, NULL, argc, argv, ShowHelp);
 
-   // Setup the output streams
-   c0out.rdbuf(clog.rdbuf());
-   c1out.rdbuf(clog.rdbuf());
-   c2out.rdbuf(clog.rdbuf());
+   _config->CndSet("quiet",0);
    Quiet = _config->FindI("quiet",0);
-   if (Quiet > 0)
-      c0out.rdbuf(devnull.rdbuf());
-   if (Quiet > 1)
-      c1out.rdbuf(devnull.rdbuf());
- 
+   InitOutput(clog.rdbuf());
+
    // Match the operation
    CmdL.DispatchArg(Cmds);
    

+ 18 - 12
test/integration/test-apt-ftparchive-cachedb

@@ -69,32 +69,38 @@ buildsimplenativepackage 'foo' 'i386' '1' 'test'
 mv incoming/* aptarchive/pool/main/
 
 # generate (empty cachedb)
-aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1 2> stats-out.txt
+testsuccess aptftparchive generate ftparchive.conf -q=0 -o APT::FTPArchive::ShowCacheMisses=1
+cp rootdir/tmp/testsuccess.output stats-out.txt
 ensure_correct_packages_file
 ensure_correct_contents_file
-testequal " Misses in Cache: 2
- dists/test/Contents-i386: New 402 B  Misses in Cache: 0" grep Misses stats-out.txt
+testsuccess grep Misses stats-out.txt
+testfileequal 'rootdir/tmp/testsuccess.output' ' Misses in Cache: 2
+ dists/test/Contents-i386: New 402 B  Misses in Cache: 0'
 
 # generate again
-aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1 2> stats-out.txt
+testsuccess aptftparchive generate ftparchive.conf -q=0 -o APT::FTPArchive::ShowCacheMisses=1
+cp rootdir/tmp/testsuccess.output stats-out.txt
 ensure_correct_packages_file
 ensure_correct_contents_file
-testequal " Misses in Cache: 0
- dists/test/Contents-i386:  Misses in Cache: 0" grep Misses stats-out.txt
+testsuccess grep Misses stats-out.txt
+testfileequal 'rootdir/tmp/testsuccess.output' ' Misses in Cache: 0
+ dists/test/Contents-i386:  Misses in Cache: 0'
 
 # and again (with removing the Packages file)
 rm -f ./aptarchive/dists/test/main/binary-i386/*
 rm -f ./aptarchive/dists/test/Contents-i386
-aptftparchive generate ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1 2> stats-out.txt
+testsuccess aptftparchive generate ftparchive.conf -q=0 -o APT::FTPArchive::ShowCacheMisses=1
+cp rootdir/tmp/testsuccess.output stats-out.txt
 ensure_correct_packages_file
 ensure_correct_contents_file
-testequal " Misses in Cache: 0
- dists/test/Contents-i386: New 402 B  Misses in Cache: 0" grep Misses stats-out.txt
+testsuccess grep Misses stats-out.txt
+testfileequal 'rootdir/tmp/testsuccess.output' ' Misses in Cache: 0
+ dists/test/Contents-i386: New 402 B  Misses in Cache: 0'
 
 # and clean
 rm -rf aptarchive/pool/main/*
-testequal "packages-main-i386.db" aptftparchive clean ftparchive.conf
-aptftparchive clean ftparchive.conf -o Debug::APT::FTPArchive::Clean=1 > clean-out.txt 2>&1 
+testequal "packages-main-i386.db" aptftparchive clean ftparchive.conf -q=0
+testsuccess aptftparchive clean ftparchive.conf -q=0 -o Debug::APT::FTPArchive::Clean=1
+cp rootdir/tmp/testsuccess.output clean-out.txt
 testequal "0	Number of unique keys in the tree" grep unique clean-out.txt
 testequal "packages-main-i386.db" grep packages-main-i386.db clean-out.txt
-

+ 28 - 32
test/integration/test-apt-ftparchive-src-cachedb

@@ -106,28 +106,22 @@ mkdir -p aptarchive/dists/test/main/source/
 mkdir aptarchive-overrides
 mkdir aptarchive-cache
 
-
-
-# generate with --db option
-(cd aptarchive && aptftparchive --db ./test.db sources pool/main/ \
-    -o APT::FTPArchive::ShowCacheMisses=1  \
-    > dists/test/main/source/Sources \
-    2> stats-out.txt
-    testequal " Misses in Cache: 2" grep Misses stats-out.txt
-)
+msgtest 'generate with --db option'
+cd aptarchive
+aptftparchive --db ./test.db sources pool/main/ -q=0 -o APT::FTPArchive::ShowCacheMisses=1  > dists/test/main/source/Sources 2>stats-out.txt && msgpass || msgfail
+testsuccess grep Misses stats-out.txt
+testfileequal '../rootdir/tmp/testsuccess.output' ' Misses in Cache: 2'
+cd ..
 assert_correct_sources_file
 
-# generate with --db option (again to ensure its in the cache)
-(cd aptarchive && aptftparchive --db ./test.db sources pool/main/ \
-    -o APT::FTPArchive::ShowCacheMisses=1  \
-    > dists/test/main/source/Sources \
-    2> stats-out.txt  
-    testequal " Misses in Cache: 0" grep Misses stats-out.txt
-)
+msgtest 'generate with --db option (again to ensure its in the cache)'
+cd aptarchive
+aptftparchive --db ./test.db sources pool/main/ -q=0 -o APT::FTPArchive::ShowCacheMisses=1  > dists/test/main/source/Sources 2>stats-out.txt && msgpass || msgfail
+testsuccess grep Misses stats-out.txt
+testfileequal '../rootdir/tmp/testsuccess.output' ' Misses in Cache: 0'
+cd ..
 assert_correct_sources_file
 
-
-
 # get ready for the "apt-ftparchive generate" command
 cat > apt-ftparchive.conf <<"EOF"
 Dir {
@@ -159,20 +153,21 @@ Tree "dists/test" {
 };
 EOF
 
-# generate (empty cachedb)
-aptftparchive generate apt-ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1 2> stats-out.txt
-testequal " Misses in Cache: 2" grep Misses stats-out.txt
+msgtest 'generate (empty cachedb)'
+testsuccess aptftparchive generate apt-ftparchive.conf -q=0 -o APT::FTPArchive::ShowCacheMisses=1
+cp rootdir/tmp/testsuccess.output stats-out.txt
+testsuccess grep Misses stats-out.txt
+testfileequal rootdir/tmp/testsuccess.output ' Misses in Cache: 2'
 assert_correct_sources_file
 
-
-# generate again out of the cache
+msgtest 'generate again out of the cache'
 rm -f ./aptarchive/dists/test/main/source/Sources
-aptftparchive generate apt-ftparchive.conf -o APT::FTPArchive::ShowCacheMisses=1  2> stats-out.txt
-testequal " Misses in Cache: 0" grep Misses stats-out.txt
+testsuccess aptftparchive generate apt-ftparchive.conf -q=0 -o APT::FTPArchive::ShowCacheMisses=1
+cp rootdir/tmp/testsuccess.output stats-out.txt
+testsuccess grep Misses stats-out.txt
+testfileequal rootdir/tmp/testsuccess.output ' Misses in Cache: 0'
 assert_correct_sources_file
 
-
-
 # generate invalid files
 mkdir aptarchive/pool/invalid
 printf "meep" > aptarchive/pool/invalid/invalid_1.0.dsc
@@ -191,8 +186,9 @@ E: DSC file 'aptarchive/pool/invalid/toobig_1.0.dsc' is too large!" aptftparchiv
 
 # ensure clean works
 rm -f aptarchive/pool/main/*
-aptftparchive clean apt-ftparchive.conf -o Debug::APT::FTPArchive::Clean=1 > clean-out.txt 2>&1 
-testequal "0	Number of unique keys in the tree" grep unique clean-out.txt
-testequal "sources-main.db" grep sources-main.db clean-out.txt
-
-
+testsuccess aptftparchive clean apt-ftparchive.conf -q=0 -o Debug::APT::FTPArchive::Clean=1
+cp rootdir/tmp/testsuccess.output clean-out.txt
+testsuccess grep unique clean-out.txt
+testfileequal 'rootdir/tmp/testsuccess.output' "0	Number of unique keys in the tree"
+testsuccess grep sources-main.db clean-out.txt
+testfileequal 'rootdir/tmp/testsuccess.output' "sources-main.db"