Mercurial > libervia-backend
annotate frontends/src/jp/cmd_profile.py @ 1626:63cef4dbf2a4
core, plugins file, XEP-0234, bridge: progression api enhancement:
- progressStarted have a new metadata parameter, useful to know the kind of progression, direction, etc. Check bridge doc
- progressGetAllMetadata can be used to retrieve this data and discover on currently running progressions
- progressFinished also have a new metadata parameter, used to e.g. indicate that hash is checked
- core: fixed progressGetAll
- file, XEP-0234: implemented the API modifications, hash is returned on progressFinished
- file: SatFile.checkSize allows to check size independently of close (be sure that all the data have been transfered though)
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 19 Nov 2015 18:13:26 +0100 |
parents | 91a605feed8c |
children | de9cc4d62a4a |
rev | line source |
---|---|
815 | 1 #! /usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # jp: a SAT command line tool | |
1396 | 5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014, 2015 Jérôme Poisson (goffi@goffi.org) |
815 | 6 |
7 # This program is free software: you can redistribute it and/or modify | |
8 # it under the terms of the GNU Affero General Public License as published by | |
9 # the Free Software Foundation, either version 3 of the License, or | |
10 # (at your option) any later version. | |
11 | |
12 # This program is distributed in the hope that it will be useful, | |
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of | |
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
15 # GNU Affero General Public License for more details. | |
16 | |
17 # You should have received a copy of the GNU Affero General Public License | |
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. | |
19 | |
814 | 20 """This module permits to manage profiles. It can list, create, delete |
1199 | 21 and retrieve information about a profile.""" |
0 | 22 |
1596 | 23 import logging as log |
771 | 24 from sat.core.i18n import _ |
817 | 25 from sat_frontends.jp import base |
402
f03688bdb858
jp: use with statement to open fifo
Goffi <goffi@goffi.org>
parents:
401
diff
changeset
|
26 |
817 | 27 __commands__ = ["Profile"] |
28 | |
29 PROFILE_HELP = _('The name of the profile') | |
0 | 30 |
31 | |
1597 | 32 class ProfileConnect(base.CommandBase): |
33 """Dummy command to use profile_session parent, i.e. to be able to connect without doing anything else""" | |
34 | |
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 | |
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')) | |
39 | |
40 def add_parser_options(self): | |
41 pass | |
42 | |
43 | |
1596 | 44 class ProfileDefault(base.CommandBase): |
45 def __init__(self, host): | |
46 super(ProfileDefault, self).__init__(host, 'default', use_profile=False, help=_('print default profile')) | |
47 | |
48 def add_parser_options(self): | |
49 pass | |
50 | |
51 def run(self): | |
52 print self.host.bridge.getProfileName('@DEFAULT@') | |
53 | |
54 | |
817 | 55 class ProfileDelete(base.CommandBase): |
56 def __init__(self, host): | |
1596 | 57 super(ProfileDelete, self).__init__(host, 'delete', use_profile=False, help=_('delete a profile')) |
817 | 58 |
59 def add_parser_options(self): | |
60 self.parser.add_argument('profile', type=str, help=PROFILE_HELP) | |
0 | 61 |
814 | 62 def run(self): |
817 | 63 super(ProfileDelete, self).run() |
64 if self.args.profile not in self.host.bridge.getProfilesList(): | |
1596 | 65 log.error("Profile %s doesn't exist." % self.args.profile) |
817 | 66 self.host.quit(1) |
893
308a96bc7c1b
core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents:
817
diff
changeset
|
67 self.host.bridge.asyncDeleteProfile(self.args.profile, callback=lambda dummy: None) |
817 | 68 |
0 | 69 |
817 | 70 class ProfileInfo(base.CommandBase): |
71 def __init__(self, host): | |
1596 | 72 super(ProfileInfo, self).__init__(host, 'info', need_connect=False, help=_('get information about a profile')) |
73 self.to_show = [(_(u"jid"), "Connection", "JabberID"),] | |
1402
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
74 self.largest = max([len(item[0]) for item in self.to_show]) |
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
75 |
0 | 76 |
817 | 77 def add_parser_options(self): |
1596 | 78 self.parser.add_argument('--show-password', action='store_true', help=_(u'show the XMPP password IN CLEAR TEXT')) |
814 | 79 |
1402
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
80 def showNextValue(self, label=None, category=None, value=None): |
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
81 """Show next value from self.to_show and quit on last one""" |
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
82 if label is not None: |
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
83 print((u"{label:<"+unicode(self.largest+2)+"}{value}").format(label=label+": ", value=value)) |
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
84 try: |
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
85 label, category, name = self.to_show.pop(0) |
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
86 except IndexError: |
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
87 self.host.quit() |
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
88 else: |
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
89 self.host.bridge.asyncGetParamA(name, category, profile_key=self.host.profile, |
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
90 callback=lambda value: self.showNextValue(label, category, value)) |
814 | 91 |
1402
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
92 def connected(self): |
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
93 self.need_loop = True |
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
94 super(ProfileInfo, self).connected() |
1596 | 95 if self.args.show_password: |
96 self.to_show.append((_(u"XMPP password"), "Connection", "Password")) | |
1402
391b0c21f4be
jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents:
1396
diff
changeset
|
97 self.showNextValue() |
817 | 98 |
99 | |
100 class ProfileList(base.CommandBase): | |
101 def __init__(self, host): | |
1596 | 102 super(ProfileList, self).__init__(host, 'list', use_profile=False, help=_('list profiles')) |
657 | 103 |
817 | 104 def add_parser_options(self): |
105 pass | |
106 | |
107 def run(self): | |
108 super(ProfileList, self).run() | |
109 for profile in self.host.bridge.getProfilesList(): | |
110 print profile | |
111 | |
814 | 112 |
817 | 113 class ProfileCreate(base.CommandBase): |
114 def __init__(self, host): | |
1597 | 115 super(ProfileCreate, self).__init__(host, 'create', use_profile=False, help=_('create a new profile')) |
657 | 116 |
817 | 117 def add_parser_options(self): |
118 self.parser.add_argument('profile', type=str, help=_('the name of the profile')) | |
1403
f913b09cd9cc
jp (profile): in "profile create", jid and password arguments are now optional + added a new --xmpp-password option to set XMPP password separately (default to the same password as for profile).
Goffi <goffi@goffi.org>
parents:
1402
diff
changeset
|
119 self.parser.add_argument('-p', '--password', type=str, default='', help=_('the password of the profile')) |
f913b09cd9cc
jp (profile): in "profile create", jid and password arguments are now optional + added a new --xmpp-password option to set XMPP password separately (default to the same password as for profile).
Goffi <goffi@goffi.org>
parents:
1402
diff
changeset
|
120 self.parser.add_argument('-j', '--jid', type=str, help=_('the jid of the profile')) |
f913b09cd9cc
jp (profile): in "profile create", jid and password arguments are now optional + added a new --xmpp-password option to set XMPP password separately (default to the same password as for profile).
Goffi <goffi@goffi.org>
parents:
1402
diff
changeset
|
121 self.parser.add_argument('-x', '--xmpp-password', type=str, help=_('the password of the XMPP account (use profile password if not specified)'), |
f913b09cd9cc
jp (profile): in "profile create", jid and password arguments are now optional + added a new --xmpp-password option to set XMPP password separately (default to the same password as for profile).
Goffi <goffi@goffi.org>
parents:
1402
diff
changeset
|
122 metavar='PASSWORD') |
817 | 123 |
124 def _profile_created(self): | |
1403
f913b09cd9cc
jp (profile): in "profile create", jid and password arguments are now optional + added a new --xmpp-password option to set XMPP password separately (default to the same password as for profile).
Goffi <goffi@goffi.org>
parents:
1402
diff
changeset
|
125 if self.args.jid: |
f913b09cd9cc
jp (profile): in "profile create", jid and password arguments are now optional + added a new --xmpp-password option to set XMPP password separately (default to the same password as for profile).
Goffi <goffi@goffi.org>
parents:
1402
diff
changeset
|
126 self.host.bridge.setParam("JabberID", self.args.jid, "Connection" ,profile_key=self.args.profile) |
f913b09cd9cc
jp (profile): in "profile create", jid and password arguments are now optional + added a new --xmpp-password option to set XMPP password separately (default to the same password as for profile).
Goffi <goffi@goffi.org>
parents:
1402
diff
changeset
|
127 xmpp_pwd = self.args.password or self.args.xmpp_password |
f913b09cd9cc
jp (profile): in "profile create", jid and password arguments are now optional + added a new --xmpp-password option to set XMPP password separately (default to the same password as for profile).
Goffi <goffi@goffi.org>
parents:
1402
diff
changeset
|
128 if xmpp_pwd: |
f913b09cd9cc
jp (profile): in "profile create", jid and password arguments are now optional + added a new --xmpp-password option to set XMPP password separately (default to the same password as for profile).
Goffi <goffi@goffi.org>
parents:
1402
diff
changeset
|
129 self.host.bridge.setParam("Password", xmpp_pwd, "Connection", profile_key=self.args.profile) |
817 | 130 self.host.quit() |
657 | 131 |
814 | 132 def run(self): |
133 """Create a new profile""" | |
817 | 134 self.need_loop = True |
135 if self.args.profile in self.host.bridge.getProfilesList(): | |
1596 | 136 log.error("Profile %s already exists." % self.args.profile) |
817 | 137 self.host.quit(1) |
1403
f913b09cd9cc
jp (profile): in "profile create", jid and password arguments are now optional + added a new --xmpp-password option to set XMPP password separately (default to the same password as for profile).
Goffi <goffi@goffi.org>
parents:
1402
diff
changeset
|
138 self.host.bridge.asyncCreateProfile(self.args.profile, self.args.password, callback=self._profile_created, errback=None) |
0 | 139 |
817 | 140 |
1404
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
141 class ProfileModify(base.CommandBase): |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
142 def __init__(self, host): |
1597 | 143 super(ProfileModify, self).__init__(host, 'modify', need_connect=False, help=_('modify an existing profile')) |
1404
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
144 |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
145 def add_parser_options(self): |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
146 self.parser.add_argument('-w', '--password', type=str, default='', help=_('the password of the profile')) |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
147 self.parser.add_argument('-j', '--jid', type=str, help=_('the jid of the profile')) |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
148 self.parser.add_argument('-x', '--xmpp-password', type=str, help=_('the password of the XMPP account'), |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
149 metavar='PASSWORD') |
1596 | 150 self.parser.add_argument('-D', '--default', action='store_true', help=_(u'set as default profile')) |
1404
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
151 |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
152 def _profile_created(self): |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
153 if self.args.jid: |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
154 self.host.bridge.setParam("JabberID", self.args.jid, "Connection" ,profile_key=self.args.profile) |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
155 xmpp_pwd = self.args.password or self.args.xmpp_password |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
156 if xmpp_pwd: |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
157 self.host.bridge.setParam("Password", xmpp_pwd, "Connection", profile_key=self.args.profile) |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
158 self.host.quit() |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
159 |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
160 def connected(self): |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
161 super(ProfileModify, self).connected() |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
162 if self.args.password is not None: |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
163 self.host.bridge.setParam("Password", self.args.password, "General", profile_key=self.host.profile) |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
164 if self.args.jid is not None: |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
165 self.host.bridge.setParam("JabberID", self.args.jid, "Connection", profile_key=self.host.profile) |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
166 if self.args.xmpp_password is not None: |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
167 self.host.bridge.setParam("Password", self.args.xmpp_password, "Connection", profile_key=self.host.profile) |
1596 | 168 if self.args.default: |
169 self.host.bridge.profileSetDefault(self.host.profile) | |
1404
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
170 |
e4e960d285b0
jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents:
1403
diff
changeset
|
171 |
817 | 172 class Profile(base.CommandBase): |
1597 | 173 subcommands = (ProfileConnect, ProfileCreate, ProfileDefault, ProfileDelete, ProfileInfo, ProfileList, ProfileModify) |
817 | 174 |
175 def __init__(self, host): | |
176 super(Profile, self).__init__(host, 'profile', use_profile=False, help=_('Profile commands')) |