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 off)" << 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;
44 void tableOut( const std::string & s1 = std::string(),
45 const std::string & s2 = std::string(),
46 const std::string & s3 = std::string(),
47 const std::string & s4 = std::string(),
48 const std::string & s5 = std::string() )
51 #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() )
52 #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() )
53 TABER( 1 ); TABEL( 2 ); TABEL( 3 ); TABEL( 4 ); TABEL( 5 );
58 /******************************************************************
60 ** FUNCTION NAME : main
61 ** FUNCTION TYPE : int
63 int main( int argc, char * argv[] )
65 INT << "===[START]==========================================" << endl;
66 appname = Pathname::basename( argv[0] );
74 ///////////////////////////////////////////////////////////////////
77 Pathname sysRoot("/");
78 sat::Pool satpool( sat::Pool::instance() );
80 if ( (*argv) == std::string("--root") )
84 return errexit("--root requires an argument.");
86 if ( ! PathInfo( *argv ).isDir() )
87 return errexit("--root requires a directory.");
93 if ( TestSetup::isTestcase( sysRoot ) )
95 message << str::form( "*** Load Testcase from '%s'", sysRoot.c_str() ) << endl;
97 test.loadTestcaseRepos( sysRoot );
99 else if ( TestSetup::isTestSetup( sysRoot ) )
101 message << str::form( "*** Load TestSetup from '%s'", sysRoot.c_str() ) << endl;
102 TestSetup test( sysRoot, Arch_x86_64 );
108 message << str::form( "*** Load system at '%s'", sysRoot.c_str() ) << endl;
111 message << "*** load target '" << Repository::systemRepoAlias() << "'\t" << endl;
112 getZYpp()->initializeTarget( sysRoot );
113 getZYpp()->target()->load();
114 message << satpool.systemRepo() << endl;
119 RepoManager repoManager( sysRoot );
120 RepoInfoList repos = repoManager.knownRepositories();
121 for_( it, repos.begin(), repos.end() )
123 RepoInfo & nrepo( *it );
125 if ( ! nrepo.enabled() )
128 if ( ! repoManager.isCached( nrepo ) )
130 message << str::form( "*** omit uncached repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
134 message << str::form( "*** load repo '%s'\t", nrepo.name().c_str() ) << flush;
137 repoManager.loadFromCache( nrepo );
138 message << satpool.reposFind( nrepo.alias() ) << endl;
140 catch ( const Exception & exp )
142 message << exp.asString() + "\n" + exp.historyAsString() << endl;
143 message << str::form( "*** omit broken repo '%s' (do 'zypper refresh')", nrepo.name().c_str() ) << endl;
150 ///////////////////////////////////////////////////////////////////
152 bool ignorecase( true );
154 bool provides ( false );
155 bool requires ( false );
157 for ( ; argc; --argc,++argv )
159 if ( (*argv)[0] == '-' )
161 switch ( (*argv)[1] )
163 case 'a': names = true, requires = provides = true; break;
164 case 'A': names = true, requires = provides = false; break;
165 case 'i': ignorecase = true; break;
166 case 'I': ignorecase = false; break;
167 case 'n': names = true; break;
168 case 'N': names = false; break;
169 case 'r': requires = true; break;
170 case 'R': requires = false; break;
171 case 'p': provides = true; break;
172 case 'P': provides = false; break;
178 std::string qstr( *argv );
181 q.setCaseSensitive( ! ignorecase );
184 q.addAttribute( sat::SolvAttr::name );
186 q.addDependency( sat::SolvAttr::provides );
188 q.addDependency( sat::SolvAttr::requires );
190 message << *argv << " [" << (ignorecase?'i':'_') << (names?'n':'_') << (requires?'r':'_') << (provides?'p':'_') << "] {" << endl;
192 for_( it, q.begin(), q.end() )
194 tableOut( str::numstring( it->id() ), it->asString(), it->repository().alias(), it->vendor().asString(),
195 str::numstring( PoolItem(*it)->buildtime() ) );
196 if ( ! it.matchesEmpty() )
198 for_( match, it.matchesBegin(), it.matchesEnd() )
200 tableOut( "", "", "", match->inSolvAttr().asString().substr( 9, 1 )+" " +match->asString() );
205 message << "}" << endl;
208 INT << "===[END]============================================" << endl << endl;