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( "NameReqPrv" );
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... [[OPTIONS] NAME...]..." << endl;
30 cerr << " Load all enabled repositories (no refresh) and search for" << endl;
31 cerr << " occurrences of NAME (regex) in package names, provides or" << endl;
32 cerr << " requires." << 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 << " --installed Process installed packages only." << endl;
36 cerr << " -i/-I turn on/off case insensitive search (default on)" << endl;
37 cerr << " -n/-N turn on/off looking for names (default on)" << endl;
38 cerr << " -p/-P turn on/off looking for provides (default off)" << endl;
39 cerr << " -r/-R turn on/off looking for requires (default off)" << endl;
40 cerr << " -c/-C turn on/off looking for conflicts (default off)" << endl;
41 cerr << " -o/-O turn on/off looking for obsoletes (default off)" << endl;
42 cerr << " -m/-M turn on/off looking for recommends (default off)" << endl;
43 cerr << " -s/-S turn on/off looking for supplements (default off)" << endl;
44 cerr << " -a short for -n -p -r" << endl;
45 cerr << " -A short for -n -P -R" << endl;
46 cerr << " -D <pkg> dump dependencies of <pkg>" << endl;
51 void tableOut( const std::string & s1 = std::string(),
52 const std::string & s2 = std::string(),
53 const std::string & s3 = std::string(),
54 const std::string & s4 = std::string(),
55 const std::string & s5 = std::string() )
58 #define TABEL(N) static unsigned w##N = 0; if ( ! s##N.empty() ) w##N = std::max( w##N, unsigned(s##N.size()) ); message << str::form( " %-*s ", w##N, s##N.c_str() )
59 #define TABER(N) static unsigned w##N = 0; if ( ! s##N.empty() ) w##N = std::max( w##N, unsigned(s##N.size()) ); message << str::form( " %*s ", w##N, s##N.c_str() )
60 TABER( 1 ); TABEL( 2 ); TABEL( 3 ); TABEL( 4 ); TABEL( 5 );
66 ///////////////////////////////////////////////////////////////////
68 void dDump( const std::string & spec_r )
70 message << "DUMP " << spec_r << " {";
72 sat::WhatProvides q( Capability::guessPackageSpec( spec_r ) );
75 message << "}" << endl;
79 for ( const auto & el : q )
81 message << endl << "==============================" << endl << dump(el);
82 if ( isKind<Pattern>(el) )
84 message << endl << "CONTENT: " << make<Pattern>(el)->contents();
87 message << endl << "}" << endl;
90 /******************************************************************
92 ** FUNCTION NAME : main
93 ** FUNCTION TYPE : int
95 int main( int argc, char * argv[] )
97 INT << "===[START]==========================================" << endl;
98 appname = Pathname::basename( argv[0] );
106 ///////////////////////////////////////////////////////////////////
109 Pathname sysRoot("/");
110 sat::Pool satpool( sat::Pool::instance() );
112 if ( argc && (*argv) == std::string("--root") )
116 return errexit("--root requires an argument.");
118 if ( ! PathInfo( *argv ).isDir() )
119 return errexit("--root requires a directory.");
125 bool onlyInstalled( false );
126 if ( argc && (*argv) == std::string("--installed") )
129 onlyInstalled = true;
132 if ( TestSetup::isTestcase( sysRoot ) )
134 message << str::form( "*** Load Testcase from '%s'", sysRoot.c_str() ) << endl;
136 test.loadTestcaseRepos( sysRoot );
137 dumpRange( message, satpool.reposBegin(), satpool.reposEnd() ) << endl;
139 else if ( TestSetup::isTestSetup( sysRoot ) )
141 message << str::form( "*** Load TestSetup from '%s'", sysRoot.c_str() ) << endl;
142 TestSetup test( sysRoot, Arch_x86_64 );
144 dumpRange( message, satpool.reposBegin(), satpool.reposEnd() ) << endl;
149 message << str::form( "*** Load system at '%s'", sysRoot.c_str() ) << endl;
152 message << "*** load target '" << Repository::systemRepoAlias() << "'\t" << endl;
153 getZYpp()->initializeTarget( sysRoot );
154 getZYpp()->target()->load();
155 message << satpool.systemRepo() << endl;
158 if ( !onlyInstalled )
160 RepoManager repoManager( sysRoot );
161 RepoInfoList repos = repoManager.knownRepositories();
162 for_( it, repos.begin(), repos.end() )
164 RepoInfo & nrepo( *it );
166 if ( ! nrepo.enabled() )
169 if ( ! repoManager.isCached( nrepo ) )
171 message << str::form( "*** omit uncached repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
175 message << str::form( "*** load repo '%s'\t", nrepo.name().c_str() ) << flush;
178 repoManager.loadFromCache( nrepo );
179 message << satpool.reposFind( nrepo.alias() ) << endl;
181 catch ( const Exception & exp )
183 message << exp.asString() + "\n" + exp.historyAsString() << endl;
184 message << str::form( "*** omit broken repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
191 ///////////////////////////////////////////////////////////////////
193 bool ignorecase ( true );
195 bool provides ( false );
196 bool requires ( false );
197 bool conflicts ( false );
198 bool obsoletes ( false );
199 bool recommends ( false );
200 bool supplements ( false );
202 for ( ; argc; --argc,++argv )
204 if ( (*argv)[0] == '-' )
206 switch ( (*argv)[1] )
208 case 'a': names = true, requires = provides = true; break;
209 case 'A': names = true, requires = provides = false; break;
217 return errexit("-D <pkgspec> requires an argument.");
219 case 'i': ignorecase = true; break;
220 case 'I': ignorecase = false; break;
221 case 'n': names = true; break;
222 case 'N': names = false; break;
223 case 'r': requires = true; break;
224 case 'R': requires = false; break;
225 case 'p': provides = true; break;
226 case 'P': provides = false; break;
227 case 'c': conflicts = true; break;
228 case 'C': conflicts = false; break;
229 case 'o': obsoletes = true; break;
230 case 'O': obsoletes = false; break;
231 case 'm': recommends = true; break;
232 case 'M': recommends = false; break;
233 case 's': supplements = true; break;
234 case 'S': supplements = false; break;
241 q.setInstalledOnly();
242 std::string qstr( *argv );
244 if ( *argv == ResKind::product )
246 q.addKind( ResKind::product );
248 else if ( *argv == ResKind::patch )
250 q.addKind( ResKind::patch );
252 else if ( *argv == ResKind::pattern )
254 q.addKind( ResKind::pattern );
258 sat::Solvable::SplitIdent ident( qstr );
259 if ( ident.kind() != ResKind::package )
261 q.addKind( ident.kind() );
262 q.addString( ident.name().asString() );
268 q.setCaseSensitive( ! ignorecase );
271 q.addAttribute( sat::SolvAttr::name );
273 q.addDependency( sat::SolvAttr::provides );
275 q.addDependency( sat::SolvAttr::requires );
277 q.addDependency( sat::SolvAttr::conflicts );
279 q.addDependency( sat::SolvAttr::obsoletes );
281 q.addDependency( sat::SolvAttr::recommends );
283 q.addDependency( sat::SolvAttr::supplements );
286 message << *argv << " [" << (ignorecase?'i':'_') << (names?'n':'_') << (requires?'r':'_') << (provides?'p':'_')
287 << (conflicts?'c':'_') << (obsoletes?'o':'_') << (recommends?'m':'_') << (supplements?'s':'_') << "] {" << endl;
289 for_( it, q.begin(), q.end() )
291 tableOut( str::numstring( it->id() ), it->asString(),
292 str::form( "(%d)%s", it->repository().info().priority(), it->repository().name().c_str() ),
293 it->vendor().asString(),
294 str::numstring( PoolItem(*it)->buildtime() ) );
295 if ( ! it.matchesEmpty() )
297 for_( match, it.matchesBegin(), it.matchesEnd() )
299 tableOut( "", "", "", match->inSolvAttr().asString().substr( 9, 3 )+": " +match->asString() );
304 message << "}" << endl;
307 INT << "===[END]============================================" << endl << endl;