diff src/memory/memory.py @ 2146:1bb9bf1b4150

core, frontends: getProfilesList renamed to profilesGetList + behaviour change: - profilesGetList now handles clients and components boolean arguments, to filter profiles - jp: added --clients and --components options to profile/list - profilesGetList now returns sorted profiles
author Goffi <goffi@goffi.org>
date Sun, 12 Feb 2017 19:08:52 +0100
parents 1d3f73e065e1
children 8b37a62336c3
line wrap: on
line diff
--- a/src/memory/memory.py	Sun Feb 12 18:59:10 2017 +0100
+++ b/src/memory/memory.py	Sun Feb 12 19:08:52 2017 +0100
@@ -430,8 +430,26 @@
         except KeyError:
             log.error(_(u"Trying to purge roster status cache for a profile not in memory: [%s]") % profile)
 
-    def getProfilesList(self):
-        return self.storage.getProfilesList()
+    def getProfilesList(self, clients=True, components=False):
+        """retrieve profiles list
+
+        @param clients(bool): if True return clients profiles
+        @param components(bool): if True return components profiles
+        @return (list[unicode]): selected profiles
+        """
+        if not clients and not components:
+            log.warning(_(u"requesting no profiles at all"))
+            return []
+        profiles = self.storage.getProfilesList()
+        if clients and components:
+            return sorted(profiles)
+        isComponent = self.storage.profileIsComponent
+        if clients:
+            p_filter = lambda p: not isComponent(p)
+        else:
+            p_filter = lambda p: isComponent(p)
+
+        return sorted(p for p in profiles if p_filter(p))
 
     def getProfileName(self, profile_key, return_profile_keys=False):
         """Return name of profile from keyword