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
5 changed files with 47 additions and 82 deletions

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@"