Commits

a4z committed 3847b21

report format and quiet option

Comments (0)

Files changed (7)

include/sbbdep/log.hpp

 #include <a4z/single.hpp>
 #include <a4z/errostream.hpp>
 
+#include <boost/iostreams/stream.hpp>
 
 namespace sbbdep {
 
 
 
 
+
+
 class Log : public a4z::LogSystemOMP<char> , public a4z::Single<sbbdep::Log>
 {
     friend class a4z::Single<Log>;
     
-    void setupChannels() ;
+
     
 public:
     //typedef a4z::LogSystemOMP< char >::ChannelType ChannelType;
 #endif
   {
     // Error/Debug = cerr , Info = cout
-    setupChannels();
+
   }
-  ~Log(){};
+  ~Log();
   
 
   static ChannelType Debug(int loglevel = Level::Debug){ 
 typedef Log::ChannelType LogChannelType; 
 
 
+// this should go to log base class
+struct DevNullSink
+{
+  typedef char char_type;
+  typedef boost::iostreams::sink_tag category;
+
+  std::streamsize
+  write( const char_type* c, std::streamsize n )
+  {
+    return n;
+  }
+};
+//--------------------------------------------------------------------------------------------------
+
+
+class  DevNullStream : public boost::iostreams::stream< DevNullSink >
+{
+  DevNullSink m_sink;
+public:
+  DevNullStream(): m_sink(){ open(m_sink); }
+};
+//--------------------------------------------------------------------------------------------------
+static  DevNullStream DevNull  ;
+
+
+
 }
 
 #endif /* SBBDEP_LOG_HPP_ */

include/sbbdep/singles.hpp

-/*
---------------Copyright (c) 2010-2012 H a r a l d  A c h i t z---------------
------------< h a r a l d dot a c h i t z at g m a i l dot c o m >------------
-Permission is hereby granted, free of charge, to any person obtaining a copy
-of this software and associated documentation files (the "Software"), to deal
-in the Software without restriction, including without limitation the rights
-to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
-copies of the Software, and to permit persons to whom the Software is
-furnished to do so, subject to the following conditions:
-
-The above copyright notice and this permission notice shall be included in
-all copies or substantial portions of the Software.
-
-THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
-IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
-FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
-AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
-LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
-OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
-THE SOFTWARE.
------------------------------------------------------------------------------
-*/
-
-
-
-#ifndef SBBDEP_SINGLES_HPP_
-#define SBBDEP_SINGLES_HPP_
-
-
-#include <sbbdep/cache.hpp>
-#include <sbbdep/log.hpp>
-//#include <sbbdep/filemagic.hpp>
-//#include <sbbdep/pkfab.hpp>
-#include <a4z/singlecollector.hpp>
-
-
-#include <string>
-
-namespace sbbdep
-{
-  void init_all_singles(const std::string& dbname){
-    
-    Log::create(); //NOTE; very important, initialise  log on first position..
-    
-    
-    Cache::create( dbname );
-    
-  //  FMagSingle::create();
-  //  PkFab::create();
-    
-  }
-  
-  void destroy_all_singles(){
-    a4z::SingleCollector::destroy();
-  }  
-  
-}
-
-
-#endif /* SBBDEP_SINGLES_HPP_ */

src/cli/appargs.cpp

   , m_nosync(0)
   , m_whoneeds(0)
   , m_explain_dynlinked(0)
+  , m_quiet(0)
   , m_featureX(0)
 {
   
   
   write.newline();
   write.newline();  
+
+  write.option("--quiet") .description("Suppress status information during sync") ;
+  write.descriptionline("messages during synchronisation will not be shown") ;
+  write.newline();
+  write.newline();
+
   
   write.option("--whoneeds") .description("prints packages that depend on arg") ;
   write.descriptionline("instead of printing the requirements of the given arg") ;
       { "short", no_argument, &m_append_versions, 0 },
       { "version", no_argument, &m_sbbdep_version, 1 },
       { "nosync", no_argument, &m_nosync, 1 },
+      { "quiet", no_argument, &m_quiet, 1 },
       { "whoneeds", no_argument, &m_whoneeds, 1 },
       { "xdl", no_argument, &m_explain_dynlinked, 1 },
       { "fx", no_argument, &m_featureX, 1 }, // undocumented option for the next test...

src/cli/appargs.hpp

   int m_nosync;
   int m_whoneeds;
   int m_explain_dynlinked;
+  int m_quiet;
   int m_featureX;
   
 public:
   bool getNoSync() const { return m_nosync ; }
   bool getWhoNeeds() const { return m_whoneeds ; }
   bool getXDL() const { return m_explain_dynlinked ; }
+  bool getQuiet() const { return m_quiet ; }
   bool getFeatureX() const { return m_featureX ; }
   
   void PrintHelp();

src/cli/appcli.cpp

 
 
 #include <sbbdep/config.hpp> // generated 
-#include <sbbdep/singles.hpp>
 #include <sbbdep/path.hpp>
+#include <sbbdep/log.hpp>
 
 // should possible not be required here
 #include <sbbdep/pkg.hpp>
 
 #include <a4z/err.hpp>
+#include <a4z/singlecollector.hpp>
 
 namespace sbbdep {
 
 
 AppCli::~AppCli()
 {
-  //clear all singletons
-  destroy_all_singles();
+  a4z::SingleCollector::destroy();
 }
 //--------------------------------------------------------------------------------------------------
 
       return 0;
     }
 
+  // log must be the first thing that is initialised !!
+  Log::create();
+  Log::getInstance()->addChannel(Log::ChannelId::Debug, std::cerr , "Debug");
+  Log::getInstance()->addChannel(Log::ChannelId::Error, std::cerr , "Error");
+
+  if( appargs.getQuiet() )
+    Log::getInstance()->addChannel(Log::ChannelId::Info, DevNull , "Info");
+  else
+    Log::getInstance()->addChannel(Log::ChannelId::Info, std::cout , "Info");
+
+
   try
     {
-      init_all_singles(appargs.getDBName());
+      Cache::create( appargs.getDBName() );
 
       if( !prepairCache(appargs.getNoSync()) )
         return -2;

src/cli/report.cpp

 using StringSet = std::set<std::string>;
 using NotFoundMap = std::map<std::string, StringSet>; // from file, so names
 
+template<typename T>
+StringSet getKeySet(const T& keyvalmap){
+  StringSet retval;
+  for(auto val: keyvalmap) retval.insert(val.first);
+  return retval;
+}
 
 
 
       UNION SELECT UNION SELECT lddir FROM rrunpath WHERE lddir IN ( ... ) // optional
       );
   */
-  std::string sql= "SELECT pkgs.fullname as pkgname,  dynlinked.filename , dynlinked.soname "
-  " FROM pkgs INNER JOIN dynlinked ON pkgs.id = dynlinked.pkg_id"
+  std::string sql= "SELECT pkgs.fullname as pkgname,  dynlinked.filename , dynlinked.soname,  " ;
+  sql+= "'" + fromfile.Str() + "' as  requiredby" ;
+  sql+=" FROM pkgs INNER JOIN dynlinked ON pkgs.id = dynlinked.pkg_id"
   " WHERE dynlinked.soname IN ( " ;
   sql+=insonames ;
   sql+= " ) AND dynlinked.arch = ";
 
   NotFoundMap not_found;
 
-  ReportSet rs {{ "pkgname", "filename", "soname" } };
+  ReportSet rs {{ "pkgname", "filename", "soname" , "requiredby" } };
 
   for(const ElfFile& elf : pkg.getDynLinked())
     {
 
 
 
+void printRequired( const Pkg& pkg, bool addversion, bool xdl )
+{
+
+  std::tuple<ReportSet, NotFoundMap> requiredinfo = getRequiredInfos(pkg);
+  ReportTree reptree;
+
+  //pkgname,  filename , soname
+  ReportSet& rs = std::get<0>(requiredinfo) ;
+  NotFoundMap& notFounds = std::get<1>(requiredinfo) ;
+
+
+  for(auto& row : rs)
+    {
+      if(xdl)
+        {
+        reptree.add( {row.getField(3).getString(),
+          row.getField(2).getString(),
+          row.getField(1).getString() ,
+          row.getField(0).getString() } );
+        }
+      else
+        {
+          reptree.add( {
+            row.getField(2).getString(),
+            row.getField(1).getString() ,
+            row.getField(0).getString() } );
+        }
+    }
+
+  if( pkg.getType() == PkgType::BinLib )
+    {
+
+      a4sqlt3::Dataset ds = getPkgsFromFile( pkg.getPath(), pkg.getArch() ) ;
+      // what to do with this , just a report summary ?
+
+    }
+
+  auto makename = [addversion, xdl](const std::string val)
+    {
+
+      if(xdl)
+        {
+          if(addversion)
+            return val;
+
+          return PkgName(val).Name();
+        }
+
+      PkgName pknam(val);
+      std::string retval = pknam.Name();
+      if (addversion) retval+= " >= " + pknam.Version();
+      return retval;
+
+
+    };
+
+  if( xdl )
+    {
+      for(auto requiredby_sos : reptree.node)
+        {
+          Log::AppMessage() << "file " << requiredby_sos.first << " needs:\n";
+          for(auto so_files : requiredby_sos.second.node)
+            {
+              Log::AppMessage() << "  " << so_files.first << " found in:\n";
+              for(auto file_pkgs : so_files.second.node)
+                {
+                  Log::AppMessage() << "    " << file_pkgs.first << "( "
+                      << joinToString(getKeySet(file_pkgs.second.node), " | ", makename) << " )\n";
+                }
+            }
+        }
+    }
+  else
+    {
+      StringSet pkglist;
+      std::string ignore_name ;
+      if(pkg.getType() == PkgType::Installed)
+        ignore_name = pkg.getPath().getBase();
+
+
+      for(auto so_files: reptree.node) // filename so, just what the pkgs...
+        {
+          StringSet pkgsofso;
+          for(auto file_pkgs : so_files.second.node )
+            {
+              if(not ignore_name.empty() &&
+                  file_pkgs.second.node.find(ignore_name) != file_pkgs.second.node.end() )
+                { // avoid own package in the list
+                  pkgsofso.clear();
+                  break;
+                }
+              for (auto so_pkg : file_pkgs.second.node)
+                pkgsofso.insert( so_pkg.first ) ;
+            }
+
+          if(not pkgsofso.empty())
+            pkglist.insert( joinToString(pkgsofso, " | ", makename ) ) ;
+        }
+
+      Log::AppMessage() << joinToString(pkglist, addversion ? "\n" : ", " ) ;
+
+    }
+    Log::AppMessage() << std::endl;
+
+
+    if(not notFounds.empty())
+      {
+        Log::AppMessage() << std::endl;
+        Log::AppMessage() << "not found in standard paths: \n" ;
+      }
+
+    for(auto val : notFounds)
+        Log::AppMessage() << " for " << val.first << ": "<<joinToString(val.second, ", ") << "\n" ;
+
+    Log::AppMessage() << std::endl;
+
+
+}
+
+
+
+
+
+
+
+
+
 
 
 
 //--------------------------------------------------------------------------------------------------
 
 
-void printRequired( const Pkg& pkg, bool addversion, bool xdl )
-{
 
-  std::tuple<ReportSet, NotFoundMap> requiredinfo = getRequiredInfos(pkg);
-  ReportTree reptree;
 
-  //pkgname,  filename , soname
-  ReportSet& rs = std::get<0>(requiredinfo) ;
-  NotFoundMap& notFounds = std::get<1>(requiredinfo) ;
-
-
-  for(auto& row : rs)
-    {
-      reptree.add( { row.getField(2).getString(),
-        row.getField(1).getString() ,
-        row.getField(0).getString() } );
-    }
-
-  if( pkg.getType() == PkgType::BinLib )
-    {
-
-      a4sqlt3::Dataset ds = getPkgsFromFile( pkg.getPath(), pkg.getArch() ) ;
-      // what to do with this , justa report summary ?
-
-    }
-
-  auto makename = [addversion](const std::string val)
-    {
-      PkgName pknam(val);
-      std::string retval = pknam.Name();
-      if (addversion) retval+= " >= " + pknam.Version();
-      return retval;
-    };
-
-  if(xdl)
-    printTree(reptree) ;
-  else
-    {
-      StringSet pkglist;
-      std::string ignore_name ;
-      if(pkg.getType() == PkgType::Installed)
-        ignore_name = pkg.getPath().getBase();
-
-
-      for(auto so_files: reptree.node) // filename so, just what the pkgs...
-        {
-          StringSet pkgsofso;
-          for(auto file_pkgs : so_files.second.node )
-            {
-              if(not ignore_name.empty() &&
-                  file_pkgs.second.node.find(ignore_name) != file_pkgs.second.node.end() )
-                { // avoid own package in the list
-                  pkgsofso.clear();
-                  break;
-                }
-              for (auto so_pkg : file_pkgs.second.node)
-                pkgsofso.insert( so_pkg.first ) ;
-            }
-
-          if(not pkgsofso.empty())
-            pkglist.insert( joinToString(pkgsofso, " | ", makename ) ) ;
-        }
-
-      Log::AppMessage() << joinToString(pkglist, addversion ? "\n" : ", " ) ;
-
-    }
-    Log::AppMessage() << std::endl;
-
-
-    if(not notFounds.empty())
-      {
-        Log::AppMessage() << std::endl;
-        Log::AppMessage() << "not found in standard paths: \n" ;
-      }
-
-    for(auto val : notFounds)
-        Log::AppMessage() << " for " << val.first << ": "<<joinToString(val.second, ", ") << "\n" ;
-
-    Log::AppMessage() << std::endl;
-
-
-}
 
 void printWhoNeed( const Pkg& pkg, bool addversion, bool xdl )
 {

src/sbbdep/log.cpp

 
 namespace sbbdep {
 
-void
-Log::setupChannels(  )
+
+Log::~Log(  )
 {
-  addChannel(ChannelId::Debug, std::cerr , "Debug");
-  addChannel(ChannelId::Error, std::cerr , "Error");
-  addChannel(ChannelId::Info, std::cout , "Info");
 
 }