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 ( (*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 ( (*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 );
107 else if ( TestSetup::isTestSetup( sysRoot ) )
109 message << str::form( "*** Load TestSetup from '%s'", sysRoot.c_str() ) << endl;
110 TestSetup test( sysRoot, Arch_x86_64 );
116 message << str::form( "*** Load system at '%s'", sysRoot.c_str() ) << endl;
119 message << "*** load target '" << Repository::systemRepoAlias() << "'\t" << endl;
120 getZYpp()->initializeTarget( sysRoot );
121 getZYpp()->target()->load();
122 message << satpool.systemRepo() << endl;
125 if ( !onlyInstalled )
127 RepoManager repoManager( sysRoot );
128 RepoInfoList repos = repoManager.knownRepositories();
129 for_( it, repos.begin(), repos.end() )
131 RepoInfo & nrepo( *it );
133 if ( ! nrepo.enabled() )
136 if ( ! repoManager.isCached( nrepo ) )
138 message << str::form( "*** omit uncached repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
142 message << str::form( "*** load repo '%s'\t", nrepo.name().c_str() ) << flush;
145 repoManager.loadFromCache( nrepo );
146 message << satpool.reposFind( nrepo.alias() ) << endl;
148 catch ( const Exception & exp )
150 message << exp.asString() + "\n" + exp.historyAsString() << endl;
151 message << str::form( "*** omit broken repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
158 ///////////////////////////////////////////////////////////////////
160 bool ignorecase( true );
162 bool provides ( false );
163 bool requires ( false );
165 for ( ; argc; --argc,++argv )
167 if ( (*argv)[0] == '-' )
169 switch ( (*argv)[1] )
171 case 'a': names = true, requires = provides = true; break;
172 case 'A': names = true, requires = provides = false; break;
173 case 'i': ignorecase = true; break;
174 case 'I': ignorecase = false; break;
175 case 'n': names = true; break;
176 case 'N': names = false; break;
177 case 'r': requires = true; break;
178 case 'R': requires = false; break;
179 case 'p': provides = true; break;
180 case 'P': provides = false; break;
186 std::string qstr( *argv );
189 q.setCaseSensitive( ! ignorecase );
192 q.addAttribute( sat::SolvAttr::name );
194 q.addDependency( sat::SolvAttr::provides );
196 q.addDependency( sat::SolvAttr::requires );
198 message << *argv << " [" << (ignorecase?'i':'_') << (names?'n':'_') << (requires?'r':'_') << (provides?'p':'_') << "] {" << endl;
200 for_( it, q.begin(), q.end() )
202 tableOut( str::numstring( it->id() ), it->asString(), it->repository().alias(), it->vendor().asString(),
203 str::numstring( PoolItem(*it)->buildtime() ) );
204 if ( ! it.matchesEmpty() )
206 for_( match, it.matchesBegin(), it.matchesEnd() )
208 tableOut( "", "", "", match->inSolvAttr().asString().substr( 9, 1 )+" " +match->asString() );
213 message << "}" << endl;
216 INT << "===[END]============================================" << endl << endl;