core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile

This commit is contained in:
souliane 2014-03-03 09:59:10 +01:00
commit d158589881
9 changed files with 47 additions and 82 deletions

View file

@ -104,6 +104,9 @@ class DBusBridgeFrontend(BridgeFrontend):
def asyncCreateProfile(self, profile, callback=None, errback=None):
return self.db_core_iface.asyncCreateProfile(profile, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:]))
def asyncDeleteProfile(self, profile, callback=None, errback=None):
return self.db_core_iface.asyncDeleteProfile(profile, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:]))
def asyncGetParamA(self, name, category, attribute="value", security_limit=-1, profile_key="@DEFAULT@", callback=None, errback=None):
return unicode(self.db_core_iface.asyncGetParamA(name, category, attribute, security_limit, profile_key, reply_handler=callback, error_handler=lambda err:errback(err._dbus_error_name[len(const_ERROR_PREFIX)+1:])))
@ -113,15 +116,9 @@ class DBusBridgeFrontend(BridgeFrontend):
def connect(self, profile_key="@DEFAULT@"):
return self.db_core_iface.connect(profile_key)
def createProfile(self, profile):
return self.db_core_iface.createProfile(profile)
def delContact(self, entity_jid, profile_key="@DEFAULT@"):
return self.db_core_iface.delContact(entity_jid, profile_key)
def deleteProfile(self, profile):
return self.db_core_iface.deleteProfile(profile)
def disconnect(self, profile_key="@DEFAULT@"):
return self.db_core_iface.disconnect(profile_key)

View file

@ -42,7 +42,7 @@ class ProfileDelete(base.CommandBase):
if self.args.profile not in self.host.bridge.getProfilesList():
error("Profile %s doesn't exist." % self.args.profile)
self.host.quit(1)
self.host.bridge.deleteProfile(self.args.profile)
self.host.bridge.asyncDeleteProfile(self.args.profile, callback=lambda dummy: None)
class ProfileInfo(base.CommandBase):

View file

@ -92,8 +92,7 @@ class ProfileManager(urwid.WidgetWrap):
def deleteProfile(self, button):
profile_name = self.list_profile.getSelectedValue()
if profile_name:
self.host.bridge.deleteProfile(profile_name)
self.__refillProfiles()
self.host.bridge.asyncDeleteProfile(profile_name, callback=self.__refillProfiles)
self.host.removePopUp()
def onNewProfile(self, e):

View file

@ -21,10 +21,8 @@
from sat.core.i18n import _
import wx
import pdb
from logging import debug, info, error
from sat.tools.jid import JID
import pdb
class ProfileManager(wx.Panel):
@ -99,9 +97,10 @@ class ProfileManager(wx.Panel):
if name[0]=='@':
wx.MessageDialog(self, _("A profile name can't start with a @"), _("Bad profile name"), wx.ICON_ERROR).ShowModal()
else:
profile = self.host.bridge.createProfile(name)
self.__refillProfiles()
self.profile_name.SetValue(name)
def cb():
self.__refillProfiles()
self.profile_name.SetValue(name)
self.host.bridge.asyncCreateProfile(name, callback=cb)
dlg.Destroy()
def onDeleteProfile(self, event):
@ -110,9 +109,10 @@ class ProfileManager(wx.Panel):
return
dlg = wx.MessageDialog(self, _("Are you sure to delete the profile [%s]") % name, _("Confirmation"), wx.ICON_QUESTION | wx.YES_NO)
if dlg.ShowModal() == wx.ID_YES:
self.host.bridge.deleteProfile(name)
self.__refillProfiles()
self.__setDefault()
def cb():
self.__refillProfiles()
self.__setDefault()
self.host.bridge.asyncDeleteProfile(name, callback=cb)
dlg.Destroy()
def onProfileChange(self, event):

View file

@ -203,6 +203,12 @@ class DbusObject(dbus.service.Object):
def asyncCreateProfile(self, profile, callback=None, errback=None):
return self._callback("asyncCreateProfile", unicode(profile), callback=callback, errback=errback)
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='s', out_signature='',
async_callbacks=('callback', 'errback'))
def asyncDeleteProfile(self, profile, callback=None, errback=None):
return self._callback("asyncDeleteProfile", unicode(profile), callback=callback, errback=errback)
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='sssis', out_signature='s',
async_callbacks=('callback', 'errback'))
@ -221,24 +227,12 @@ class DbusObject(dbus.service.Object):
def connect(self, profile_key="@DEFAULT@"):
return self._callback("connect", unicode(profile_key))
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='s', out_signature='i',
async_callbacks=None)
def createProfile(self, profile):
return self._callback("createProfile", unicode(profile))
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='ss', out_signature='',
async_callbacks=None)
def delContact(self, entity_jid, profile_key="@DEFAULT@"):
return self._callback("delContact", unicode(entity_jid), unicode(profile_key))
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='s', out_signature='i',
async_callbacks=None)
def deleteProfile(self, profile):
return self._callback("deleteProfile", unicode(profile))
@dbus.service.method(const_INT_PREFIX+const_CORE_SUFFIX,
in_signature='s', out_signature='',
async_callbacks=None)

View file

@ -192,18 +192,6 @@ doc_param_2=%(doc_profile)s
doc_return=dictionary of asked key,
if key doesn't exist, the resulting dictionary will neither have the key
[createProfile]
deprecated=
type=method
category=core
sig_in=s
sig_out=i
doc=Create a new profile
doc_param_0=%(doc_profile)s
doc_return=status of the creation:
- 0: Profile created
- 1: The profile name already exists
[asyncCreateProfile]
async=
type=method
@ -214,19 +202,22 @@ doc=Create a new profile
doc_param_0=%(doc_profile)s
doc_return=callback is called when profile actually exists in database and memory
errback is called with error constant as parameter:
- "CONFLICT": The profile name already exists
- "CANCELED": profile creation canceled
- ConflictError: the profile name already exists
- CancelError: profile creation canceled
[deleteProfile]
[asyncDeleteProfile]
async=
type=method
category=core
sig_in=s
sig_out=i
sig_out=
doc=Delete a profile
doc_param_0=%(doc_profile)s
doc_return=status of the deletion:
- 0: Profile deleted
- 1: The profile doesn't exists
doc_return=callback is called when profile has been deleted from database and memory
errback is called with error constant as parameter:
- ProfileUnknownError: the profile name is unknown
- ConnectedProfileError: a connected profile would not be deleted
[registerNewAccount]
deprecated=

View file

@ -33,6 +33,11 @@ class ProfileNotSetError(Exception):
pass
class ConnectedProfileError(Exception):
"""This error is raised when trying to delete a connected profile."""
pass
class NotConnectedProfileError(Exception):
pass

View file

@ -134,9 +134,8 @@ class SAT(service.Service):
self.bridge.register("getProfileName", self.memory.getProfileName)
self.bridge.register("getProfilesList", self.memory.getProfilesList)
self.bridge.register("getEntityData", lambda _jid, keys, profile: self.memory.getEntityData(jid.JID(_jid), keys, profile))
self.bridge.register("createProfile", self.memory.createProfile)
self.bridge.register("asyncCreateProfile", self.memory.asyncCreateProfile)
self.bridge.register("deleteProfile", self.memory.deleteProfile)
self.bridge.register("asyncDeleteProfile", self.memory.asyncDeleteProfile)
self.bridge.register("registerNewAccount", self.registerNewAccount)
self.bridge.register("connect", self.connect)
self.bridge.register("asyncConnect", self.asyncConnect)

View file

@ -215,25 +215,11 @@ class Params(object):
self.params_gen = {}
host.registerCallback(host.registerNewAccountCB, with_data=True, force_id="registerNewAccount")
def createProfile(self, profile):
"""Create a new profile
@param profile: profile of the profile"""
#FIXME: must be asynchronous and call the callback once the profile actually exists
if self.storage.hasProfile(profile):
info(_('The profile [%s] already exists') % (profile, ))
return True
if not self.host.trigger.point("ProfileCreation", profile):
return False
self.storage.createProfile(profile)
return False
def asyncCreateProfile(self, profile):
"""Create a new profile
@param profile: name of the profile
@param callback: called when the profile actually exists in database and memory
@param errback: called with a string constant as parameter:
- CONFLICT: the profile already exists
- CANCELED: profile creation canceled
@return: a Deferred instance
"""
if self.storage.hasProfile(profile):
info(_('The profile name already exists'))
@ -242,18 +228,18 @@ class Params(object):
return defer.fail(Failure(exceptions.CancelError))
return self.storage.createProfile(profile)
def deleteProfile(self, profile):
def asyncDeleteProfile(self, profile):
"""Delete an existing profile
@param profile: name of the profile"""
#TODO: async equivalent, like for createProfile
@param profile: name of the profile
@return: a Deferred instance
"""
if not self.storage.hasProfile(profile):
error(_('Trying to delete an unknown profile'))
return True
info(_('Trying to delete an unknown profile'))
return defer.fail(Failure(exceptions.ProfileUnknownError))
if self.host.isConnected(profile):
error(_("Trying to delete a connected profile"))
raise exceptions.NotConnectedProfileError
self.storage.deleteProfile(profile)
return False
info(_("Trying to delete a connected profile"))
return defer.fail(Failure(exceptions.ConnectedProfileError))
return self.storage.deleteProfile(profile)
def getProfileName(self, profile_key, return_profile_keys = False):
"""return profile according to profile_key
@ -890,22 +876,16 @@ class Memory(object):
@return: profile name or None if it doesn't exist"""
return self.params.getProfileName(profile_key, return_profile_keys)
def createProfile(self, name):
"""Create a new profile
@param name: Profile name
"""
return self.params.createProfile(name)
def asyncCreateProfile(self, name):
"""Create a new profile
@param name: Profile name
"""
return self.params.asyncCreateProfile(name)
def deleteProfile(self, name):
def asyncDeleteProfile(self, name):
"""Delete an existing profile
@param name: Name of the profile"""
return self.params.deleteProfile(name)
return self.params.asyncDeleteProfile(name)
def addToHistory(self, from_jid, to_jid, message, type_='chat', extra=None, timestamp=None, profile="@NONE@"):
assert profile != "@NONE@"