From a6ed2bd410125d40004549069ae4461332848e19 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Wed, 30 Aug 2006 15:38:27 +0000 Subject: [PATCH] ScanSource tool --- devel/devel.ma/ScanSource.cc | 162 +++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 162 insertions(+) create mode 100644 devel/devel.ma/ScanSource.cc diff --git a/devel/devel.ma/ScanSource.cc b/devel/devel.ma/ScanSource.cc new file mode 100644 index 0000000..22620e9 --- /dev/null +++ b/devel/devel.ma/ScanSource.cc @@ -0,0 +1,162 @@ +#include + +#include +#include +//#include +#include +#include +#include +#include +#include +#include + +using namespace std; +using namespace zypp; + +static bool verbose = false; +static bool debug = false; + +#define LOG (debug ? USR : cout) + +struct KeyRingReceiver : public callback::ReceiveReport +{ + KeyRingReceiver() + { + connect(); + } + + virtual bool askUserToAcceptUnsignedFile( const std::string & file ) + { + LOG << "===[UnsignedFile " << file << "]" << endl; + return true; + } + virtual bool askUserToAcceptUnknownKey( const std::string &file, + const std::string &id ) + { + LOG << "===[UnknownKey " << id << "]" << endl; + return true; + } + virtual bool askUserToTrustKey( const PublicKey &key) + { + LOG << "===[TrustKey" << key << "]" << endl; + return true; + } + virtual bool askUserToImportKey( const PublicKey &key) + { + LOG << "===[ImportKey " << key << "]" << endl; + return true; + } + virtual bool askUserToAcceptVerificationFailed( const std::string &file, + const PublicKey &key ) + { + LOG << "===[VerificationFailed " << file << " " << key << "]" << endl; + return true; + } +}; + +struct ResStoreStats : public pool::PoolStats +{ + void operator()( const ResObject::constPtr & obj ) + { + if ( isKind( obj ) ) + { + LOG << obj << endl; + } + pool::PoolStats::operator()( obj ); + } +}; + +/****************************************************************** +** +** FUNCTION NAME : main +** FUNCTION TYPE : int +*/ +int main( int argc, char * argv[] ) +{ + zypp::base::LogControl::instance().logfile( "" ); + INT << "===[START]==========================================" << endl; + --argc; + ++argv; + + if ( ! argc ) + { + LOG << "Usage: ScanSource [options] url [[options] url...]" << endl; + LOG << " Display summary of Sources found at 'url'. " << endl; + LOG << " " << endl; + LOG << " " << endl; + LOG << " options:" << endl; + LOG << " +/-l enable/disable detailed listing of Source content" << endl; + LOG << " +/-d enable/disable debug output" << endl; + return 0; + } + + KeyRingReceiver accept; + + for ( ; argc; --argc, ++argv ) + { + if ( *argv == string("+l") ) + { + verbose = true; + continue; + } + if ( *argv == string("-l") ) + { + verbose = false; + continue; + } + if ( *argv == string("+d") ) + { + zypp::base::LogControl::instance().logfile( "-" ); + debug = true; + continue; + } + if ( *argv == string("-d") ) + { + zypp::base::LogControl::instance().logfile( "" ); + debug = false; + continue; + } + + LOG << "====================================================" << endl; + LOG << "===Search Source at Url(" << *argv << ")..." << endl; + Source_Ref src; + try + { + src = SourceFactory().createFrom( Url(*argv), "/", "" ); + } + catch ( const Exception & except_r ) + { + LOG << "***Failed: " << except_r << endl; + continue; + } + LOG << "numberOfMedia: " << src.numberOfMedia() << endl; + LOG << "alias: " << src.alias() << endl; + LOG << "vendor: " << src.vendor() << endl; + LOG << "unique_id: " << src.unique_id() << endl; + LOG << "zmdName: " << src.zmdName() << endl; + LOG << "zmdDescription: " << src.zmdDescription() << endl; + LOG << "baseSource: " << src.baseSource() << endl; + LOG << "publicKeys: " << src.publicKeys() << endl; + + LOG << "===Parse content..." << endl; + try + { + src.resolvables(); + } + catch ( const Exception & except_r ) + { + LOG << "***Failed: " << except_r << endl; + continue; + } + LOG << for_each( src.resolvables().begin(), src.resolvables().end(), + ResStoreStats() ) << endl; + if ( verbose ) + { + dumpRange( LOG, src.resolvables().begin(), src.resolvables().end() ) << endl; + } + } + + INT << "===[END]============================================" << endl << endl; + return 0; +} + -- 2.7.4