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 << " --installed Process installed packages only." << endl;
35 cerr << " -i/-I turn on/off case insensitive search (default on)" << endl;
36 cerr << " -n/-N turn on/off looking for names (default on)" << endl;
37 cerr << " -p/-P turn on/off looking for provides (default off)" << endl;
38 cerr << " -r/-R turn on/off looking for requires (default off)" << endl;
39 cerr << " -a short for -n -p -r" << endl;
40 cerr << " -A short for -n -P -R" << 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, unsigned(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, unsigned(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 ( argc && (*argv) == std::string("--root") )
85 return errexit("--root requires an argument.");
87 if ( ! PathInfo( *argv ).isDir() )
88 return errexit("--root requires a directory.");
94 bool onlyInstalled( false );
95 if ( argc && (*argv) == std::string("--installed") )
101 if ( TestSetup::isTestcase( sysRoot ) )
103 message << str::form( "*** Load Testcase from '%s'", sysRoot.c_str() ) << endl;
105 test.loadTestcaseRepos( sysRoot );
106 dumpRange( message, satpool.reposBegin(), satpool.reposEnd() ) << endl;
108 else if ( TestSetup::isTestSetup( sysRoot ) )
110 message << str::form( "*** Load TestSetup from '%s'", sysRoot.c_str() ) << endl;
111 TestSetup test( sysRoot, Arch_x86_64 );
113 dumpRange( message, satpool.reposBegin(), satpool.reposEnd() ) << endl;
118 message << str::form( "*** Load system at '%s'", sysRoot.c_str() ) << endl;
121 message << "*** load target '" << Repository::systemRepoAlias() << "'\t" << endl;
122 getZYpp()->initializeTarget( sysRoot );
123 getZYpp()->target()->load();
124 message << satpool.systemRepo() << endl;
127 if ( !onlyInstalled )
129 RepoManager repoManager( sysRoot );
130 RepoInfoList repos = repoManager.knownRepositories();
131 for_( it, repos.begin(), repos.end() )
133 RepoInfo & nrepo( *it );
135 if ( ! nrepo.enabled() )
138 if ( ! repoManager.isCached( nrepo ) )
140 message << str::form( "*** omit uncached repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
144 message << str::form( "*** load repo '%s'\t", nrepo.name().c_str() ) << flush;
147 repoManager.loadFromCache( nrepo );
148 message << satpool.reposFind( nrepo.alias() ) << endl;
150 catch ( const Exception & exp )
152 message << exp.asString() + "\n" + exp.historyAsString() << endl;
153 message << str::form( "*** omit broken repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
160 ///////////////////////////////////////////////////////////////////
162 bool ignorecase( true );
164 bool provides ( false );
165 bool requires ( false );
167 for ( ; argc; --argc,++argv )
169 if ( (*argv)[0] == '-' )
171 switch ( (*argv)[1] )
173 case 'a': names = true, requires = provides = true; break;
174 case 'A': names = true, requires = provides = false; break;
175 case 'i': ignorecase = true; break;
176 case 'I': ignorecase = false; break;
177 case 'n': names = true; break;
178 case 'N': names = false; break;
179 case 'r': requires = true; break;
180 case 'R': requires = false; break;
181 case 'p': provides = true; break;
182 case 'P': provides = false; break;
189 q.setInstalledOnly();
190 std::string qstr( *argv );
192 if ( *argv == ResKind::product )
194 q.addKind( ResKind::product );
196 else if ( *argv == ResKind::patch )
198 q.addKind( ResKind::patch );
200 else if ( *argv == ResKind::pattern )
202 q.addKind( ResKind::pattern );
208 q.setCaseSensitive( ! ignorecase );
211 q.addAttribute( sat::SolvAttr::name );
213 q.addDependency( sat::SolvAttr::provides );
215 q.addDependency( sat::SolvAttr::requires );
218 message << *argv << " [" << (ignorecase?'i':'_') << (names?'n':'_') << (requires?'r':'_') << (provides?'p':'_') << "] {" << endl;
220 for_( it, q.begin(), q.end() )
222 tableOut( str::numstring( it->id() ), it->asString(), it->repository().name(), it->vendor().asString(),
223 str::numstring( PoolItem(*it)->buildtime() ) );
224 if ( ! it.matchesEmpty() )
226 for_( match, it.matchesBegin(), it.matchesEnd() )
228 tableOut( "", "", "", match->inSolvAttr().asString().substr( 9, 1 )+" " +match->asString() );
233 message << "}" << endl;
236 INT << "===[END]============================================" << endl << endl;