1 #define INCLUDE_TESTSETUP_WITHOUT_BOOST
2 #include "zypp/../tests/lib/TestSetup.h"
3 #undef INCLUDE_TESTSETUP_WITHOUT_BOOST
5 #include <zypp/PoolQuery.h>
7 static std::string appname( "NameReqPrv" );
9 void message( const std::string & msg_r )
11 cerr << "*** " << msg_r << endl;
14 int errexit( const std::string & msg_r = std::string(), int exit_r = 100 )
16 if ( ! msg_r.empty() )
25 int usage( const std::string & msg_r = std::string(), int exit_r = 100 )
27 if ( ! msg_r.empty() )
33 cerr << "Usage: " << appname << " [--root ROOTDIR] [OPTIONS] NAME... [[OPTIONS] NAME...]..." << endl;
34 cerr << " Load all enabled repositories (no refresh) and search for" << endl;
35 cerr << " occurrences of NAME (substring) in package names, provides or" << endl;
36 cerr << " requires." << endl;
37 cerr << " --root Load repos from the system located below ROOTDIR. If ROOTDIR" << endl;
38 cerr << " denotes a sover testcase, the testcase is loaded." << endl;
39 cerr << " -i/-I turn on/off case insensitive search (default on)" << endl;
40 cerr << " -n/-N turn on/off looking for names (default on)" << endl;
41 cerr << " -p/-P turn on/off looking for provides (default off)" << endl;
42 cerr << " -r/-R turn on/off looking for requires (default off)" << endl;
43 cerr << " -a short for -n -p -r" << endl;
44 cerr << " -A short for -n -P -R" << endl;
45 cerr << "TODO: Waiting for PoolQuery::allMatches switch and need to beautify output." << endl;
50 /******************************************************************
52 ** FUNCTION NAME : main
53 ** FUNCTION TYPE : int
55 int main( int argc, char * argv[] )
57 INT << "===[START]==========================================" << endl;
58 appname = Pathname::basename( argv[0] );
66 ///////////////////////////////////////////////////////////////////
69 Pathname sysRoot("/");
71 if ( (*argv) == std::string("--root") )
75 return errexit("--root requires an argument.");
77 if ( ! PathInfo( *argv ).isDir() )
78 return errexit("--root requires a directory.");
84 if ( TestSetup::isTestcase( sysRoot ) )
86 message( str::form( "*** Load Testcase from '%s'", sysRoot.c_str() ) );
88 test.loadTestcaseRepos( sysRoot );
90 else if ( TestSetup::isTestSetup( sysRoot ) )
92 message( str::form( "*** Load TestSetup from '%s'", sysRoot.c_str() ) );
93 TestSetup test( sysRoot );
99 message( str::form( "*** Load system at '%s'", sysRoot.c_str() ) );
102 message( "*** load target" );
103 getZYpp()->initializeTarget( sysRoot );
104 getZYpp()->target()->load();
109 RepoManager repoManager( sysRoot );
110 RepoInfoList repos = repoManager.knownRepositories();
111 for_( it, repos.begin(), repos.end() )
113 RepoInfo & nrepo( *it );
115 if ( ! nrepo.enabled() )
118 if ( ! repoManager.isCached( nrepo ) )
120 message( str::form( "*** omit uncached repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) );
124 message( str::form( "*** load repo '%s'", nrepo.name().c_str() ) );
127 repoManager.loadFromCache( nrepo );
129 catch ( const Exception & exp )
131 message( exp.asString() + "\n" + exp.historyAsString() );
132 message( str::form( "*** omit broken repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) );
139 sat::Pool satpool( sat::Pool::instance() );
140 dumpRange( cerr, satpool.reposBegin(), satpool.reposEnd() ) << endl;
141 ///////////////////////////////////////////////////////////////////
143 bool ignorecase( true );
145 bool provides ( false );
146 bool requires ( false );
148 for ( ; argc; --argc,++argv )
150 if ( (*argv)[0] == '-' )
152 switch ( (*argv)[1] )
154 case 'a': names = true, requires = provides = true; break;
155 case 'A': names = true, requires = provides = false; break;
156 case 'i': ignorecase = true; break;
157 case 'I': ignorecase = false; break;
158 case 'n': names = true; break;
159 case 'N': names = false; break;
160 case 'r': requires = true; break;
161 case 'R': requires = false; break;
162 case 'p': provides = true; break;
163 case 'P': provides = false; break;
169 q.addString( *argv );
170 q.setMatchSubstring();
171 q.setCaseSensitive( ! ignorecase );
174 q.addAttribute( sat::SolvAttr::name );
176 q.addDependency( sat::SolvAttr::provides );
178 q.addDependency( sat::SolvAttr::requires );
181 // cerr << q << endl;
183 cerr << *argv << " [" << (ignorecase?'i':'_') << (names?'n':'_') << (requires?'r':'_') << (provides?'p':'_') << "] {" << endl;
185 for_( it, q.begin(), q.end() )
187 cerr << " " << it << endl;
193 INT << "===[END]============================================" << endl << endl;