diff src/memory/memory.py @ 893:308a96bc7c1b

core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
author souliane <souliane@mailoo.org>
date Mon, 03 Mar 2014 09:59:10 +0100
parents f27d736428f1
children 57c32d8ec847
line wrap: on
line diff
--- a/src/memory/memory.py	Fri Feb 28 11:19:08 2014 +0100
+++ b/src/memory/memory.py	Mon Mar 03 09:59:10 2014 +0100
@@ -215,25 +215,11 @@
         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 @@
             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 @@
         @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@"