Mercurial > libervia-backend
comparison 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 |
comparison
equal
deleted
inserted
replaced
2145:33c8c4973743 | 2146:1bb9bf1b4150 |
---|---|
33 """Dummy command to use profile_session parent, i.e. to be able to connect without doing anything else""" | 33 """Dummy command to use profile_session parent, i.e. to be able to connect without doing anything else""" |
34 | 34 |
35 def __init__(self, host): | 35 def __init__(self, host): |
36 # it's weird to have a command named "connect" with need_connect=False, but it can be handy to be able | 36 # it's weird to have a command named "connect" with need_connect=False, but it can be handy to be able |
37 # to launch just the session, so some paradox don't hurt | 37 # to launch just the session, so some paradox don't hurt |
38 super(ProfileConnect, self).__init__(host, 'connect', need_connect=False, help=_('connect a profile')) | 38 super(ProfileConnect, self).__init__(host, 'connect', need_connect=False, help=(u'connect a profile')) |
39 | 39 |
40 def add_parser_options(self): | 40 def add_parser_options(self): |
41 pass | 41 pass |
42 | 42 |
43 | 43 |
44 class ProfileDefault(base.CommandBase): | 44 class ProfileDefault(base.CommandBase): |
45 def __init__(self, host): | 45 def __init__(self, host): |
46 super(ProfileDefault, self).__init__(host, 'default', use_profile=False, help=_('print default profile')) | 46 super(ProfileDefault, self).__init__(host, 'default', use_profile=False, help=(u'print default profile')) |
47 | 47 |
48 def add_parser_options(self): | 48 def add_parser_options(self): |
49 pass | 49 pass |
50 | 50 |
51 def start(self): | 51 def start(self): |
52 print self.host.bridge.getProfileName('@DEFAULT@') | 52 print self.host.bridge.getProfileName('@DEFAULT@') |
53 | 53 |
54 | 54 |
55 class ProfileDelete(base.CommandBase): | 55 class ProfileDelete(base.CommandBase): |
56 def __init__(self, host): | 56 def __init__(self, host): |
57 super(ProfileDelete, self).__init__(host, 'delete', use_profile=False, help=_('delete a profile')) | 57 super(ProfileDelete, self).__init__(host, 'delete', use_profile=False, help=(u'delete a profile')) |
58 | 58 |
59 def add_parser_options(self): | 59 def add_parser_options(self): |
60 self.parser.add_argument('profile', type=str, help=PROFILE_HELP) | 60 self.parser.add_argument('profile', type=str, help=PROFILE_HELP) |
61 self.parser.add_argument('-f', '--force', action='store_true', help=_(u'delete profile without confirmation')) | 61 self.parser.add_argument('-f', '--force', action='store_true', help=_(u'delete profile without confirmation')) |
62 | 62 |
63 def start(self): | 63 def start(self): |
64 if self.args.profile not in self.host.bridge.getProfilesList(): | 64 if self.args.profile not in self.host.bridge.profilesListGet(): |
65 log.error("Profile %s doesn't exist." % self.args.profile) | 65 log.error("Profile %s doesn't exist." % self.args.profile) |
66 self.host.quit(1) | 66 self.host.quit(1) |
67 message = u"Are you sure to delete profile [{}] ?".format(self.args.profile) | 67 message = u"Are you sure to delete profile [{}] ?".format(self.args.profile) |
68 if not self.args.force: | 68 if not self.args.force: |
69 res = raw_input("{} (y/N)? ".format(message)) | 69 res = raw_input("{} (y/N)? ".format(message)) |
74 self.host.bridge.asyncDeleteProfile(self.args.profile, callback=lambda dummy: None) | 74 self.host.bridge.asyncDeleteProfile(self.args.profile, callback=lambda dummy: None) |
75 | 75 |
76 | 76 |
77 class ProfileInfo(base.CommandBase): | 77 class ProfileInfo(base.CommandBase): |
78 def __init__(self, host): | 78 def __init__(self, host): |
79 super(ProfileInfo, self).__init__(host, 'info', need_connect=False, help=_('get information about a profile')) | 79 super(ProfileInfo, self).__init__(host, 'info', need_connect=False, help=_(u'get information about a profile')) |
80 self.need_loop = True | 80 self.need_loop = True |
81 self.to_show = [(_(u"jid"), "Connection", "JabberID"),] | 81 self.to_show = [(_(u"jid"), "Connection", "JabberID"),] |
82 self.largest = max([len(item[0]) for item in self.to_show]) | 82 self.largest = max([len(item[0]) for item in self.to_show]) |
83 | 83 |
84 | 84 |
103 self.showNextValue() | 103 self.showNextValue() |
104 | 104 |
105 | 105 |
106 class ProfileList(base.CommandBase): | 106 class ProfileList(base.CommandBase): |
107 def __init__(self, host): | 107 def __init__(self, host): |
108 super(ProfileList, self).__init__(host, 'list', use_profile=False, use_output='list', help=_('list profiles')) | 108 super(ProfileList, self).__init__(host, 'list', use_profile=False, use_output='list', help=(u'list profiles')) |
109 | 109 |
110 def add_parser_options(self): | 110 def add_parser_options(self): |
111 pass | 111 group = self.parser.add_mutually_exclusive_group() |
112 group.add_argument('-c', '--clients', action='store_true', help=_(u'the password of the profile')) | |
113 group.add_argument('-C', '--components', action='store_true', help=(u'the password of the profile')) | |
114 | |
112 | 115 |
113 def start(self): | 116 def start(self): |
114 self.output(self.host.bridge.getProfilesList()) | 117 if self.args.clients: |
118 clients, components = True, False | |
119 elif self.args.components: | |
120 clients, components = False, True | |
121 else: | |
122 clients, components = True, True | |
123 self.output(self.host.bridge.profilesListGet(clients, components)) | |
115 | 124 |
116 | 125 |
117 class ProfileCreate(base.CommandBase): | 126 class ProfileCreate(base.CommandBase): |
118 def __init__(self, host): | 127 def __init__(self, host): |
119 super(ProfileCreate, self).__init__(host, 'create', use_profile=False, help=_('create a new profile')) | 128 super(ProfileCreate, self).__init__(host, 'create', use_profile=False, help=(u'create a new profile')) |
120 self.need_loop = True | 129 self.need_loop = True |
121 | 130 |
122 def add_parser_options(self): | 131 def add_parser_options(self): |
123 self.parser.add_argument('profile', type=str, help=_('the name of the profile')) | 132 self.parser.add_argument('profile', type=str, help=(u'the name of the profile')) |
124 self.parser.add_argument('-p', '--password', type=str, default='', help=_('the password of the profile')) | 133 self.parser.add_argument('-p', '--password', type=str, default='', help=(u'the password of the profile')) |
125 self.parser.add_argument('-j', '--jid', type=str, help=_('the jid of the profile')) | 134 self.parser.add_argument('-j', '--jid', type=str, help=(u'the jid of the profile')) |
126 self.parser.add_argument('-x', '--xmpp-password', type=str, help=_('the password of the XMPP account (use profile password if not specified)'), | 135 self.parser.add_argument('-x', '--xmpp-password', type=str, help=(u'the password of the XMPP account (use profile password if not specified)'), |
127 metavar='PASSWORD') | 136 metavar='PASSWORD') |
128 self.parser.add_argument('-C', '--component', type=base.unicode_decoder, default='', | 137 self.parser.add_argument('-C', '--component', type=base.unicode_decoder, default='', |
129 help=_(u'set to component import name (entry point) if this is a component')) | 138 help=_(u'set to component import name (entry point) if this is a component')) |
130 | 139 |
131 def _session_started(self, dummy): | 140 def _session_started(self, dummy): |
139 def _profile_created(self): | 148 def _profile_created(self): |
140 self.host.bridge.profileStartSession(self.args.password, self.args.profile, callback=self._session_started, errback=None) | 149 self.host.bridge.profileStartSession(self.args.password, self.args.profile, callback=self._session_started, errback=None) |
141 | 150 |
142 def start(self): | 151 def start(self): |
143 """Create a new profile""" | 152 """Create a new profile""" |
144 if self.args.profile in self.host.bridge.getProfilesList(): | 153 if self.args.profile in self.host.bridge.profilesListGet(): |
145 log.error("Profile %s already exists." % self.args.profile) | 154 log.error("Profile %s already exists." % self.args.profile) |
146 self.host.quit(1) | 155 self.host.quit(1) |
147 self.host.bridge.profileCreate(self.args.profile, self.args.password, self.args.component, callback=self._profile_created, errback=None) | 156 self.host.bridge.profileCreate(self.args.profile, self.args.password, self.args.component, callback=self._profile_created, errback=None) |
148 | 157 |
149 | 158 |
150 class ProfileModify(base.CommandBase): | 159 class ProfileModify(base.CommandBase): |
151 def __init__(self, host): | 160 def __init__(self, host): |
152 super(ProfileModify, self).__init__(host, 'modify', need_connect=False, help=_('modify an existing profile')) | 161 super(ProfileModify, self).__init__(host, 'modify', need_connect=False, help=(u'modify an existing profile')) |
153 | 162 |
154 def add_parser_options(self): | 163 def add_parser_options(self): |
155 profile_pwd_group = self.parser.add_mutually_exclusive_group() | 164 profile_pwd_group = self.parser.add_mutually_exclusive_group() |
156 profile_pwd_group.add_argument('-w', '--password', type=base.unicode_decoder, help=_('change the password of the profile')) | 165 profile_pwd_group.add_argument('-w', '--password', type=base.unicode_decoder, help=(u'change the password of the profile')) |
157 profile_pwd_group.add_argument('--disable-password', action='store_true', help=_('disable profile password (dangerous!)')) | 166 profile_pwd_group.add_argument('--disable-password', action='store_true', help=(u'disable profile password (dangerous!)')) |
158 self.parser.add_argument('-j', '--jid', type=base.unicode_decoder, help=_('the jid of the profile')) | 167 self.parser.add_argument('-j', '--jid', type=base.unicode_decoder, help=(u'the jid of the profile')) |
159 self.parser.add_argument('-x', '--xmpp-password', type=base.unicode_decoder, help=_('change the password of the XMPP account'), | 168 self.parser.add_argument('-x', '--xmpp-password', type=base.unicode_decoder, help=(u'change the password of the XMPP account'), |
160 metavar='PASSWORD') | 169 metavar='PASSWORD') |
161 self.parser.add_argument('-D', '--default', action='store_true', help=_(u'set as default profile')) | 170 self.parser.add_argument('-D', '--default', action='store_true', help=_(u'set as default profile')) |
162 | 171 |
163 def start(self): | 172 def start(self): |
164 if self.args.disable_password: | 173 if self.args.disable_password: |
175 | 184 |
176 class Profile(base.CommandBase): | 185 class Profile(base.CommandBase): |
177 subcommands = (ProfileConnect, ProfileCreate, ProfileDefault, ProfileDelete, ProfileInfo, ProfileList, ProfileModify) | 186 subcommands = (ProfileConnect, ProfileCreate, ProfileDefault, ProfileDelete, ProfileInfo, ProfileList, ProfileModify) |
178 | 187 |
179 def __init__(self, host): | 188 def __init__(self, host): |
180 super(Profile, self).__init__(host, 'profile', use_profile=False, help=_('Profile commands')) | 189 super(Profile, self).__init__(host, 'profile', use_profile=False, help=(u'Profile commands')) |