Author: jkupec
Date: Sat Aug 4 19:03:22 2007
New Revision: 6473
URL: http://svn.opensuse.org/viewcvs/zypp?rev=6473&view=rev
Log:
- zypper refresh now takes aliases or repo numbers that should be
refreshed as arguments.
- zypper repos output fixed to show proper repo numbers (#296779)
Modified:
trunk/zypper/doc/zypper.8
trunk/zypper/src/zypper-sources.cc
trunk/zypper/src/zypper-sources.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=6473&r1=6472&r2=6473&view=diff
==============================================================================
--- trunk/zypper/doc/zypper.8 (original)
+++ trunk/zypper/doc/zypper.8 Sat Aug 4 19:03:22 2007
@@ -270,10 +270,10 @@
Disable auto-refresh for the repository.
.TP
-.B refresh (ref)
-Refresh all installation sources found in system.
+.B refresh (ref) [alias|#] ...
+Refresh repositories specified by their alias or number. If no repositories are specified, all enabled repositories will be refreshed.
.IP
-This means downloading resolvables' metadata from source media (if needed), storing it in local cache (typically under /var/lib/zypp/cache/raw directory) and preparsing the metadata into an sqlite database (/var/lib/zypp/cache/zypp.db).
+Refreshing a repository means downloading metadata of resolvables from media (if needed), storing it in local cache (typically under /var/cache/zypp/raw/<alias> directory) and preparsing the metadata into an sqlite database (/var/cache/zypp/zypp.db).
.SH "GLOBAL OPTIONS"
.TP
Modified: trunk/zypper/src/zypper-sources.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-sources.cc?rev=6473&r1=6472&r2=6473&view=diff
==============================================================================
--- trunk/zypper/src/zypper-sources.cc (original)
+++ trunk/zypper/src/zypper-sources.cc Sat Aug 4 19:03:22 2007
@@ -3,6 +3,7 @@
#include "zypper-sources.h"
#include "zypper-tabulator.h"
+#include <iostream>
#include <fstream>
#include
#include
@@ -151,7 +152,7 @@
tbl << th;
int i = 1;
-
+
for (std::list<RepoInfo>::const_iterator it = repos.begin();
it != repos.end(); ++it)
{
@@ -183,6 +184,7 @@
}
tbl << tr;
+ i++;
}
if (tbl.empty())
@@ -217,34 +219,104 @@
// ----------------------------------------------------------------------------
-void refresh_repos()
+template
+void safe_lexical_cast (Source s, Target &tr) {
+ try {
+ tr = boost::lexical_cast<Target> (s);
+ }
+ catch (boost::bad_lexical_cast &) {
+ }
+}
+
+// ----------------------------------------------------------------------------
+
+int refresh_repos(vector<string> & arguments)
{
RepoManager manager;
- gData.repos = manager.knownRepositories();
+ list<RepoInfo> repos;
+ try
+ {
+ repos = manager.knownRepositories();
+ }
+ catch ( const Exception &e )
+ {
+ ZYPP_CAUGHT(e);
+ cerr << _("Error reading repositories:") << endl
+ << e.asUserString() << endl;
+ return ZYPPER_EXIT_ERR_ZYPP;
+ }
- int error_count = 0;
- int enabled_repo_count = gData.repos.size();
- for (std::list<RepoInfo>::iterator it = gData.repos.begin();
- it != gData.repos.end(); ++it)
+ unsigned error_count = 0;
+ unsigned enabled_repo_count = repos.size();
+ unsigned repo_number = 0;
+ unsigned argc = arguments.size();
+ for (std::list<RepoInfo>::iterator it = repos.begin();
+ it != repos.end(); ++it)
{
RepoInfo repo(*it);
+ repo_number++;
+
+ if (argc)
+ {
+ bool specified_found = false;
+
+ // search for the repo alias among arguments
+ for (vector<string>::iterator it = arguments.begin();
+ it != arguments.end(); ++it)
+ if ((*it) == repo.alias())
+ {
+ specified_found = true;
+ arguments.erase(it);
+ break;
+ }
+
+ // search for the repo number among arguments
+ if (!specified_found)
+ for (vector<string>::iterator it = arguments.begin();
+ it != arguments.end(); ++it)
+ {
+ unsigned tmp = 0;
+ safe_lexical_cast (*it, tmp);
+ if (tmp == repo_number)
+ {
+ specified_found = true;
+ arguments.erase(it);
+ break;
+ }
+ }
+
+ if (!specified_found)
+ {
+ DBG << repo.alias() << "(#" << repo_number << ") not specified,"
+ << " skipping." << endl;
+ enabled_repo_count--;
+ continue;
+ }
+ }
// skip disabled repos
if (!repo.enabled())
{
- cout_v << format(_("Skipping disabled repository '%s'")) % repo.alias()
- << endl;
+ string msg = boost::str(
+ format(_("Skipping disabled repository '%s'")) % repo.alias());
+
+ if (argc)
+ cerr << msg << endl;
+ else
+ cout_v << msg << endl;
+
enabled_repo_count--;
continue;
}
+ // do the refresh
try
{
- cout_n << _("Refreshing ") << it->alias() << endl;
- manager.refreshMetadata(repo); //! \todo progress reporting
+ cout_n << format(_("Refreshing '%s'")) % it->alias() << endl;
+ manager.refreshMetadata(repo, RepoManager::RefreshIfNeeded);
cout_v << _("Creating repository cache...") << endl;
- manager.buildCache(repo);
+ manager.buildCache(repo, RepoManager::BuildIfNeeded);
//cout_n << _("DONE") << endl << endl;
}
@@ -261,14 +333,42 @@
% repo.alias() << endl;
error_count++;
}
+
}
- if (error_count == enabled_repo_count)
+ // the rest of arguments are those not found, complain to the user
+ bool show_hint = arguments.size();
+ for (vector<string>::iterator it = arguments.begin();
+ it != arguments.end();)
+ {
+ cerr << format(_("Repository '%s' not found by its alias or number.")) % *it
+ << endl;
+ it = arguments.erase(it);
+ }
+ if (show_hint)
+ cout_n << _("Use 'zypper repos' to get the list of defined repositories.")
+ << endl;
+
+ // print the result message
+ if (enabled_repo_count == 0)
+ {
+ if (argc)
+ cerr << _("Specified repositories are not enabled or defined.");
+ else
+ cerr << _("There are no enabled repositories defined.");
+
+ cout_n << endl
+ << _("Use 'zypper addrepo' or 'zypper modifyrepo' commands to add or enable repositories.")
+ << endl;
+ }
+ else if (error_count == enabled_repo_count)
cerr << _("Could not refresh the repositories because of errors.") << endl;
else if (error_count)
cerr << _("Some of the repositories have not been refreshed because of error.") << endl;
+ else if (argc)
+ cout << _("Specified repositories have been refreshed.") << endl;
else
- cout_n << _("All repositories have been refreshed.") << endl;
+ cout << _("All repositories have been refreshed.") << endl;
}
// ----------------------------------------------------------------------------
@@ -412,17 +512,6 @@
// ----------------------------------------------------------------------------
-template
-void safe_lexical_cast (Source s, Target &tr) {
- try {
- tr = boost::lexical_cast<Target> (s);
- }
- catch (boost::bad_lexical_cast &) {
- }
-}
-
-// ----------------------------------------------------------------------------
-
static
bool looks_like_url (const string& s) {
static bool schemes_shown = false;
Modified: trunk/zypper/src/zypper-sources.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-sources.h?rev=6473&r1=6472&r2=6473&view=diff
==============================================================================
--- trunk/zypper/src/zypper-sources.h (original)
+++ trunk/zypper/src/zypper-sources.h Sat Aug 4 19:03:22 2007
@@ -22,7 +22,7 @@
/**
* Refresh all enabled repositories.
*/
-void refresh_repos();
+int refresh_repos(std::vectorstd::string & arguments);
/**
Modified: trunk/zypper/src/zypper.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper.cc?rev=6473&r1=6472&r2=6473&view=diff
==============================================================================
--- trunk/zypper/src/zypper.cc (original)
+++ trunk/zypper/src/zypper.cc Sat Aug 4 19:03:22 2007
@@ -421,9 +421,10 @@
};
specific_options = refresh_options;
specific_help = _(
- "refresh\n"
+ "refresh (ref) [alias|#] ...\n"
"\n"
- "Refresh all defined and enabled repositories.\n"
+ "Refresh repositories specified by their alias or number."
+ " If none are specified, all enabled repositories will be refreshed.\n"
"\n"
"This command has no additional options.\n"
);
@@ -964,7 +965,7 @@
return ZYPPER_EXIT_ERR_PRIVILEGES;
}
- refresh_repos();
+ refresh_repos(arguments);
}
// --------------------------( remove/install )-----------------------------
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org