diff src/memory/memory.py @ 728:e07afabc4a25

plugin XEP-0050: Ad-Hoc commands first draft (answering part)
author Goffi <goffi@goffi.org>
date Tue, 10 Dec 2013 17:25:31 +0100
parents 04aabc3f2684
children 8f50a0079769
line wrap: on
line diff
--- a/src/memory/memory.py	Tue Dec 10 17:25:31 2013 +0100
+++ b/src/memory/memory.py	Tue Dec 10 17:25:31 2013 +0100
@@ -181,12 +181,13 @@
         self.storage.deleteProfile(profile)
         return False
 
-    def getProfileName(self, profile_key):
+    def getProfileName(self, profile_key, return_profile_keys = False):
         """return profile according to profile_key
         @param profile_key: profile name or key which can be
                             @ALL@ for all profiles
                             @DEFAULT@ for default profile
-        @return: requested profile name or None if it doesn't exist"""
+        @param return_profile_keys: if True, return unmanaged profile keys (like "@ALL@"). This keys must be managed by the caller
+        @return: requested profile name or emptry string if it doesn't exist"""
         if profile_key == '@DEFAULT@':
             default = self.host.memory.memory_data.get('Profile_default')
             if not default:
@@ -199,9 +200,11 @@
             return default  # FIXME: temporary, must use real default value, and fallback to first one if it doesn't exists
         elif profile_key == '@NONE@':
             raise exceptions.ProfileNotSetError
+        elif return_profile_keys and profile_key in ["@ALL@"]:
+            return profile_key # this value must be managed by the caller
         if not self.storage.hasProfile(profile_key):
             info(_('Trying to access an unknown profile'))
-            return ""
+            return "" # FIXME: raise exceptions.ProfileUnknownError here (must be well checked, this method is used in lot of places)
         return profile_key
 
     def __get_unique_node(self, parent, tag, name):
@@ -711,11 +714,11 @@
     def getProfilesList(self):
         return self.storage.getProfilesList()
 
-    def getProfileName(self, profile_key):
+    def getProfileName(self, profile_key, return_profile_keys = False):
         """Return name of profile from keyword
         @param profile_key: can be the profile name or a keywork (like @DEFAULT@)
         @return: profile name or None if it doesn't exist"""
-        return self.params.getProfileName(profile_key)
+        return self.params.getProfileName(profile_key, return_profile_keys)
 
     def createProfile(self, name):
         """Create a new profile