From c99d8ff360d7d3ca30ac293d48827fe29db11d92 Mon Sep 17 00:00:00 2001 From: =?utf8?q?J=C3=A1n=20Kupec?= Date: Tue, 30 Mar 2010 12:27:21 +0200 Subject: [PATCH] repos.h: repo_specs_to_aliases added --- src/repos.cc | 25 +++++++++++++++++++++++++ src/repos.h | 21 +++++++++++++++++++++ 2 files changed, 46 insertions(+) diff --git a/src/repos.cc b/src/repos.cc index 23f6e75..aa78a90 100644 --- a/src/repos.cc +++ b/src/repos.cc @@ -477,6 +477,31 @@ void report_unknown_repos(Out & out, list not_found) "zypper repos")); } +// ---------------------------------------------------------------------------- + +unsigned repo_specs_to_aliases(Zypper & zypper, + const list & rspecs, list & aliases, bool enabled_only) +{ + list not_found; + list repos; + get_repos(zypper, rspecs.begin(), rspecs.end(), repos, not_found); + if (!not_found.empty()) + { + report_unknown_repos(zypper.out(), not_found); + zypper.setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS); + ZYPP_THROW(ExitRequestException("Unknown repo specified.")); + } + for_(it, repos.begin(), repos.end()) + { + if (!enabled_only || it->enabled()) + aliases.push_back(it->alias()); + else + zypper.out().warning(str::form(_("Ignoring disabled repository '%s'"), + zypper.config().show_alias ? it->alias().c_str() : it->name().c_str())); + } + return aliases.size(); +} + // --------------------------------------------------------------------------- /** diff --git a/src/repos.h b/src/repos.h index 87afd21..037e3ee 100644 --- a/src/repos.h +++ b/src/repos.h @@ -36,6 +36,27 @@ void get_repos(Zypper & zypper, void report_unknown_repos(Out & out, std::list not_found); /** + * Looks for known repos based on specified arguments and creates a list + * of aliases of found repos. Reports repos not found via zypper's output. + * + * By default, only enabled repos are returned. This can be changed via the + * \a enabled_only argument. + * + * \param zypper The Zypper instance. + * \param repos List of repository specifiers as strings (alias/name/#/URL) + * \param aliases List of strings which should be fed by found aliases. + * \param enabled_only Whether to return only enabled repos. Default is true. + * \returns Number of repos found. + * + * \throws ExitRequestException if one of the repos could not be found. + */ +unsigned repo_specs_to_aliases( + Zypper & zypper, + const std::list & repos, + std::list & aliases, + bool enabled_only = true); + +/** * Reads known enabled repositories and stores them in gData. * This command also refreshes repos with auto-refresh enabled. * -- 2.7.4