Author: jkupec
Date: Fri Jun 22 18:21:00 2007
New Revision: 5838
URL: http://svn.opensuse.org/viewcvs/zypp?rev=5838&view=rev
Log:
RENAME_REPO command reimplemented
Modified:
trunk/zypper/src/zypper-command.cc
trunk/zypper/src/zypper-command.h
trunk/zypper/src/zypper-sources.cc
trunk/zypper/src/zypper-sources.h
trunk/zypper/src/zypper.cc
Modified: trunk/zypper/src/zypper-command.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-command.cc?rev=5838&r1=5837&r2=5838&view=diff
==============================================================================
--- trunk/zypper/src/zypper-command.cc (original)
+++ trunk/zypper/src/zypper-command.cc Fri Jun 22 18:21:00 2007
@@ -18,6 +18,7 @@
const ZypperCommand ZypperCommand::ADD_REPO(ZypperCommand::ADD_REPO_e);
const ZypperCommand ZypperCommand::REMOVE_REPO(ZypperCommand::REMOVE_REPO_e);
+const ZypperCommand ZypperCommand::RENAME_REPO(ZypperCommand::RENAME_REPO_e);
const ZypperCommand ZypperCommand::LIST_REPOS(ZypperCommand::LIST_REPOS_e);
const ZypperCommand ZypperCommand::REFRESH(ZypperCommand::REFRESH_e);
@@ -52,7 +53,8 @@
// initialize it
_table["addrepo"] = _table["service-add"] = _table["sa"] = ZypperCommand::ADD_REPO_e;
_table["rmrepo"] = _table["service-delete"] = _table["sd"] = ZypperCommand::REMOVE_REPO_e;
- _table["listrepos"] = _table["service-list"] = _table["sl"] = ZypperCommand::LIST_REPOS_e;
+ _table["renamerepo"]= _table["rr"] = _table["service-rename"] = _table["sr"] = ZypperCommand::RENAME_REPO_e;
+ _table["listrepos"] = _table["lr"] = _table["service-list"] = _table["sl"] = ZypperCommand::LIST_REPOS_e;
_table["refresh"] = _table["ref"] = ZypperCommand::REFRESH_e;
_table["install"] = _table["in"] = ZypperCommand::INSTALL_e;
Modified: trunk/zypper/src/zypper-command.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-command.h?rev=5838&r1=5837&r2=5838&view=diff
==============================================================================
--- trunk/zypper/src/zypper-command.h (original)
+++ trunk/zypper/src/zypper-command.h Fri Jun 22 18:21:00 2007
@@ -12,6 +12,7 @@
{
static const ZypperCommand ADD_REPO;
static const ZypperCommand REMOVE_REPO;
+ static const ZypperCommand RENAME_REPO;
static const ZypperCommand LIST_REPOS;
static const ZypperCommand REFRESH;
@@ -42,6 +43,7 @@
{
ADD_REPO_e,
REMOVE_REPO_e,
+ RENAME_REPO_e,
LIST_REPOS_e,
REFRESH_e,
Modified: trunk/zypper/src/zypper-sources.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-sources.cc?rev=5838&r1=5837&r2=5838&view=diff
==============================================================================
--- trunk/zypper/src/zypper-sources.cc (original)
+++ trunk/zypper/src/zypper-sources.cc Fri Jun 22 18:21:00 2007
@@ -341,6 +341,8 @@
return s;
}
+// ----------------------------------------------------------------------------
+
template
void safe_lexical_cast (Source s, Target &tr) {
try {
@@ -350,6 +352,8 @@
}
}
+// ----------------------------------------------------------------------------
+
static
bool looks_like_url (const string& s) {
static bool schemes_shown = false;
@@ -368,6 +372,8 @@
return false;
}
+// ----------------------------------------------------------------------------
+
void remove_repo( const std::string &alias )
{
RepoManager manager;
@@ -376,81 +382,29 @@
manager.removeRepository(info);
}
-//! remove a source, identified in any way: alias, url, id
-// may throw:
-/*
-void remove_source( const std::string& anystring )
+// ----------------------------------------------------------------------------
+
+void rename_repo(const std::string & alias, const std::string & newalias)
{
- cerr_vv << "Constructing SourceManager" << endl;
- SourceManager_Ptr manager = SourceManager::sourceManager();
- cerr_vv << "Restoring SourceManager" << endl;
- try {
- manager->restore (gSettings.root_dir, true /*use_cache*//*);
- }
- catch (const Exception & ex) {
- // so what if sources cannot be restored
- // we want to delete anyway
- ZYPP_CAUGHT (ex);
- cerr << ex.asUserString () << endl
- << _("Continuing anyway") << endl;
- }
+ RepoManager manager;
+
+ RepoInfo repo(manager.getRepositoryInfo(alias));
+ repo.setAlias(newalias);
+
+ try
+ {
+ manager.modifyRepository(alias, repo);
- SourceManager::SourceId sid = 0;
- safe_lexical_cast (anystring, sid);
- if (sid > 0) {
- cerr_v << _("removing source ") << sid << endl;
- try {
- manager->findSource (sid);
- }
- catch (const Exception & ex) {
- ZYPP_CAUGHT (ex);
- // boost::format: %s is fine regardless of the actual type :-)
- cerr << format (_("Source %s not found.")) % sid << endl;
- }
- manager->removeSource (sid);
+ cout << format(_("Repository %s renamed to %s")) % alias % repo.alias() << endl;
}
- else {
- bool is_url = false;
- if (looks_like_url (anystring)) {
- is_url = true;
- cerr_vv << "Looks like a URL" << endl;
-
- Url url;
- try {
- url = Url (anystring);
- }
- catch ( const Exception & excpt_r ) {
- ZYPP_CAUGHT( excpt_r );
- cerr << _("URL is invalid: ") << excpt_r.asUserString() << endl;
- }
- if (url.isValid ()) {
- try {
- manager->findSourceByUrl (url);
- }
- catch (const Exception & ex) {
- ZYPP_CAUGHT (ex);
- cerr << format (_("Source %s not found.")) % url.asString() << endl;
- }
- manager->removeSourceByUrl (url);
- }
- }
-
- if (!is_url) {
- try {
- manager->findSource (anystring);
- }
- catch (const Exception & ex) {
- ZYPP_CAUGHT (ex);
- cerr << format (_("Source %s not found.")) % anystring << endl;
- }
- manager->removeSource (anystring); // by alias
- }
+ catch (const Exception & ex)
+ {
+ cerr << _("Error while modifying the repository:") << endl;
+ cerr << ex.asUserString();
+ cerr << format(_("Leaving repository %s unchanged.")) % alias << endl;
}
-
- cerr_vv << "Storing source data" << endl;
- manager->store( gSettings.root_dir, true /*metadata_cache*//* );
}
-*/
+
/*
//! rename a source, identified in any way: alias, url, id
void rename_source( const std::string& anystring, const std::string& newalias )
Modified: trunk/zypper/src/zypper-sources.h
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper-sources.h?rev=5838&r1=5837&r2=5838&view=diff
==============================================================================
--- trunk/zypper/src/zypper-sources.h (original)
+++ trunk/zypper/src/zypper-sources.h Fri Jun 22 18:21:00 2007
@@ -62,11 +62,18 @@
//void cond_init_system_sources(); // OLD
void init_system_sources(); // OLD
-void remove_source( const std::string& anystring ); // OLD
+/**
+ * Delte repository specified by \a alias.
+ */
void remove_repo( const std::string &alias );
-void rename_source( const std::string& anystring, const std::string& newalias ); // OLD
-void include_source_by_url( const zypp::Url &url ); // OLD
+
+/**
+ * Rename repository specified by \a alias to \a newalias.
+ */
+void rename_repo(const std::string & alias, const std::string & newalias);
+
+//void include_source_by_url( const zypp::Url &url ); // OLD
#endif
// Local Variables:
Modified: trunk/zypper/src/zypper.cc
URL: http://svn.opensuse.org/viewcvs/zypp/trunk/zypper/src/zypper.cc?rev=5838&r1=5837&r2=5838&view=diff
==============================================================================
--- trunk/zypper/src/zypper.cc (original)
+++ trunk/zypper/src/zypper.cc Fri Jun 22 18:21:00 2007
@@ -683,19 +683,16 @@
}
// --------------------------( service rename )-----------------------------
-/*
- else if (command == ZypperCommand::NONE) //command_str == "service-rename" || command_str == "sr")
+
+ else if (command == ZypperCommand::RENAME_REPO)
{
- if (ghelp || arguments.size() < 2) {
- cerr << specific_help;
- return !ghelp;
- }
+ if (ghelp || arguments.size() < 2) { cerr << specific_help; return !ghelp; }
- cond_init_target ();
+// cond_init_target ();
warn_if_zmd ();
try {
// also stores it
- rename_source (arguments[0], arguments[1]);
+ rename_repo(arguments[0], arguments[1]);
}
catch ( const Exception & excpt_r )
{
@@ -705,7 +702,7 @@
return ZYPPER_EXIT_OK;
}
- */
+
// --------------------------( refresh )------------------------------------
else if (command == ZypperCommand::REFRESH)
--
To unsubscribe, e-mail: zypp-commit+unsubscribe@opensuse.org
For additional commands, e-mail: zypp-commit+help@opensuse.org