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" );
12 int errexit( const std::string & msg_r = std::string(), int exit_r = 100 )
14 if ( ! msg_r.empty() )
16 cerr << endl << msg_r << endl << endl;
21 int usage( const std::string & msg_r = std::string(), int exit_r = 100 )
23 if ( ! msg_r.empty() )
25 cerr << endl << msg_r << endl << endl;
27 cerr << "Usage: " << appname << " [--root ROOTDIR] [OPTIONS] NAME... [[OPTIONS] NAME...]..." << endl;
28 cerr << " Load all enabled repositories (no refresh) and search for" << endl;
29 cerr << " occurrences of NAME (substring) in package names, provides or" << endl;
30 cerr << " requires." << endl;
31 cerr << " --root Load repos from the system located below ROOTDIR. If ROOTDIR" << endl;
32 cerr << " denotes a sover testcase, the testcase is loaded." << endl;
33 cerr << " -i/-I turn on/off case insensitive search (default on)" << endl;
34 cerr << " -n/-N turn on/off looking for names (default on)" << endl;
35 cerr << " -p/-P turn on/off looking for provides (default on)" << endl;
36 cerr << " -r/-R turn on/off looking for requires (default off)" << endl;
37 cerr << " -a short for -n -p -r" << endl;
38 cerr << " -A short for -n -P -R" << endl;
39 cerr << "TODO: Waiting for PoolQuery::allMatches switch and need to beautify output." << endl;
44 /******************************************************************
46 ** FUNCTION NAME : main
47 ** FUNCTION TYPE : int
49 int main( int argc, char * argv[] )
51 INT << "===[START]==========================================" << endl;
52 appname = Pathname::basename( argv[0] );
60 ///////////////////////////////////////////////////////////////////
63 Pathname sysRoot("/");
64 sat::Pool satpool( sat::Pool::instance() );
66 if ( (*argv) == std::string("--root") )
70 return errexit("--root requires an argument.");
72 if ( ! PathInfo( *argv ).isDir() )
73 return errexit("--root requires a directory.");
79 if ( TestSetup::isTestcase( sysRoot ) )
81 message << str::form( "*** Load Testcase from '%s'", sysRoot.c_str() ) << endl;
83 test.loadTestcaseRepos( sysRoot );
85 else if ( TestSetup::isTestSetup( sysRoot ) )
87 message << str::form( "*** Load TestSetup from '%s'", sysRoot.c_str() ) << endl;
88 TestSetup test( sysRoot );
94 message << str::form( "*** Load system at '%s'", sysRoot.c_str() ) << endl;
97 message << "*** load target '" << Repository::systemRepoAlias() << "'\t" << endl;
98 getZYpp()->initializeTarget( sysRoot );
99 getZYpp()->target()->load();
100 message << satpool.systemRepo() << endl;
105 RepoManager repoManager( sysRoot );
106 RepoInfoList repos = repoManager.knownRepositories();
107 for_( it, repos.begin(), repos.end() )
109 RepoInfo & nrepo( *it );
111 if ( ! nrepo.enabled() )
114 if ( ! repoManager.isCached( nrepo ) )
116 message << str::form( "*** omit uncached repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
120 message << str::form( "*** load repo '%s'\t", nrepo.name().c_str() ) << flush;
123 repoManager.loadFromCache( nrepo );
124 message << satpool.reposFind( nrepo.alias() ) << endl;
126 catch ( const Exception & exp )
128 message << exp.asString() + "\n" + exp.historyAsString() << endl;
129 message << str::form( "*** omit broken repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
136 ///////////////////////////////////////////////////////////////////
138 bool ignorecase( true );
140 bool provides ( true );
141 bool requires ( false );
143 for ( ; argc; --argc,++argv )
145 if ( (*argv)[0] == '-' )
147 switch ( (*argv)[1] )
149 case 'a': names = true, requires = provides = true; break;
150 case 'A': names = true, requires = provides = false; break;
151 case 'i': ignorecase = true; break;
152 case 'I': ignorecase = false; break;
153 case 'n': names = true; break;
154 case 'N': names = false; break;
155 case 'r': requires = true; break;
156 case 'R': requires = false; break;
157 case 'p': provides = true; break;
158 case 'P': provides = false; break;
164 q.addString( *argv );
165 q.setMatchSubstring();
166 q.setCaseSensitive( ! ignorecase );
169 q.addAttribute( sat::SolvAttr::name );
171 q.addDependency( sat::SolvAttr::provides );
173 q.addDependency( sat::SolvAttr::requires );
175 message << *argv << " [" << (ignorecase?'i':'_') << (names?'n':'_') << (requires?'r':'_') << (provides?'p':'_') << "] {" << endl;
177 for_( it, q.begin(), q.end() )
179 message << " " << dump(it) << endl;
182 message << "}" << endl;
185 INT << "===[END]============================================" << endl << endl;