Author: jreidinger
Date: Fri Mar 7 12:53:46 2008
New Revision: 9044
URL: http://svn.opensuse.org/viewcvs/zypp?rev=9044&view=rev
Log:
Allow write repo as number or URL -repo and for repo-manipulating commands (bnc #298312). Allow multiple repos in removerepo command.
Modified:
trunk/zypper/doc/zypper.8
trunk/zypper/src/zypper-repos.cc
trunk/zypper/src/zypper-repos.h
trunk/zypper/src/zypper.cc
Modified: trunk/zypper/doc/zypper.8
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/doc/zypper.8?rev=9044&r1=9043&r2=9044&view=diff
==============================================================================
--- trunk/zypper/doc/zypper.8 (original)
+++ trunk/zypper/doc/zypper.8 Fri Mar 7 12:53:46 2008
@@ -46,8 +46,8 @@
Displays full info for the specified packages or other resolvables.
.TP
-.I \-r, \-\-repo <alias>
-Work only with the repository specified by the alias.
+.I \-r, \-\-repo
+Work only with the repository specified by the alias, number or URL.
.TP
.I \-t, \-\-type <type>
Type of resolvable (default: package). Currently supported resolvable types for
@@ -85,8 +85,8 @@
respective resolvables for installation.
.TP
-\fI\-r, \-\-repo\fR <alias>
-Install resolvables only from the repository specified by the alias.
+\fI\-r, \-\-repo\fR
+Install resolvables only from the repository specified by the alias, number or URL.
.TP
\fI\-t, \-\-type\fR
Type of resolvable (default: package)
@@ -137,8 +137,8 @@
\fI\-t, --type\fR
Type of resolvable (default: patch)
.TP
-\fI\-r, \-\-repo\fR <alias>
-List only updates from the repository specified by the alias.
+\fI\-r, \-\-repo\fR
+List only updates from the repository specified by the alias, number or URL.
See also the NOTE at
.BR update .
@@ -153,8 +153,8 @@
For details see the install command
.TP
-\fI\-r, \-\-repo\fR <alias>
-Operate only with resolvables from repository specified by alias.
+\fI\-r, \-\-repo\fR
+Operate only with resolvables from repository specified by alias, number or URL.
.TP
\fI\-t, -\-type\fR
Type of resolvable (default: package)
@@ -186,8 +186,8 @@
\fI\-t, -\-type\fR
Type of resolvable (default: patch)
.TP
-\fI\-r, \-\-repo\fR <alias>
-Limit updates to repository specified by alias.
+\fI\-r, \-\-repo\fR
+Limit updates to repository specified by alias, number or URL.
.TP
.I \-\-skip\-interactive
This will skip interactive patches, that is, those that need reboot,
@@ -221,8 +221,8 @@
and product updates, etc.
.TP
-\fI\-r, \-\-repo\fR <alias>
-Limit updates to repository specified by alias.
+\fI\-r, \-\-repo\fR
+Limit updates to repository specified by alias, number or URL.
.TP
.I \-l, \-\-auto\-agree\-with\-licenses
Automatically say 'yes' to third party license confirmation prompt. By using this option, you choose to agree with licenses of all third-party software this command will install. This option is particularly useful for administators installing the same set of packages on multiple machines (by an automated process) and have the licenses confirmed before.
@@ -276,8 +276,8 @@
Search only for resolvables of specified type. See the beginning of the subsection for the list of available resolvable types.
Multiple \-t option are allowed.
.TP
-.I \-r, \-\-repo <alias>
-Search only in the repository specified by the alias.
+.I \-r, \-\-repo
+Search only in the repository specified by the alias, number or URL.
Multiple \-r options are allowed.
.TP
\fI \-\-sort\-by\-name\fR
@@ -296,16 +296,16 @@
See also the EXIT CODES section for details on exit status of 0, 100, and 101
returned by this command.
.TP
-.I \-r, \-\-repo <alias>
-Check for patches only in the repository specified by the alias.
+.I \-r, \-\-repo
+Check for patches only in the repository specified by the alias, number or URL.
.TP
.B patches (pch)
List patches. Lists all patches that are available, including
installed and not applicable ones.
.TP
-.I \-r, \-\-repo <alias>
-Check for patches only in the repository specified by the alias.
+.I \-r, \-\-repo
+Check for patches only in the repository specified by the alias, number or URL.
.SS Repository Management
@@ -337,8 +337,8 @@
NOTE: This command does not automatically refresh the newly added repositories. You have to use the \fBrefresh\fR command after finishing your modifications to repositories with \fB*repo\fR commands.
.TP
-.B removerepo (rr) [options]
-Delete repository specified by alias or URI.
+.B removerepo (rr) [options]
+Delete repository specified by alias, number or URI.
.TP
\fI --loose-auth\fR
Ignore user authentication data in the URI
@@ -362,12 +362,12 @@
the repositories will be written to the standard output.
.TP
-.B renamerepo (nr) <alias> <new-alias>
-Assign new alias to the repository specified by alias.
+.B renamerepo (nr) <new-alias>
+Assign new alias to the repository specified by alias, number or URL.
.TP
-.B modifyrepo (mr) <options> <alias>
-Modify properties of the repository specified by alias.
+.B modifyrepo (mr) <options>
+Modify properties of the repository specified by alias, number or URL.
.TP
\fI\-e, \-\-enable\fR
Enable the repository.
Modified: trunk/zypper/src/zypper-repos.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-repos.cc?rev=9044&r1=9043&r2=9044&view=diff
==============================================================================
--- trunk/zypper/src/zypper-repos.cc (original)
+++ trunk/zypper/src/zypper-repos.cc Fri Mar 7 12:53:46 2008
@@ -216,6 +216,37 @@
return false; // no error
}
+bool match_repo(Zypper & zypper, string str, RepoInfo *repo){
+ RepoManager manager(zypper.globalOpts().rm_options);
+ list<RepoInfo> known = manager.knownRepositories();
+ bool founded = false;
+
+ unsigned int number = 1; // repo number
+ for (list<RepoInfo>::const_iterator known_it = known.begin();
+ known_it != known.end(); ++known_it, number++)
+ {
+ unsigned int tmp = 0;
+ safe_lexical_cast (str, tmp); // try to make an int out of the string
+
+ try
+ {
+ if (known_it->alias() == str ||
+ tmp == number ||
+ find(known_it->baseUrlsBegin(),known_it->baseUrlsEnd(),Url(str))
+ != known_it->baseUrlsEnd())
+ {
+ *repo = *known_it;
+ founded = true;
+ break;
+ }
+ }
+ catch(const url::UrlException &){}
+
+ } // END for all known repos
+
+ return founded;
+}
+
// ---------------------------------------------------------------------------
/**
@@ -229,37 +260,12 @@
const T & begin, const T & end,
list<RepoInfo> & repos, list<string> & not_found)
{
- RepoManager manager(zypper.globalOpts().rm_options);
- list<RepoInfo> known = manager.knownRepositories();
for (T it = begin; it != end; ++it)
{
RepoInfo repo;
- // can i find it by alias, #, or the url, in that order?
- unsigned int number = 1; // repo number
- for (list<RepoInfo>::const_iterator known_it = known.begin();
- known_it != known.end(); ++known_it, number++)
- {
- unsigned int tmp = 0;
- safe_lexical_cast (*it, tmp); // try to make an int out of the string
-
- try
- {
- if (known_it->alias() == *it ||
- tmp == number ||
- find(known_it->baseUrlsBegin(),known_it->baseUrlsEnd(),Url(*it))
- != known_it->baseUrlsEnd())
- {
- repo = *known_it;
- break;
- }
- }
- catch(const url::UrlException &){}
- } // END for all known repos
-
- // no match found
- if (repo.alias().empty())
+ if (!match_repo(zypper,*it,&repo))
{
not_found.push_back(*it);
continue;
@@ -291,8 +297,10 @@
catch(const url::UrlException &){}
}
- if (equals)
+ if (equals){
duplicate = true;
+ break;
+ }
} // END for all found so far
if (!duplicate)
@@ -1329,9 +1337,7 @@
}
catch (const RepoNotFoundException & ex)
{
- zypper.out().error(boost::str(format(
- _("Repository '%s' not found.")) % alias));
- ERR << "Repo " << alias << " not found" << endl;
+ MIL << "This should not happen. Already finded repo is not found" << endl;
}
catch (const RepoAlreadyExistsException & ex)
{
Modified: trunk/zypper/src/zypper-repos.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-repos.h?rev=9044&r1=9043&r2=9044&view=diff
==============================================================================
--- trunk/zypper/src/zypper-repos.h (original)
+++ trunk/zypper/src/zypper-repos.h Fri Mar 7 12:53:46 2008
@@ -4,6 +4,7 @@
#include
#include "zypp/Url.h"
+#include "zypp/RepoInfo.h"
#include "zypper.h"
@@ -38,6 +39,15 @@
*/
void clean_repos(Zypper & zypper);
+/**
+ * Try match given string with any known repository.
+ *
+ * \param str string to match
+ * \param repo pointer to fill with founded repository
+ * \return success if respository is founded
+ */
+bool match_repo(Zypper & zypper, const std::string str, zypp::RepoInfo *repo);
+
/**
* Add repository specified by \url to system repositories.
Modified: trunk/zypper/src/zypper.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper.cc?rev=9044&r1=9043&r2=9044&view=diff
==============================================================================
--- trunk/zypper/src/zypper.cc (original)
+++ trunk/zypper/src/zypper.cc Fri Mar 7 12:53:46 2008
@@ -896,7 +896,7 @@
};
specific_options = service_delete_options;
_command_help = _(
- "removerepo (rr) [options] \n"
+ "removerepo (rr) [options] \n"
"\n"
"Remove repository specified by alias or URL.\n"
"\n"
@@ -915,9 +915,9 @@
};
specific_options = service_rename_options;
_command_help = _(
- "renamerepo [options] <alias> <new-alias>\n"
+ "renamerepo [options] <new-alias>\n"
"\n"
- "Assign new alias to the repository specified by alias.\n"
+ "Assign new alias to the repository specified by alias,number or URL.\n"
"\n"
"This command has no additional options.\n"
);
@@ -938,9 +938,9 @@
};
specific_options = service_modify_options;
_command_help = _(
- "modifyrepo (mr) <options> <alias>\n"
+ "modifyrepo (mr) <options> \n"
"\n"
- "Modify properties of the repository specified by alias.\n"
+ "Modify properties of the repository specified by alias, number or URL.\n"
"\n"
" Command options:\n"
"-d, --disable Disable the repository (but don't remove it)\n"
@@ -967,7 +967,7 @@
_command_help = _(
"refresh (ref) [alias|#] ...\n"
"\n"
- "Refresh repositories specified by their alias or number."
+ "Refresh repositories specified by their alias, number or URL."
" If none are specified, all enabled repositories will be refreshed.\n"
"\n"
" Command options:\n"
@@ -1148,7 +1148,7 @@
"-i, --installed-only Show only packages that are already installed.\n"
"-u, --uninstalled-only Show only packages that are not currently installed.\n"
"-t, --type <type> Search only for packages of the specified type.\n"
- "-r, --repo <alias> Search only in the repository specified by the alias.\n"
+ "-r, --repo Search only in the repository specified by the alias.\n"
" --sort-by-name Sort packages by name (default).\n"
" --sort-by-repo Sort packages by repository.\n"
"\n"
@@ -1564,55 +1564,37 @@
// too many arguments
//! \todo allow to specify multiple repos to delete
- else if (_arguments.size() > 1)
+/* else if (_arguments.size() > 1)
{
report_too_many_arguments(_command_help);
setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
return;
- }
+ } */
warn_if_zmd ();
- bool found = remove_repo(*this, _arguments[0]);
- if (found)
- return;
-
- MIL << "Repository not found by alias, trying delete by URL" << endl;
- out().info(_("Repository not found by alias, trying delete by URL..."), Out::HIGH);
-
- Url url;
- try { url = Url (_arguments[0]); }
- catch ( const Exception & excpt_r )
- {
- ZYPP_CAUGHT( excpt_r );
- ostringstream s;
- s << _("Given URL is invalid.") << " " << excpt_r.asUserString();
- out().warning(s.str(), Out::HIGH);
- }
-
- if (url.isValid())
- {
- url::ViewOption urlview = url::ViewOption::DEFAULTS + url::ViewOption::WITH_PASSWORD;
-
- if (copts.count("loose-auth"))
- {
- urlview = urlview
- - url::ViewOptions::WITH_PASSWORD
- - url::ViewOptions::WITH_USERNAME;
+ //must store repository before remove to ensure correct match number
+ list<RepoInfo> repo_to_remove;
+ for (vector<string>::const_iterator it = _arguments.begin();
+ it!= _arguments.end();++it){
+ RepoInfo repo;
+ if (match_repo(*this,*it,&repo)){
+ repo_to_remove.push_back(repo);
+ } else {
+ MIL << "Repository not found by given alias, number or URL." << endl;
+ out().error(boost::str(format(
+ //TranslatorExplanation %s is string which not founded (can be url,
+ //allias or number of repo)
+ _("Repository %s not found by alias, number or URL."))
+ % *it));
}
-
- if (copts.count("loose-query"))
- urlview = urlview - url::ViewOptions::WITH_QUERY_STR;
-
- found = remove_repo(*this, url, urlview);
}
- else
- found = false;
- if (!found)
- {
- MIL << "Repository not found by given alias or URL." << endl;
- out().error(_("Repository not found by given alias or URL."));
+ for (std::list<RepoInfo>::const_iterator it = repo_to_remove.begin();
+ it!=repo_to_remove.end();++it){
+ if (!remove_repo(*this,*it))
+ MIL << "Repository is founded but cannot remove with root privilegies."
+ << "Should not happen." << endl ;
}
return;
@@ -1652,8 +1634,14 @@
// init_target(*this);
warn_if_zmd ();
try {
- // also stores it
- rename_repo(*this, _arguments[0], _arguments[1]);
+ RepoInfo repo;
+ if (match_repo(*this,_arguments[0], &repo)){
+ rename_repo(*this, repo.alias(), _arguments[1]);
+ } else {
+ this->out().error(boost::str(format(
+ _("Repository '%s' not found.")) % _arguments[0]));
+ ERR << "Repo " << _arguments[0] << " not found" << endl;
+ }
}
catch ( const Exception & excpt_r )
{
@@ -1695,8 +1683,15 @@
setExitCode(ZYPPER_EXIT_ERR_INVALID_ARGS);
return;
}
-
- modify_repo(*this, _arguments[0]);
+
+ RepoInfo repo;
+ if (match_repo(*this,_arguments[0],&repo)){
+ modify_repo(*this, repo.alias());
+ } else {
+ this->out().error(
+ boost::str(format(_("Repository %s not found.")) % _arguments[0]));
+ ERR << "Repo " << _arguments[0] << " not found" << endl;
+ }
}
// --------------------------( refresh )------------------------------------
@@ -2021,19 +2016,16 @@
query.addKind( ResTraits<Package>::kind );
}
- if (copts.count("repo") > 0)
- {
- //options.clearRepos();
- std::liststd::string::const_iterator it;
- for (it = copts["repo"].begin(); it != copts["repo"].end(); ++it) {
- query.addRepo( *it );
- }
- }
-
init_repos(*this);
if (exitCode() != ZYPPER_EXIT_OK)
return;
+ //add available repos to query
+ std::listzypp::RepoInfo::const_iterator repo_it;
+ for (repo_it = gData.repos.begin();repo_it != gData.repos.end();++repo_it){
+ query.addRepo( repo_it->alias());
+ }
+
init_target(*this);
// now load resolvables:
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org