Author: lslezak
Date: Fri Oct 17 14:41:22 2008
New Revision: 52334
URL: http://svn.opensuse.org/viewcvs/yast?rev=52334&view=rev
Log:
- added ServiceSave() function (bnc#435669)
Modified:
trunk/pkg-bindings/package/yast2-pkg-bindings.changes
trunk/pkg-bindings/src/PkgFunctions.h
trunk/pkg-bindings/src/Service.cc
trunk/pkg-bindings/src/ServiceManager.cc
trunk/pkg-bindings/src/ServiceManager.h
Modified: trunk/pkg-bindings/package/yast2-pkg-bindings.changes
URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/package/yast2-pkg-bindings.changes?rev=52334&r1=52333&r2=52334&view=diff
==============================================================================
--- trunk/pkg-bindings/package/yast2-pkg-bindings.changes (original)
+++ trunk/pkg-bindings/package/yast2-pkg-bindings.changes Fri Oct 17 14:41:22 2008
@@ -1,6 +1,7 @@
-------------------------------------------------------------------
Fri Oct 17 12:06:44 CEST 2008 - lslezak@suse.cz
+- added ServiceSave() function (bnc#435669)
- fixed ServiceDelete() - delete also the repositories belonging
to the deleted service, similar fix in enabling/disabling
a service via ServiceSet() (bnc#435711)
Modified: trunk/pkg-bindings/src/PkgFunctions.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/PkgFunctions.h?rev=52334&r1=52333&r2=52334&view=diff
==============================================================================
--- trunk/pkg-bindings/src/PkgFunctions.h (original)
+++ trunk/pkg-bindings/src/PkgFunctions.h Fri Oct 17 14:41:22 2008
@@ -798,6 +798,8 @@
YCPValue ServiceURL(const YCPString &alias);
/* TYPEINFO: string(string)*/
YCPValue ServiceProbe(const YCPString &url);
+ /* TYPEINFO: boolean(string)*/
+ YCPValue ServiceSave(const YCPString &alias);
YCPValue ResolvablePropertiesEx(const YCPString& name, const YCPSymbol& kind_r, const YCPString& version, bool dependencies);
Modified: trunk/pkg-bindings/src/Service.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/Service.cc?rev=52334&r1=52333&r2=52334&view=diff
==============================================================================
--- trunk/pkg-bindings/src/Service.cc (original)
+++ trunk/pkg-bindings/src/Service.cc Fri Oct 17 14:41:22 2008
@@ -130,6 +130,38 @@
/**
+ * @builtin ServiceSave
+ * @short Save a service to .service file
+ * All services are saved/updated/removed in Pkg::SourceSaveAll()
+ * @param alias alias of the service to remove
+ * @return boolean false if failed
+*/
+YCPValue PkgFunctions::ServiceSave(const YCPString &alias)
+{
+ try
+ {
+ if (alias.isNull())
+ {
+ y2error("Found nil parameter in Pkg::ServiceSave()");
+ return YCPBoolean(false);
+ }
+
+ std::string service_alias = alias->value();
+ zypp::RepoManager repomanager = CreateRepoManager();
+ y2milestone("Saving service %s", service_alias.c_str());
+
+ bool ret = service_manager.SaveService(service_alias, repomanager);
+ return YCPBoolean(ret);
+ }
+ catch (const zypp::Exception& excpt)
+ {
+ _last_error.setLastError(ExceptionAsString(excpt));
+ }
+
+ return YCPBoolean(false);
+}
+
+/**
@builtin ServiceGet
@short Get detailed properties of a service
@param alias alias of the service
Modified: trunk/pkg-bindings/src/ServiceManager.cc
URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/ServiceManager.cc?rev=52334&r1=52333&r2=52334&view=diff
==============================================================================
--- trunk/pkg-bindings/src/ServiceManager.cc (original)
+++ trunk/pkg-bindings/src/ServiceManager.cc Fri Oct 17 14:41:22 2008
@@ -70,52 +70,37 @@
{
if (!it->second.isDeleted())
{
- const PkgService s_known = it->second;
- const std::string alias(s_known.alias());
- const zypp::ServiceInfo s_stored = repomgr.getService(alias);
-
- DBG << "Known Service: " << it->second << std::endl;
- DBG << "Stored Service: " << repomgr.getService(alias) << std::endl;
-
- bool modified = (s_stored.url() != s_known.url()
- || s_stored.name() != s_known.name()
- || s_stored.enabled() != s_known.enabled()
- || s_stored.autorefresh() != s_known.autorefresh()
- );
-
- if (modified)
- {
- std::string orig_alias(s_known.origAlias());
-
- y2internal("orig_alias: %s", orig_alias.c_str());
-
- // the old alias is empty for new services
- if (orig_alias.empty())
- {
- y2milestone("Adding new service %s", alias.c_str());
- // add the service
- repomgr.addService(s_known);
- }
- else
- {
- y2milestone("Saving service %s", alias.c_str());
- // use the old alias
- repomgr.modifyService(orig_alias, s_known);
- }
- }
- else
- {
- y2milestone("Service %s has not been modified, not saving", alias.c_str());
- }
+ SavePkgService(it->second, repomgr);
}
}
}
+bool ServiceManager::SaveService(const std::string &alias, zypp::RepoManager &repomgr) const
+{
+ PkgServices::const_iterator serv_it = _known_services.find(alias);
+
+ if (serv_it == _known_services.end())
+ {
+ y2error("Service '%s' does not exist", alias.c_str());
+ return false;
+ }
+
+ if (serv_it->second.isDeleted())
+ {
+ y2error("Service '%s' has been deleted", alias.c_str());
+ return false;
+ }
+
+ SavePkgService(serv_it->second, repomgr);
+
+ return true;
+}
+
bool ServiceManager::RefreshService(const std::string &alias, zypp::RepoManager &repomgr)
{
PkgServices::iterator serv_it = _known_services.find(alias);
- if (serv_it == _known_services.end())
+ if (serv_it == _known_services.end() || serv_it->second.isDeleted())
{
y2error("Service '%s' does not exist", alias.c_str());
return false;
@@ -292,3 +277,42 @@
return _known_services.size();
}
+void ServiceManager::SavePkgService(const PkgService &s_known, zypp::RepoManager &repomgr) const
+{
+ const std::string alias(s_known.alias());
+ const zypp::ServiceInfo s_stored = repomgr.getService(alias);
+
+ DBG << "Known Service: " << s_known << std::endl;
+ DBG << "Stored Service: " << s_stored << std::endl;
+
+ bool modified = (s_stored.url() != s_known.url()
+ || s_stored.name() != s_known.name()
+ || s_stored.enabled() != s_known.enabled()
+ || s_stored.autorefresh() != s_known.autorefresh()
+ );
+
+ if (modified)
+ {
+ std::string orig_alias(s_known.origAlias());
+
+ y2internal("orig_alias: %s", orig_alias.c_str());
+
+ // the old alias is empty for new services
+ if (orig_alias.empty())
+ {
+ y2milestone("Adding new service %s", alias.c_str());
+ // add the service
+ repomgr.addService(s_known);
+ }
+ else
+ {
+ y2milestone("Saving service %s", alias.c_str());
+ // use the old alias
+ repomgr.modifyService(orig_alias, s_known);
+ }
+ }
+ else
+ {
+ y2milestone("Service %s has not been modified, not saving", alias.c_str());
+ }
+}
Modified: trunk/pkg-bindings/src/ServiceManager.h
URL: http://svn.opensuse.org/viewcvs/yast/trunk/pkg-bindings/src/ServiceManager.h?rev=52334&r1=52333&r2=52334&view=diff
==============================================================================
--- trunk/pkg-bindings/src/ServiceManager.h (original)
+++ trunk/pkg-bindings/src/ServiceManager.h Fri Oct 17 14:41:22 2008
@@ -44,6 +44,8 @@
void SaveServices(zypp::RepoManager &repomgr) const;
+ bool SaveService(const std::string &alias, zypp::RepoManager &repomgr) const;
+
bool AddService(const std::string &alias, const std::string &url);
bool RemoveService(const std::string &alias);
@@ -67,10 +69,13 @@
private:
+ // internal helper method
+ void SavePkgService(const PkgService &s_known, zypp::RepoManager &repomgr) const;
+
// current alias -> PkgService for convenient search by alias
typedef std::map