1 #define INCLUDE_TESTSETUP_WITHOUT_BOOST
2 #include "zypp/../tests/lib/TestSetup.h"
3 #undef INCLUDE_TESTSETUP_WITHOUT_BOOST
6 #include <zypp/PoolQuery.h>
8 static std::string appname( "NameReqPrv" );
13 int errexit( const std::string & msg_r = std::string(), int exit_r = 100 )
15 if ( ! msg_r.empty() )
17 cerr << endl << msg_r << endl << endl;
22 int usage( const std::string & msg_r = std::string(), int exit_r = 100 )
24 if ( ! msg_r.empty() )
26 cerr << endl << msg_r << endl << endl;
28 cerr << "Usage: " << appname << " [--root ROOTDIR] [OPTIONS] NAME... [[OPTIONS] NAME...]..." << endl;
29 cerr << " Load all enabled repositories (no refresh) and search for" << endl;
30 cerr << " occurrences of NAME (regex) in package names, provides or" << endl;
31 cerr << " requires." << 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 << " -i/-I turn on/off case insensitive search (default on)" << endl;
35 cerr << " -n/-N turn on/off looking for names (default on)" << endl;
36 cerr << " -p/-P turn on/off looking for provides (default on)" << endl;
37 cerr << " -r/-R turn on/off looking for requires (default off)" << endl;
38 cerr << " -a short for -n -p -r" << endl;
39 cerr << " -A short for -n -P -R" << endl;
40 cerr << "TODO: Waiting for PoolQuery::allMatches switch and need to beautify output." << endl;
45 void tableOut( const std::string & s1 = std::string(),
46 const std::string & s2 = std::string(),
47 const std::string & s3 = std::string(),
48 const std::string & s4 = std::string(),
49 const std::string & s5 = std::string() )
52 #define TABEL(N) static unsigned w##N = 0; if ( ! s##N.empty() ) w##N = std::max( w##N, s##N.size() ); message << str::form( " %-*s ", w##N, s##N.c_str() )
53 #define TABER(N) static unsigned w##N = 0; if ( ! s##N.empty() ) w##N = std::max( w##N, s##N.size() ); message << str::form( " %*s ", w##N, s##N.c_str() )
54 TABER( 1 ); TABEL( 2 ); TABEL( 3 ); TABEL( 4 ); TABEL( 5 );
59 /******************************************************************
61 ** FUNCTION NAME : main
62 ** FUNCTION TYPE : int
64 int main( int argc, char * argv[] )
66 INT << "===[START]==========================================" << endl;
67 appname = Pathname::basename( argv[0] );
75 ///////////////////////////////////////////////////////////////////
78 Pathname sysRoot("/");
79 sat::Pool satpool( sat::Pool::instance() );
81 if ( (*argv) == std::string("--root") )
85 return errexit("--root requires an argument.");
87 if ( ! PathInfo( *argv ).isDir() )
88 return errexit("--root requires a directory.");
94 if ( TestSetup::isTestcase( sysRoot ) )
96 message << str::form( "*** Load Testcase from '%s'", sysRoot.c_str() ) << endl;
98 test.loadTestcaseRepos( sysRoot );
100 else if ( TestSetup::isTestSetup( sysRoot ) )
102 message << str::form( "*** Load TestSetup from '%s'", sysRoot.c_str() ) << endl;
103 TestSetup test( sysRoot, Arch_x86_64 );
109 message << str::form( "*** Load system at '%s'", sysRoot.c_str() ) << endl;
112 message << "*** load target '" << Repository::systemRepoAlias() << "'\t" << endl;
113 getZYpp()->initializeTarget( sysRoot );
114 getZYpp()->target()->load();
115 message << satpool.systemRepo() << endl;
120 RepoManager repoManager( sysRoot );
121 RepoInfoList repos = repoManager.knownRepositories();
122 for_( it, repos.begin(), repos.end() )
124 RepoInfo & nrepo( *it );
126 if ( ! nrepo.enabled() )
129 if ( ! repoManager.isCached( nrepo ) )
131 message << str::form( "*** omit uncached repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
135 message << str::form( "*** load repo '%s'\t", nrepo.name().c_str() ) << flush;
138 repoManager.loadFromCache( nrepo );
139 message << satpool.reposFind( nrepo.alias() ) << endl;
141 catch ( const Exception & exp )
143 message << exp.asString() + "\n" + exp.historyAsString() << endl;
144 message << str::form( "*** omit broken repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
151 ///////////////////////////////////////////////////////////////////
153 bool ignorecase( true );
155 bool provides ( true );
156 bool requires ( false );
158 for ( ; argc; --argc,++argv )
160 if ( (*argv)[0] == '-' )
162 switch ( (*argv)[1] )
164 case 'a': names = true, requires = provides = true; break;
165 case 'A': names = true, requires = provides = false; break;
166 case 'i': ignorecase = true; break;
167 case 'I': ignorecase = false; break;
168 case 'n': names = true; break;
169 case 'N': names = false; break;
170 case 'r': requires = true; break;
171 case 'R': requires = false; break;
172 case 'p': provides = true; break;
173 case 'P': provides = false; break;
179 std::string qstr( *argv );
182 q.setCaseSensitive( ! ignorecase );
185 q.addAttribute( sat::SolvAttr::name );
187 q.addDependency( sat::SolvAttr::provides );
189 q.addDependency( sat::SolvAttr::requires );
191 message << *argv << " [" << (ignorecase?'i':'_') << (names?'n':'_') << (requires?'r':'_') << (provides?'p':'_') << "] {" << endl;
193 for_( it, q.begin(), q.end() )
195 tableOut( str::numstring( it->id() ), it->asString(), it->repository().alias(), it->vendor().asString() );
196 //message << " " << *it << "(" << it->vendor() << ")";
197 if ( ! it.matchesEmpty() )
199 for_( match, it.matchesBegin(), it.matchesEnd() )
201 //tableOut( match->inSolvAttr().asString().substr( 9, 1 ), match->asString() );
202 tableOut( "", "", "", match->inSolvAttr().asString().substr( 9, 1 )+" " +match->asString() );
203 //message << endl << " " << match->inSolvAttr() << "\t" << match->asString();
209 message << "}" << endl;
212 INT << "===[END]============================================" << endl << endl;