1 #define INCLUDE_TESTSETUP_WITHOUT_BOOST
2 #include "../tests/lib/TestSetup.h"
3 #undef INCLUDE_TESTSETUP_WITHOUT_BOOST
6 #include <zypp/PoolQuery.h>
8 static std::string appname( "zypp-list" );
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 << " [GLOBALOPTS] COMMAND" << endl;
30 cerr << "List pool items according to command." << endl;
32 cerr << "GLOBALOPTS:" << endl;
33 cerr << " --root Load repos from the system located below ROOTDIR. If ROOTDIR" << endl;
34 cerr << " denotes a sover testcase, the testcase is loaded." << endl;
35 cerr << " -i, --installed Process installed packages only." << endl;
37 cerr << "COMMANDS:" << endl;
38 cerr << " locks: List all locked pool items." << endl;
44 void startup( const Pathname & sysRoot = "/", bool onlyInstalled = false )
47 sat::Pool satpool( sat::Pool::instance() );
49 if ( TestSetup::isTestcase( sysRoot ) )
51 message << str::form( "*** Load Testcase from '%s'", sysRoot.c_str() ) << endl;
53 test.loadTestcaseRepos( sysRoot );
54 dumpRange( message, satpool.reposBegin(), satpool.reposEnd() ) << endl;
56 else if ( TestSetup::isTestSetup( sysRoot ) )
58 message << str::form( "*** Load TestSetup from '%s'", sysRoot.c_str() ) << endl;
59 TestSetup test( sysRoot, Arch_x86_64 );
61 dumpRange( message, satpool.reposBegin(), satpool.reposEnd() ) << endl;
66 message << str::form( "*** Load system at '%s'", sysRoot.c_str() ) << endl;
69 message << "*** load target '" << Repository::systemRepoAlias() << "'\t";
70 getZYpp()->initializeTarget( sysRoot );
71 getZYpp()->target()->load();
72 message << satpool.systemRepo() << endl;
77 RepoManager repoManager( sysRoot );
78 RepoInfoList repos = repoManager.knownRepositories();
79 for_( it, repos.begin(), repos.end() )
81 RepoInfo & nrepo( *it );
83 if ( ! nrepo.enabled() )
86 if ( ! repoManager.isCached( nrepo ) )
88 message << str::form( "*** omit uncached repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
92 message << str::form( "*** load repo '%s'\t", nrepo.name().c_str() ) << flush;
95 repoManager.loadFromCache( nrepo );
96 message << satpool.reposFind( nrepo.alias() ) << endl;
98 catch ( const Exception & exp )
100 message << exp.asString() + "\n" + exp.historyAsString() << endl;
101 message << str::form( "*** omit broken repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
109 /******************************************************************
111 ** FUNCTION NAME : main
112 ** FUNCTION TYPE : int
114 int main( int argc, char * argv[] )
116 INT << "===[START]==========================================" << endl;
117 appname = Pathname::basename( argv[0] );
125 ///////////////////////////////////////////////////////////////////
127 Pathname sysRoot( "/" );
128 if ( argc && (*argv) == std::string("--root") )
132 return errexit("--root requires an argument.");
134 if ( ! PathInfo( *argv ).isDir() )
135 return errexit("--root requires a directory.");
141 bool onlyInstalled( false );
142 if ( argc && (*argv) == std::string("--installed") )
145 onlyInstalled = true;
148 ///////////////////////////////////////////////////////////////////
155 startup( sysRoot, onlyInstalled );
156 ResPool pool( ResPool::instance() );
158 if ( argc && (*argv) == std::string("locked") )
160 OUT << "*** Locked:" << endl;
161 for_( it, pool.begin(), pool.end() )
163 if ( (*it).status().isLocked() )
168 INT << "===[END]============================================" << endl << endl;