1 #define INCLUDE_TESTSETUP_WITHOUT_BOOST
2 #include "zypp/../tests/lib/TestSetup.h"
3 #undef INCLUDE_TESTSETUP_WITHOUT_BOOST
6 #include <zypp/PoolQuery.h>
7 #include <zypp/ResObjects.h>
9 static std::string appname( "DumpSelectable" );
14 int errexit( const std::string & msg_r = std::string(), int exit_r = 100 )
16 if ( ! msg_r.empty() )
18 cerr << endl << msg_r << endl << endl;
23 int usage( const std::string & msg_r = std::string(), int exit_r = 100 )
25 if ( ! msg_r.empty() )
27 cerr << endl << msg_r << endl << endl;
29 cerr << "Usage: " << appname << " [--root ROOTDIR] [OPTIONS] NAME..." << endl;
30 cerr << " Load all enabled repositories (no refresh) and search for" << endl;
31 cerr << " Selectables names NAME" << endl;
32 cerr << " --root Load repos from the system located below ROOTDIR. If ROOTDIR" << endl;
33 cerr << " denotes a sover testcase, the testcase is loaded." << endl;
34 cerr << " -v Verbose list solvables data." << endl;
39 void dumpPi( std::ostream & message, const PoolItem & pi )
41 std::string indent(" ");
42 message << indent << "--------------------------------------------------" << endl;
43 message << indent << (pi->isSystem() ? "i " : "a ") << pi->satSolvable().asString() << endl;
44 message << indent << pi->summary() << endl;
45 if ( pi->isKind<Package>() )
47 message << indent << pi->asKind<Package>()->changelog() << endl;
51 /******************************************************************
53 ** FUNCTION NAME : main
54 ** FUNCTION TYPE : int
56 int main( int argc, char * argv[] )
58 INT << "===[START]==========================================" << endl;
59 appname = Pathname::basename( argv[0] );
62 Pathname sysRoot("/");
65 while ( argc && (*argv)[0] == '-' )
67 if ( (*argv) == std::string("--root") )
71 return errexit("--root requires an argument.");
73 if ( ! PathInfo( *argv ).isDir() )
74 return errexit("--root requires a directory.");
78 else if ( (*argv) == std::string("-v") )
91 ///////////////////////////////////////////////////////////////////
94 sat::Pool satpool( sat::Pool::instance() );
96 if ( TestSetup::isTestcase( sysRoot ) )
98 message << str::form( "*** Load Testcase from '%s'", sysRoot.c_str() ) << endl;
100 test.loadTestcaseRepos( sysRoot );
102 else if ( TestSetup::isTestSetup( sysRoot ) )
104 message << str::form( "*** Load TestSetup from '%s'", sysRoot.c_str() ) << endl;
105 TestSetup test( sysRoot, Arch_x86_64 );
111 message << str::form( "*** Load system at '%s'", sysRoot.c_str() ) << endl;
114 message << "*** load target '" << Repository::systemRepoAlias() << "'\t" << endl;
115 getZYpp()->initializeTarget( sysRoot );
116 getZYpp()->target()->load();
117 message << satpool.systemRepo() << endl;
122 RepoManager repoManager( sysRoot );
123 RepoInfoList repos = repoManager.knownRepositories();
124 for_( it, repos.begin(), repos.end() )
126 RepoInfo & nrepo( *it );
128 if ( ! nrepo.enabled() )
131 if ( ! repoManager.isCached( nrepo ) )
133 message << str::form( "*** omit uncached repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
137 message << str::form( "*** load repo '%s'\t", nrepo.name().c_str() ) << flush;
140 repoManager.loadFromCache( nrepo );
141 message << satpool.reposFind( nrepo.alias() ) << endl;
143 catch ( const Exception & exp )
145 message << exp.asString() + "\n" + exp.historyAsString() << endl;
146 message << str::form( "*** omit broken repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
153 ///////////////////////////////////////////////////////////////////
155 for ( ; argc; --argc,++argv )
157 ui::Selectable::Ptr sel( ui::Selectable::get( IdString( *argv ) ) );
158 message << dump( sel ) << endl;
161 for_( it, sel->installedBegin(), sel->installedEnd() )
162 dumpPi( message, *it );
163 for_( it, sel->availableBegin(), sel->availableEnd() )
164 dumpPi( message, *it );
168 INT << "===[END]============================================" << endl << endl;