diff frontends/src/jp/cmd_profile.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 63d191c05ecd
line wrap: on
line diff
--- a/frontends/src/jp/cmd_profile.py	Sun Feb 12 18:59:10 2017 +0100
+++ b/frontends/src/jp/cmd_profile.py	Sun Feb 12 19:08:52 2017 +0100
@@ -35,7 +35,7 @@
     def __init__(self, host):
         # it's weird to have a command named "connect" with need_connect=False, but it can be handy to be able
         # to launch just the session, so some paradox don't hurt
-        super(ProfileConnect, self).__init__(host, 'connect', need_connect=False, help=_('connect a profile'))
+        super(ProfileConnect, self).__init__(host, 'connect', need_connect=False, help=(u'connect a profile'))
 
     def add_parser_options(self):
         pass
@@ -43,7 +43,7 @@
 
 class ProfileDefault(base.CommandBase):
     def __init__(self, host):
-        super(ProfileDefault, self).__init__(host, 'default', use_profile=False, help=_('print default profile'))
+        super(ProfileDefault, self).__init__(host, 'default', use_profile=False, help=(u'print default profile'))
 
     def add_parser_options(self):
         pass
@@ -54,14 +54,14 @@
 
 class ProfileDelete(base.CommandBase):
     def __init__(self, host):
-        super(ProfileDelete, self).__init__(host, 'delete', use_profile=False, help=_('delete a profile'))
+        super(ProfileDelete, self).__init__(host, 'delete', use_profile=False, help=(u'delete a profile'))
 
     def add_parser_options(self):
         self.parser.add_argument('profile', type=str, help=PROFILE_HELP)
         self.parser.add_argument('-f', '--force', action='store_true', help=_(u'delete profile without confirmation'))
 
     def start(self):
-        if self.args.profile not in self.host.bridge.getProfilesList():
+        if self.args.profile not in self.host.bridge.profilesListGet():
             log.error("Profile %s doesn't exist." % self.args.profile)
             self.host.quit(1)
         message = u"Are you sure to delete profile [{}] ?".format(self.args.profile)
@@ -76,7 +76,7 @@
 
 class ProfileInfo(base.CommandBase):
     def __init__(self, host):
-        super(ProfileInfo, self).__init__(host, 'info', need_connect=False, help=_('get information about a profile'))
+        super(ProfileInfo, self).__init__(host, 'info', need_connect=False, help=_(u'get information about a profile'))
         self.need_loop = True
         self.to_show = [(_(u"jid"), "Connection", "JabberID"),]
         self.largest = max([len(item[0]) for item in self.to_show])
@@ -105,25 +105,34 @@
 
 class ProfileList(base.CommandBase):
     def __init__(self, host):
-        super(ProfileList, self).__init__(host, 'list', use_profile=False, use_output='list', help=_('list profiles'))
+        super(ProfileList, self).__init__(host, 'list', use_profile=False, use_output='list', help=(u'list profiles'))
 
     def add_parser_options(self):
-        pass
+        group = self.parser.add_mutually_exclusive_group()
+        group.add_argument('-c', '--clients', action='store_true', help=_(u'the password of the profile'))
+        group.add_argument('-C', '--components', action='store_true', help=(u'the password of the profile'))
+
 
     def start(self):
-        self.output(self.host.bridge.getProfilesList())
+        if self.args.clients:
+            clients, components = True, False
+        elif self.args.components:
+            clients, components = False, True
+        else:
+            clients, components = True, True
+        self.output(self.host.bridge.profilesListGet(clients, components))
 
 
 class ProfileCreate(base.CommandBase):
     def __init__(self, host):
-        super(ProfileCreate, self).__init__(host, 'create', use_profile=False, help=_('create a new profile'))
+        super(ProfileCreate, self).__init__(host, 'create', use_profile=False, help=(u'create a new profile'))
         self.need_loop = True
 
     def add_parser_options(self):
-        self.parser.add_argument('profile', type=str, help=_('the name of the profile'))
-        self.parser.add_argument('-p', '--password', type=str, default='', help=_('the password of the profile'))
-        self.parser.add_argument('-j', '--jid', type=str, help=_('the jid of the profile'))
-        self.parser.add_argument('-x', '--xmpp-password', type=str, help=_('the password of the XMPP account (use profile password if not specified)'),
+        self.parser.add_argument('profile', type=str, help=(u'the name of the profile'))
+        self.parser.add_argument('-p', '--password', type=str, default='', help=(u'the password of the profile'))
+        self.parser.add_argument('-j', '--jid', type=str, help=(u'the jid of the profile'))
+        self.parser.add_argument('-x', '--xmpp-password', type=str, help=(u'the password of the XMPP account (use profile password if not specified)'),
                                  metavar='PASSWORD')
         self.parser.add_argument('-C', '--component', type=base.unicode_decoder, default='',
                                  help=_(u'set to component import name (entry point) if this is a component'))
@@ -141,7 +150,7 @@
 
     def start(self):
         """Create a new profile"""
-        if self.args.profile in self.host.bridge.getProfilesList():
+        if self.args.profile in self.host.bridge.profilesListGet():
             log.error("Profile %s already exists." % self.args.profile)
             self.host.quit(1)
         self.host.bridge.profileCreate(self.args.profile, self.args.password, self.args.component, callback=self._profile_created, errback=None)
@@ -149,14 +158,14 @@
 
 class ProfileModify(base.CommandBase):
     def __init__(self, host):
-        super(ProfileModify, self).__init__(host, 'modify', need_connect=False, help=_('modify an existing profile'))
+        super(ProfileModify, self).__init__(host, 'modify', need_connect=False, help=(u'modify an existing profile'))
 
     def add_parser_options(self):
         profile_pwd_group = self.parser.add_mutually_exclusive_group()
-        profile_pwd_group.add_argument('-w', '--password', type=base.unicode_decoder, help=_('change the password of the profile'))
-        profile_pwd_group.add_argument('--disable-password', action='store_true', help=_('disable profile password (dangerous!)'))
-        self.parser.add_argument('-j', '--jid', type=base.unicode_decoder, help=_('the jid of the profile'))
-        self.parser.add_argument('-x', '--xmpp-password', type=base.unicode_decoder, help=_('change the password of the XMPP account'),
+        profile_pwd_group.add_argument('-w', '--password', type=base.unicode_decoder, help=(u'change the password of the profile'))
+        profile_pwd_group.add_argument('--disable-password', action='store_true', help=(u'disable profile password (dangerous!)'))
+        self.parser.add_argument('-j', '--jid', type=base.unicode_decoder, help=(u'the jid of the profile'))
+        self.parser.add_argument('-x', '--xmpp-password', type=base.unicode_decoder, help=(u'change the password of the XMPP account'),
                                  metavar='PASSWORD')
         self.parser.add_argument('-D', '--default', action='store_true', help=_(u'set as default profile'))
 
@@ -177,4 +186,4 @@
     subcommands = (ProfileConnect, ProfileCreate, ProfileDefault, ProfileDelete, ProfileInfo, ProfileList, ProfileModify)
 
     def __init__(self, host):
-        super(Profile, self).__init__(host, 'profile', use_profile=False, help=_('Profile commands'))
+        super(Profile, self).__init__(host, 'profile', use_profile=False, help=(u'Profile commands'))