Author: dmacvicar
Date: Tue May 6 17:32:36 2008
New Revision: 9961
URL: http://svn.opensuse.org/viewcvs/zypp?rev=9961&view=rev
Log:
add -i option to query pool for installed objects
Modified:
trunk/libzypp/tools/registration/zypp-query-pool.cc
Modified: trunk/libzypp/tools/registration/zypp-query-pool.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/libzypp/tools/registration/zypp-query-pool.cc?rev=9961&r1=9960&r2=9961&view=diff
==============================================================================
--- trunk/libzypp/tools/registration/zypp-query-pool.cc (original)
+++ trunk/libzypp/tools/registration/zypp-query-pool.cc Tue May 6 17:32:36 2008
@@ -10,6 +10,8 @@
#include
#include
#include
+#include
+#include
#undef ZYPP_BASE_LOGGER_LOGGROUP
#define ZYPP_BASE_LOGGER_LOGGROUP "zypp-query-pool"
@@ -18,6 +20,19 @@
using namespace std;
using namespace zypp;
+using namespace zypp::resfilter;
+
+struct ByPresent : public PoolItemFilterFunctor
+{
+ bool operator()( const PoolItem & p ) const
+ {
+ if ( isKind<Package>(p.resolvable()) )
+ return p.status().isInstalled();
+ else
+ return p.status().isSatisfied();
+ }
+};
+
//-----------------------------------------------------------------------------
@@ -64,7 +79,10 @@
static void
-query_pool( ZYpp::Ptr Z, string filter, const string & repository)
+query_pool( ZYpp::Ptr Z,
+ string filter,
+ const string & repository,
+ bool installed_only )
{
Resolvable::Kind kind;
@@ -77,80 +95,75 @@
else if (filter == "products") kind = ResTraitszypp::Product::kind;
else if (filter != FILTER_ALL)
{
- std::cerr << "usage: zypp-query-pool [packages|patches|patterns|products] [<alias>]" << endl;
+ std::cerr << "usage: zypp-query-pool [-i] [packages|patches|patterns|products] [<alias>]" << endl;
exit( 1 );
}
- bool system = (repository == "@system");
-
MIL << "query_pool kind '" << kind << "', repository '" << repository << "'" << endl;
- if (!system)
+ try
{
- try
- {
MIL << "Load enabled repositories..." << endl;
RepoManager repoManager;
RepoInfoList repos = repoManager.knownRepositories();
for ( RepoInfoList::iterator it = repos.begin(); it != repos.end(); ++it )
{
- RepoInfo & repo( *it );
-
- if ( ! repo.enabled() )
- continue;
-
- MIL << "Loading " << repo << endl;
- if ( ! repoManager.isCached( repo ) )
- {
- MIL << "Must build cache..." << repo << endl;
- repoManager.buildCache( repo );
- }
- repoManager.loadFromCache( repo );
+ RepoInfo & repo( *it );
+
+ if ( ! repo.enabled() )
+ continue;
+
+ MIL << "Loading " << repo << endl;
+ if ( ! repoManager.isCached( repo ) )
+ {
+ MIL << "Must build cache..." << repo << endl;
+ repoManager.buildCache( repo );
+ }
+ repoManager.loadFromCache( repo );
}
MIL << "Loaded enabled repositories." << endl;
- }
- catch (Exception & excpt_r)
- {
+ }
+ catch (Exception & excpt_r)
+ {
ZYPP_CAUGHT( excpt_r );
ERR << "Couldn't restore sources" << endl;
exit( 1 );
- }
}
- // add resolvables from the system
+// add resolvables from the system
MIL << "Loading target..." << endl;
Z->target()->load();
MIL << "Loaded target." << endl;
-
+
MIL << "Pool has " << Z->pool().size() << " entries" << endl;
-
- // solve to get the status satisfied available
+
+// solve to get the status satisfied available
getZYpp()->resolver()->resolvePool();
-
+
if ( filter == FILTER_ALL)
{
- PrintItem printitem( system ? "" : repository );
- if (system)
- zypp::invokeOnEach( Z->pool().begin(), Z->pool().end(), // all kinds
- zypp::resfilter::ByInstalled(),
- zypp::functor::functorRef (printitem) );
- else
- zypp::invokeOnEach( Z->pool().begin(), Z->pool().end(), // all kinds
- zypp::functor::functorRef (printitem) );
-
+ PrintItem printitem( repository );
+ if (installed_only)
+ zypp::invokeOnEach( Z->pool().begin(), Z->pool().end(), // all kinds
+ ByPresent(),
+ zypp::functor::functorRef (printitem) );
+ else
+ zypp::invokeOnEach( Z->pool().begin(), Z->pool().end(), // all kinds
+ zypp::functor::functorRef (printitem) );
+
}
- else
- {
- PrintItem printitem( system ? "" : repository );
- if (system)
- zypp::invokeOnEach( Z->pool().byKindBegin( kind ), Z->pool().byKindEnd( kind ), // filter kind
- zypp::resfilter::ByInstalled(),
- zypp::functor::functorRef (printitem) );
+else
+{
+ PrintItem printitem( repository );
+ if (installed_only)
+ zypp::invokeOnEach( Z->pool().byKindBegin( kind ), Z->pool().byKindEnd( kind ), // filter kind
+ ByPresent(),
+ zypp::functor::functorRef (printitem) );
else
- zypp::invokeOnEach( Z->pool().byKindBegin( kind ), Z->pool().byKindEnd( kind ), // filter kind
- zypp::functor::functorRef (printitem) );
- }
+ zypp::invokeOnEach( Z->pool().byKindBegin( kind ), Z->pool().byKindEnd( kind ), // filter kind
+ zypp::functor::functorRef (printitem) );
+}
return;
}
@@ -161,11 +174,27 @@
{
MIL << "-------------------------------------" << endl;
string filter;
- if (argc > 1)
- filter = argv[1];
string repository;
- if (argc > 2)
- repository = argv[2];
+ bool only_installed = false;
+ int offset = 1;
+
+ if ( (argc>1) && (string(argv[offset]) == "-i"))
+ {
+ only_installed = true;
+ ++offset; --argc;
+ }
+
+ if ( argc > 1 )
+ {
+ filter = argv[offset];
+ --argc; ++offset;
+
+ if ( argc > 1 )
+ {
+ repository = argv[offset];
+ ++offset; --argc;
+ }
+ }
MIL << "START zypp-query-pool " << filter << " " << repository << endl;
@@ -177,7 +206,9 @@
Z->initializeTarget( "/" );
- query_pool( Z, filter, repository );
+ std::cout << argc << "#" << filter << std::endl;
+
+ query_pool( Z, filter, repository, only_installed );
MIL << "END zypp-query-pool, result 0" << endl;
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org