From 6eaa9e9466b0233524c3027e810548a5b5b96da2 Mon Sep 17 00:00:00 2001 From: Michael Andres Date: Fri, 6 Nov 2009 21:52:14 +0100 Subject: [PATCH] Add tool/DumpSelectable --- tools/DumpSelectable.cc | 138 ++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 138 insertions(+) create mode 100644 tools/DumpSelectable.cc diff --git a/tools/DumpSelectable.cc b/tools/DumpSelectable.cc new file mode 100644 index 0000000..60b2402 --- /dev/null +++ b/tools/DumpSelectable.cc @@ -0,0 +1,138 @@ +#define INCLUDE_TESTSETUP_WITHOUT_BOOST +#include "zypp/../tests/lib/TestSetup.h" +#undef INCLUDE_TESTSETUP_WITHOUT_BOOST + +#include +#include + +static std::string appname( "DumpSelectable" ); + +#define message cout +using std::flush; + +int errexit( const std::string & msg_r = std::string(), int exit_r = 100 ) +{ + if ( ! msg_r.empty() ) + { + cerr << endl << msg_r << endl << endl; + } + return exit_r; +} + +int usage( const std::string & msg_r = std::string(), int exit_r = 100 ) +{ + if ( ! msg_r.empty() ) + { + cerr << endl << msg_r << endl << endl; + } + cerr << "Usage: " << appname << " [--root ROOTDIR] [OPTIONS] NAME..." << endl; + cerr << " Load all enabled repositories (no refresh) and search for" << endl; + cerr << " Selectables names NAME" << endl; + cerr << " --root Load repos from the system located below ROOTDIR. If ROOTDIR" << endl; + cerr << " denotes a sover testcase, the testcase is loaded." << endl; + cerr << "" << endl; + return exit_r; +} + +/****************************************************************** +** +** FUNCTION NAME : main +** FUNCTION TYPE : int +*/ +int main( int argc, char * argv[] ) +{ + INT << "===[START]==========================================" << endl; + appname = Pathname::basename( argv[0] ); + --argc,++argv; + + if ( ! argc ) + { + return usage(); + } + + /////////////////////////////////////////////////////////////////// + + ZConfig::instance(); + Pathname sysRoot("/"); + sat::Pool satpool( sat::Pool::instance() ); + + if ( (*argv) == std::string("--root") ) + { + --argc,++argv; + if ( ! argc ) + return errexit("--root requires an argument."); + + if ( ! PathInfo( *argv ).isDir() ) + return errexit("--root requires a directory."); + + sysRoot = *argv; + --argc,++argv; + } + + if ( TestSetup::isTestcase( sysRoot ) ) + { + message << str::form( "*** Load Testcase from '%s'", sysRoot.c_str() ) << endl; + TestSetup test; + test.loadTestcaseRepos( sysRoot ); + } + else if ( TestSetup::isTestSetup( sysRoot ) ) + { + message << str::form( "*** Load TestSetup from '%s'", sysRoot.c_str() ) << endl; + TestSetup test( sysRoot, Arch_x86_64 ); + test.loadRepos(); + } + else + { + // a system + message << str::form( "*** Load system at '%s'", sysRoot.c_str() ) << endl; + if ( true ) + { + message << "*** load target '" << Repository::systemRepoAlias() << "'\t" << endl; + getZYpp()->initializeTarget( sysRoot ); + getZYpp()->target()->load(); + message << satpool.systemRepo() << endl; + } + + if ( true ) + { + RepoManager repoManager( sysRoot ); + RepoInfoList repos = repoManager.knownRepositories(); + for_( it, repos.begin(), repos.end() ) + { + RepoInfo & nrepo( *it ); + + if ( ! nrepo.enabled() ) + continue; + + if ( ! repoManager.isCached( nrepo ) ) + { + message << str::form( "*** omit uncached repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl; + continue; + } + + message << str::form( "*** load repo '%s'\t", nrepo.name().c_str() ) << flush; + try + { + repoManager.loadFromCache( nrepo ); + message << satpool.reposFind( nrepo.alias() ) << endl; + } + catch ( const Exception & exp ) + { + message << exp.asString() + "\n" + exp.historyAsString() << endl; + message << str::form( "*** omit broken repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl; + continue; + } + } + } + } + + /////////////////////////////////////////////////////////////////// + + for ( ; argc; --argc,++argv ) + { + message << dump( ui::Selectable::get( IdString( *argv ) ) ) << endl; + } + + INT << "===[END]============================================" << endl << endl; + return 0; +} -- 2.7.4