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

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