const ZypperCommand ZypperCommand::INFO(ZypperCommand::INFO_e);
const ZypperCommand ZypperCommand::LIST_UPDATES(ZypperCommand::LIST_UPDATES_e);
const ZypperCommand ZypperCommand::PATCH_CHECK(ZypperCommand::PATCH_CHECK_e);
-//const ZypperCommand ZypperCommand::PACKAGES(ZypperCommand::PACKAGES_e);
+const ZypperCommand ZypperCommand::PACKAGES(ZypperCommand::PACKAGES_e);
const ZypperCommand ZypperCommand::PATCHES(ZypperCommand::PATCHES_e);
const ZypperCommand ZypperCommand::PATTERNS(ZypperCommand::PATTERNS_e);
-//const ZypperCommand ZypperCommand::PRODUCTS(ZypperCommand::PRODUCTS_e);
+const ZypperCommand ZypperCommand::PRODUCTS(ZypperCommand::PRODUCTS_e);
const ZypperCommand ZypperCommand::XML_LIST_UPDATES_PATCHES(ZypperCommand::XML_LIST_UPDATES_PATCHES_e);
const ZypperCommand ZypperCommand::ADD_LOCK(ZypperCommand::ADD_LOCK_e);
_table["info"] = _table["if"] = ZypperCommand::INFO_e;
_table["list-updates"] = _table["lu"] = ZypperCommand::LIST_UPDATES_e;
_table["patch-check"] = _table["pchk"] = ZypperCommand::PATCH_CHECK_e;
- //_table["packages"] = _table["pa"] = _table["pkg"] = ZypperCommand::PACKAGES_e;
+ _table["packages"] = _table["pa"] = _table["pkg"] = ZypperCommand::PACKAGES_e;
_table["patches"] = _table["pch"] = ZypperCommand::PATCHES_e;
_table["patterns"] = _table["pt"] = ZypperCommand::PATTERNS_e;
- //_table["products"] = _table["pd"] = ZypperCommand::PRODUCTS_e;
+ _table["products"] = _table["pd"] = ZypperCommand::PRODUCTS_e;
_table["xml-updates"] = _table["xu"] = ZypperCommand::XML_LIST_UPDATES_PATCHES_e;
_table["addlock"] = _table["al"] = _table["lock-add"] = _table["la"] = ZypperCommand::ADD_LOCK_e;
static const ZypperCommand INFO;
static const ZypperCommand LIST_UPDATES;
static const ZypperCommand PATCH_CHECK;
- //static const ZypperCommand PACKAGES;
+ static const ZypperCommand PACKAGES;
static const ZypperCommand PATCHES;
static const ZypperCommand PATTERNS;
- //static const ZypperCommand PRODUCTS;
+ static const ZypperCommand PRODUCTS;
static const ZypperCommand XML_LIST_UPDATES_PATCHES;
static const ZypperCommand ADD_LOCK;
INFO_e,
LIST_UPDATES_e,
PATCH_CHECK_e,
- //PACKAGES_e,
+ PACKAGES_e,
PATCHES_e,
PATTERNS_e,
- //PRODUCTS_e,
+ PRODUCTS_e,
XML_LIST_UPDATES_PATCHES_e,
ADD_LOCK_e,
#include "zypp/Patch.h"
#include "zypp/Pattern.h"
+#include "zypp/ResPoolProxy.h"
+
#include "zypper.h"
#include "zypper-main.h"
#include "zypper-tabulator.h"
extern ZYpp::Ptr God;
+
+string selectable_search_repo_str(const ui::Selectable & s)
+{
+ string repostr;
+ for_(it, s.installedBegin(), s.installedEnd())
+ {
+ if (!(*it)->repository().isSystemRepo())
+ {
+ cout << "can this ever be true?" << endl;
+ if (repostr.empty())
+ repostr = (*it)->repository().info().name();
+ else
+ {
+ repostr = _("(multiple)");
+ return repostr;
+ }
+ }
+ }
+
+ // show available objects
+ for_(it, s.availableBegin(), s.availableEnd())
+ {
+ if (repostr.empty())
+ repostr = (*it)->repository().info().name();
+ else
+ {
+ repostr = _("(multiple)");
+ return repostr;
+ }
+ }
+
+ return string();
+}
+
+
static string string_status (const ResStatus& rs)
{
return rs.isInstalled () ? _("Installed"): _("Uninstalled");
}
+
static string string_weak_status(const ResStatus & rs)
{
if (rs.isRecommended())
cout << tbl;
}
+void list_packages(Zypper & zypper)
+{
+ MIL << "Going to list patterns." << std::endl;
+
+ Table tbl;
+ TableHeader th;
+
+ // translators: S for installed Status
+ th << _("S");
+ if (zypper.globalOpts().is_rug_compatible)
+ // translators: Bundle is a term used in rug. See rug for how to translate it.
+ th << _("Bundle");
+ else
+ th << _("Repository");
+ th << _("Name") << _("Version") << _("Arch");
+ tbl << th;
+
+ bool installed_only = zypper.cOpts().count("installed-only");
+ bool notinst_only = zypper.cOpts().count("uninstalled-only");
+
+ ResPoolProxy::const_iterator
+ it = God->pool().proxy().byKindBegin(ResKind::package),
+ e = God->pool().proxy().byKindEnd(ResKind::package);
+ for (; it != e; ++it )
+ {
+ ui::Selectable::constPtr s = *it;
+
+ // get the first installed object
+ PoolItem installed;
+ if (!s->installedEmpty())
+ installed = s->installedObj();
+
+ // show available objects
+ for_(it, s->availableBegin(), s->availableEnd())
+ {
+ TableRow row;
+
+ zypp::PoolItem pi = *it;
+ if (installed)
+ {
+ if (notinst_only)
+ continue;
+ row << (equalNVRA(*installed.resolvable(), *pi.resolvable()) ? "i" : "v");
+ }
+ else
+ {
+ if (installed_only)
+ continue;
+ row << "";
+ }
+ row << (zypper.globalOpts().is_rug_compatible ? "" : pi->repository().info().name())
+ << pi->name()
+ << pi->edition().asString()
+ << pi->arch().asString();
+
+ tbl << row;
+ }
+ }
+ if (zypper.cOpts().count("sort-by-repo") || zypper.cOpts().count("sort-by-catalog"))
+ tbl.sort(1); // Repo
+ else
+ tbl.sort(2); // Name
+
+ if (tbl.empty())
+ zypper.out().info(_("No packages found."));
+ else
+ // display the result, even if --quiet specified
+ cout << tbl;
+}
+
+
// Local Variables:
// c-basic-offset: 2
// End:
#include "zypper-utils.h" // for kind_to_string_localized
#include "zypper-tabulator.h"
+std::string selectable_search_repo_str(const zypp::ui::Selectable & s);
+
/**
* Functor for filling search output table in rug style.
*/
-struct FillTable
+struct FillSearchTableSolvable
{
// the table used for output
Table * _table;
const GlobalOptions & _gopts;
- FillTable( Table & table )
+ FillSearchTableSolvable( Table & table )
: _table( &table )
, _gopts(Zypper::instance()->globalOpts())
{
TableHeader header;
- // TranslatorExplanation S as Status
+ // translators: S for installed Status
header << _("S");
if (_gopts.is_rug_compatible)
header << _("Repository");
if (_gopts.is_rug_compatible)
- // TranslatorExplanation This is Bundle in as used in rug.
+ // translators: Bundle is a term used in rug. See rug for how to translate it.
header << _("Bundle");
else
header << _("Type");
*_table << row;
return true;
}
+
+ bool operator()(const zypp::ui::Selectable::constPtr & s) const
+ {
+ // show installed objects
+ for_(it, s->installedBegin(), s->installedEnd())
+ {
+ TableRow row;
+ zypp::PoolItem pi = *it;
+ row << "i";
+ row << pi->repository().info().name()
+ // TODO what about rug's Bundle?
+ << (_gopts.is_rug_compatible ? "" : kind_to_string_localized(pi->kind(), 1))
+ << pi->name()
+ << pi->edition().asString()
+ << pi->arch().asString();
+ *_table << row;
+ }
+
+ // get the first installed object
+ zypp::PoolItem installed;
+ if (!s->installedEmpty())
+ installed = s->installedObj();
+
+ // show available objects
+ for_(it, s->availableBegin(), s->availableEnd())
+ {
+ TableRow row;
+
+ zypp::PoolItem pi = *it;
+ if (installed)
+ {
+ row << (equalNVRA(*installed.resolvable(), *pi.resolvable()) ? "i" : "v");
+ }
+ else
+ row << "";
+ row << pi->repository().info().name();
+ row << (_gopts.is_rug_compatible ? "" : kind_to_string_localized(pi->kind(), 1))
+ << pi->name()
+ << pi->edition().asString()
+ << pi->arch().asString();
+
+ *_table << row;
+ }
+ return true;
+ }
+};
+
+struct FillSearchTableSelectable
+{
+ // the table used for output
+ Table * _table;
+ const GlobalOptions & _gopts;
+
+ FillSearchTableSelectable( Table & table )
+ : _table( &table )
+ , _gopts(Zypper::instance()->globalOpts())
+ {
+ TableHeader header;
+ // translators: S for installed Status
+ header << _("S");
+ header << _("Name");
+ header << _("Summary");
+ header << _("Type");
+ header << _("Repository");
+ *_table << header;
+ }
+
+ bool operator()(const zypp::ui::Selectable::constPtr & s) const
+ {
+ TableRow row;
+
+ row << (s->installedEmpty() ? "" : "i");
+ //! \todo improve the abbreviation
+ row << (_gopts.no_abbrev || s->theObj()->summary().size() < 33 ?
+ s->theObj()->summary() : s->theObj()->summary().substr(0,28) + "...");
+ row << kind_to_string_localized(s->kind(), 1);
+ row << selectable_search_repo_str(*s);
+ *_table << row;
+ return true;
+ }
};
-/** List patches */
+/** List all patches with specific info in specified repos */
void list_patches(Zypper & zypper);
-/** List paterns */
+/** List all patterns with specific info in specified repos */
void list_patterns(Zypper & zypper);
+/** List all packages with specific info in specified repos
+ * - currently looks like zypper search -t package -r foorepo */
+void list_packages(Zypper & zypper);
+
#endif /*ZYPPERSEARCH_H_*/
#include <boost/format.hpp>
#include "zypp/ZYppFactory.h"
-#include "zypp/base/Logger.h"
+#include "zypp/zypp_detail/ZYppReadOnlyHack.h"
+#include "zypp/base/Logger.h"
+#include "zypp/base/Algorithm.h"
#include "zypp/base/UserRequestException.h"
-#include "zypp/repo/RepoException.h"
-#include "zypp/zypp_detail/ZYppReadOnlyHack.h"
+
#include "zypp/sat/SolvAttr.h"
#include "zypp/PoolQuery.h"
break;
}
+ case ZypperCommand::PACKAGES_e:
+ {
+ static struct option options[] = {
+ {"repo", required_argument, 0, 'r'},
+ // rug compatibility option, we have --repo
+ {"catalog", required_argument, 0, 'c'},
+ {"installed-only", no_argument, 0, 'i'},
+ {"uninstalled-only", no_argument, 0, 'u'},
+ {"sort-by-name", no_argument, 0, 'N'},
+ {"sort-by-repo", no_argument, 0, 'R'},
+ {"sort-by-catalog", no_argument, 0, 0},
+ {"help", no_argument, 0, 'h'},
+ {0, 0, 0, 0}
+ };
+ specific_options = options;
+ _command_help = _(
+ "packages (pa) [options] [repository] ...\n"
+ "\n"
+ "List all packages available in specified repositories.\n"
+ "\n"
+ " Command options:\n"
+ "\n"
+ "-r, --repo <alias|#|URI> Just another means to specify repository.\n"
+ "-i, --installed-only Show only installed patterns.\n"
+ "-u, --uninstalled-only Show only patterns wich are not installed.\n"
+ "-N, --sort-by-name Sort the list by package name.\n"
+ "-R, --sort-by-repo Sort the list by repository.\n"
+ );
+ break;
+ }
+
case ZypperCommand::PATTERNS_e:
{
static struct option options[] = {
try
{
- FillTable callback( t );
- query.execute(callback);
- //unsigned int count = invokeOnEach(query.begin(), query.end(), callback);
- //cout << "query: " << endl << query;
+ FillSearchTableSolvable callback(t);
+ invokeOnEach(query.selectableBegin(), query.selectableEnd(), callback);
if (t.empty())
out().info(_("No resolvables found."), Out::QUIET);
t.sort(3); // sort by name
cout << t; //! \todo out().table()?
-
-// cout << "invocations:" << count << endl;
}
}
catch (const Exception & e)
// --------------------------( patches )------------------------------------
else if (command() == ZypperCommand::PATCHES ||
- command() == ZypperCommand::PATTERNS)
+ command() == ZypperCommand::PATTERNS ||
+ command() == ZypperCommand::PACKAGES)
{
if (runningHelp()) { out().info(_command_help, Out::QUIET); return; }
case ZypperCommand::PATTERNS_e:
list_patterns(*this);
break;
+ case ZypperCommand::PACKAGES_e:
+ list_packages(*this);
+ break;
default:;
}
no_gpg_checks(false),
machine_readable(false),
no_refresh(false),
- root_dir("/")
+ root_dir("/"),
+ no_abbrev(false),
+ terse(false)
{}
// std::list<zypp::Url> additional_sources;
bool no_refresh;
std::string root_dir;
zypp::RepoManagerOptions rm_options;
+ bool no_abbrev;
+ bool terse;
};