From 3eaf520f5b9e96dfbac20974052322e0cc0b5a59 Mon Sep 17 00:00:00 2001 From: Gabriele Mohr Date: Wed, 24 Jul 2013 12:12:36 +0200 Subject: [PATCH] add --orphaned, --suggested, --recommended, --unneeded to 'zypper packages' --- doc/zypper.8 | 18 ++++++++++++++-- src/Zypper.cc | 8 ++++++++ src/search.cc | 66 +++++++++++++++++++++++++++++++++++++++++++++++++++++++++-- 3 files changed, 88 insertions(+), 4 deletions(-) diff --git a/doc/zypper.8 b/doc/zypper.8 index d4c4d98..c834c91 100644 --- a/doc/zypper.8 +++ b/doc/zypper.8 @@ -907,8 +907,10 @@ Look for RSI acronym (case-sensitively), also in summaries and descriptions: .TP .B packages (pa) [options] [repository] ... -List all available packages or all packages from specified repositories. -Similar to \fBzypper search -s -t package\fR. +List all available packages or all packages from specified repositories +(similar to \fBzypper search -s -t package\fR). +Also allows the options \fI\-\-orphaned\fR, \fI\-\-suggested\fR, \fI\-\-recommended\fR +and \fI\-\-unneeded\fR to get corresponding lists of packages. .TP .I \-r, \-\-repo Just another means to specify repositories. @@ -918,6 +920,18 @@ Show only installed packages. .TP .I \-u, \-\-uninstalled\-only Show only packages which are not installed. +.TP +.I \-o, \-\-orphaned +Show packages which are orphaned (without repository). +.TP +.I \-s, \-\-suggested +Show packages which are suggested. +.TP +.I \-r, \-\-recommended +Show packages which are recommeded. +.TP +.I \-n, \-\-unneeded +Show packages which are unneeded. .TP .B patches (pch) [options] [repository] ... diff --git a/src/Zypper.cc b/src/Zypper.cc index 54c1965..7fc5e25 100644 --- a/src/Zypper.cc +++ b/src/Zypper.cc @@ -2019,6 +2019,10 @@ void Zypper::processCommandOptions() {"catalog", required_argument, 0, 'c'}, {"installed-only", no_argument, 0, 'i'}, {"uninstalled-only", no_argument, 0, 'u'}, + {"orphaned", no_argument, 0, 'o'}, + {"suggested", no_argument, 0, 's'}, + {"recommended", no_argument, 0, 'r'}, + {"unneeded", no_argument, 0, 'n'}, {"sort-by-name", no_argument, 0, 'N'}, {"sort-by-repo", no_argument, 0, 'R'}, {"sort-by-catalog", no_argument, 0, 0}, @@ -2036,6 +2040,10 @@ void Zypper::processCommandOptions() "-r, --repo Just another means to specify repository.\n" "-i, --installed-only Show only installed packages.\n" "-u, --uninstalled-only Show only packages which are not installed.\n" + "-o, --orphaned Show packages which are orphaned (without repository).\n" + "-s, --suggested Show packages which are suggested.\n" + "-r, --recommended Show packages which are recommended.\n" + "-n, --unneeded Show packages which are unneeded.\n" "-N, --sort-by-name Sort the list by package name.\n" "-R, --sort-by-repo Sort the list by repository.\n" ); diff --git a/src/search.cc b/src/search.cc index 205e790..6e13164 100644 --- a/src/search.cc +++ b/src/search.cc @@ -512,6 +512,28 @@ void list_patterns(Zypper & zypper) list_pattern_table(zypper); } +static bool check_bits( PoolItem pi, Zypper & zypper ) +{ + bool orphaned = zypper.cOpts().count("orphaned"); + bool suggested = zypper.cOpts().count("suggested"); + bool recommended = zypper.cOpts().count("recommended"); + bool unneeded = zypper.cOpts().count("unneeded"); + + if ( orphaned && !pi.status().isOrphaned() ) + return false; + + if ( suggested && !pi.status().isSuggested() ) + return false; + + if ( recommended && !pi.status().isRecommended() ) + return false; + + if ( unneeded && !pi.status().isUnneeded() ) + return false; + + return true; +} + void list_packages(Zypper & zypper) { MIL << "Going to list packages." << std::endl; @@ -531,6 +553,14 @@ void list_packages(Zypper & zypper) bool installed_only = zypper.cOpts().count("installed-only"); bool notinst_only = zypper.cOpts().count("uninstalled-only"); + bool check = false; + + if ( zypper.cOpts().count("orphaned") || zypper.cOpts().count("suggested") || + zypper.cOpts().count("recommended") || zypper.cOpts().count("unneeded") ) + { + check = true; + God->resolver()->resolvePool(); + } ResPoolProxy::const_iterator it = God->pool().proxy().byKindBegin(ResKind::package), @@ -538,18 +568,50 @@ void list_packages(Zypper & zypper) for (; it != e; ++it ) { ui::Selectable::constPtr s = *it; + bool found = false; // get the first installed object PoolItem installed; if (!s->installedEmpty()) installed = s->installedObj(); - // show available objects - for_(it, s->availableBegin(), s->availableEnd()) + // If asked for package classification and there is an installed obj, check this first. + // The corresponding bits are set only for installed packages and these are NOT in the + // pick list if an identical obj (candidate) from a repo is available. + if ( check ) + { + if ( installed ) + { + if ( check_bits( installed, zypper ) ) + { + found = true; + } + } + else + { + for_(it, s->picklistBegin(), s->picklistEnd()) + { + if ( check_bits( (*it), zypper ) ) + { + found = true; + continue; + } + } + } + } + + if ( check && !found ) + continue; + + // Don't use availableBegin/End here, there would be packages lost. The pick list + // additionally contains packages without a repo (the orphaned ones) as well as + // the installed ones having other version than available from any repo. + for_(it, s->picklistBegin(), s->picklistEnd()) { TableRow row; zypp::PoolItem pi = *it; + if (installed) { if (notinst_only) -- 2.7.4