annotate frontends/src/jp/cmd_profile.py @ 2342:f047d5410040

core (memory/disco): added use_cache parameter to discoInfos/discoItems (set to False to ignore cache)
author Goffi <goffi@goffi.org>
date Tue, 22 Aug 2017 22:12:57 +0200
parents a7438fe4e24d
children 8b37a62336c3
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
1960
3e168cde7a7d jp: fixed shebang python call
Goffi <goffi@goffi.org>
parents: 1864
diff changeset
1 #!/usr/bin/env python2
815
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
2 # -*- coding: utf-8 -*-
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
3
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
4 # jp: a SAT command line tool
1766
d17772b0fe22 copyright update
Goffi <goffi@goffi.org>
parents: 1702
diff changeset
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
815
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
6
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
7 # This program is free software: you can redistribute it and/or modify
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
10 # (at your option) any later version.
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
11
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
12 # This program is distributed in the hope that it will be useful,
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
15 # GNU Affero General Public License for more details.
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
16
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
f8d534ed1d1e jp: added missing license headers
Goffi <goffi@goffi.org>
parents: 814
diff changeset
19
814
59c7bc51c323 jp: refactoring using ArgParse
Dal <kedals0@gmail.com>
parents: 811
diff changeset
20 """This module permits to manage profiles. It can list, create, delete
1199
96fb74a4714d misc: fixed some typos
Matteo Cypriani <mcy@lm7.fr>
parents: 1139
diff changeset
21 and retrieve information about a profile."""
0
goffi@necton2
parents:
diff changeset
22
2164
63d191c05ecd jp (blog): set default template and data mapping for the new template output
Goffi <goffi@goffi.org>
parents: 2146
diff changeset
23 from sat.core.log import getLogger
63d191c05ecd jp (blog): set default template and data mapping for the new template output
Goffi <goffi@goffi.org>
parents: 2146
diff changeset
24 log = getLogger(__name__)
771
bfabeedbf32e core: i18n refactoring:
Goffi <goffi@goffi.org>
parents: 721
diff changeset
25 from sat.core.i18n import _
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
26 from sat_frontends.jp import base
402
f03688bdb858 jp: use with statement to open fifo
Goffi <goffi@goffi.org>
parents: 401
diff changeset
27
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
28 __commands__ = ["Profile"]
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
29
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
30 PROFILE_HELP = _('The name of the profile')
0
goffi@necton2
parents:
diff changeset
31
goffi@necton2
parents:
diff changeset
32
1597
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
33 class ProfileConnect(base.CommandBase):
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
34 """Dummy command to use profile_session parent, i.e. to be able to connect without doing anything else"""
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
35
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
36 def __init__(self, host):
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
37 # it's weird to have a command named "connect" with need_connect=False, but it can be handy to be able
2336
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
38 # to launch just the session, so some paradoxes don't hurt
2146
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
39 super(ProfileConnect, self).__init__(host, 'connect', need_connect=False, help=(u'connect a profile'))
1597
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
40
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
41 def add_parser_options(self):
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
42 pass
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
43
91a605feed8c jp: added profile/connect command
Goffi <goffi@goffi.org>
parents: 1596
diff changeset
44
2336
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
45 class ProfileDisconnect(base.CommandBase):
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
46
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
47 def __init__(self, host):
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
48 super(ProfileDisconnect, self).__init__(host, 'disconnect', need_connect=False, help=(u'disconnect a profile'))
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
49 self.need_loop = True
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
50
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
51 def add_parser_options(self):
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
52 pass
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
53
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
54 def start(self):
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
55 self.host.bridge.disconnect(self.args.profile, callback=self.host.quit)
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
56
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
57
1596
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
58 class ProfileDefault(base.CommandBase):
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
59 def __init__(self, host):
2146
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
60 super(ProfileDefault, self).__init__(host, 'default', use_profile=False, help=(u'print default profile'))
1596
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
61
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
62 def add_parser_options(self):
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
63 pass
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
64
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1861
diff changeset
65 def start(self):
2168
255830fdb80b core, bridge: renamed getProfileName to profileNameGet according to new conventions
Goffi <goffi@goffi.org>
parents: 2164
diff changeset
66 print self.host.bridge.profileNameGet('@DEFAULT@')
1596
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
67
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
68
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
69 class ProfileDelete(base.CommandBase):
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
70 def __init__(self, host):
2146
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
71 super(ProfileDelete, self).__init__(host, 'delete', use_profile=False, help=(u'delete a profile'))
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
72
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
73 def add_parser_options(self):
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
74 self.parser.add_argument('profile', type=str, help=PROFILE_HELP)
1861
3b2a236fa743 jp (profile): added confirmation and --force arguement to profile/delete
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
75 self.parser.add_argument('-f', '--force', action='store_true', help=_(u'delete profile without confirmation'))
0
goffi@necton2
parents:
diff changeset
76
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1861
diff changeset
77 def start(self):
2146
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
78 if self.args.profile not in self.host.bridge.profilesListGet():
1596
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
79 log.error("Profile %s doesn't exist." % self.args.profile)
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
80 self.host.quit(1)
1861
3b2a236fa743 jp (profile): added confirmation and --force arguement to profile/delete
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
81 if not self.args.force:
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2179
diff changeset
82 message = u"Are you sure to delete profile [{}] ?".format(self.args.profile)
1861
3b2a236fa743 jp (profile): added confirmation and --force arguement to profile/delete
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
83 res = raw_input("{} (y/N)? ".format(message))
3b2a236fa743 jp (profile): added confirmation and --force arguement to profile/delete
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
84 if res not in ("y", "Y"):
3b2a236fa743 jp (profile): added confirmation and --force arguement to profile/delete
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
85 self.disp(_(u"Profile deletion cancelled"))
3b2a236fa743 jp (profile): added confirmation and --force arguement to profile/delete
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
86 self.host.quit(2)
3b2a236fa743 jp (profile): added confirmation and --force arguement to profile/delete
Goffi <goffi@goffi.org>
parents: 1766
diff changeset
87
893
308a96bc7c1b core, frontends: add method asyncDeleteProfile, remove synchronous methods createProfile and deleteProfile
souliane <souliane@mailoo.org>
parents: 817
diff changeset
88 self.host.bridge.asyncDeleteProfile(self.args.profile, callback=lambda dummy: None)
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
89
0
goffi@necton2
parents:
diff changeset
90
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
91 class ProfileInfo(base.CommandBase):
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
92 def __init__(self, host):
2146
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
93 super(ProfileInfo, self).__init__(host, 'info', need_connect=False, help=_(u'get information about a profile'))
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1861
diff changeset
94 self.need_loop = True
1596
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
95 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
96 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
97
0
goffi@necton2
parents:
diff changeset
98
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
99 def add_parser_options(self):
1596
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
100 self.parser.add_argument('--show-password', action='store_true', help=_(u'show the XMPP password IN CLEAR TEXT'))
814
59c7bc51c323 jp: refactoring using ArgParse
Dal <kedals0@gmail.com>
parents: 811
diff changeset
101
1402
391b0c21f4be jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
102 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
103 """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
104 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
105 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
106 try:
391b0c21f4be jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
107 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
108 except IndexError:
391b0c21f4be jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
109 self.host.quit()
391b0c21f4be jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
110 else:
391b0c21f4be jp (profile): fixed "profile info" to use profile, and then manage connection.
Goffi <goffi@goffi.org>
parents: 1396
diff changeset
111 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
112 callback=lambda value: self.showNextValue(label, category, value))
814
59c7bc51c323 jp: refactoring using ArgParse
Dal <kedals0@gmail.com>
parents: 811
diff changeset
113
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1861
diff changeset
114 def start(self):
1596
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
115 if self.args.show_password:
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
116 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
117 self.showNextValue()
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
118
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
119
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
120 class ProfileList(base.CommandBase):
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
121 def __init__(self, host):
2146
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
122 super(ProfileList, self).__init__(host, 'list', use_profile=False, use_output='list', help=(u'list profiles'))
657
09bbd5c00244 jp: profiles management
Dal <kedals0@gmail.com>
parents: 627
diff changeset
123
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
124 def add_parser_options(self):
2146
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
125 group = self.parser.add_mutually_exclusive_group()
2174
0c32ff2f64c4 jp (profile/list): fixed options help
Goffi <goffi@goffi.org>
parents: 2168
diff changeset
126 group.add_argument('-c', '--clients', action='store_true', help=_(u'get clients profiles only'))
0c32ff2f64c4 jp (profile/list): fixed options help
Goffi <goffi@goffi.org>
parents: 2168
diff changeset
127 group.add_argument('-C', '--components', action='store_true', help=(u'get components profiles only'))
2146
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
128
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
129
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1861
diff changeset
130 def start(self):
2146
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
131 if self.args.clients:
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
132 clients, components = True, False
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
133 elif self.args.components:
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
134 clients, components = False, True
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
135 else:
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
136 clients, components = True, True
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
137 self.output(self.host.bridge.profilesListGet(clients, components))
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
138
814
59c7bc51c323 jp: refactoring using ArgParse
Dal <kedals0@gmail.com>
parents: 811
diff changeset
139
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
140 class ProfileCreate(base.CommandBase):
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
141 def __init__(self, host):
2146
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
142 super(ProfileCreate, self).__init__(host, 'create', use_profile=False, help=(u'create a new profile'))
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1861
diff changeset
143 self.need_loop = True
657
09bbd5c00244 jp: profiles management
Dal <kedals0@gmail.com>
parents: 627
diff changeset
144
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
145 def add_parser_options(self):
2179
e42c6c131b52 jp (profile): fixed help gettext calls
Goffi <goffi@goffi.org>
parents: 2174
diff changeset
146 self.parser.add_argument('profile', type=str, help=_(u'the name of the profile'))
e42c6c131b52 jp (profile): fixed help gettext calls
Goffi <goffi@goffi.org>
parents: 2174
diff changeset
147 self.parser.add_argument('-p', '--password', type=str, default='', help=_(u'the password of the profile'))
e42c6c131b52 jp (profile): fixed help gettext calls
Goffi <goffi@goffi.org>
parents: 2174
diff changeset
148 self.parser.add_argument('-j', '--jid', type=str, help=_(u'the jid of the profile'))
e42c6c131b52 jp (profile): fixed help gettext calls
Goffi <goffi@goffi.org>
parents: 2174
diff changeset
149 self.parser.add_argument('-x', '--xmpp-password', type=str, help=_(u'the password of the XMPP account (use profile password if not specified)'),
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
150 metavar='PASSWORD')
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1969
diff changeset
151 self.parser.add_argument('-C', '--component', type=base.unicode_decoder, default='',
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1969
diff changeset
152 help=_(u'set to component import name (entry point) if this is a component'))
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
153
1702
bc7e3ff3c838 jp (profile): fixed creating profile with given JID and XMPP password
souliane <souliane@mailoo.org>
parents: 1687
diff changeset
154 def _session_started(self, dummy):
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
155 if self.args.jid:
2179
e42c6c131b52 jp (profile): fixed help gettext calls
Goffi <goffi@goffi.org>
parents: 2174
diff changeset
156 self.host.bridge.setParam("JabberID", self.args.jid, "Connection", profile_key=self.args.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
157 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
158 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
159 self.host.bridge.setParam("Password", xmpp_pwd, "Connection", profile_key=self.args.profile)
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
160 self.host.quit()
657
09bbd5c00244 jp: profiles management
Dal <kedals0@gmail.com>
parents: 627
diff changeset
161
1702
bc7e3ff3c838 jp (profile): fixed creating profile with given JID and XMPP password
souliane <souliane@mailoo.org>
parents: 1687
diff changeset
162 def _profile_created(self):
bc7e3ff3c838 jp (profile): fixed creating profile with given JID and XMPP password
souliane <souliane@mailoo.org>
parents: 1687
diff changeset
163 self.host.bridge.profileStartSession(self.args.password, self.args.profile, callback=self._session_started, errback=None)
bc7e3ff3c838 jp (profile): fixed creating profile with given JID and XMPP password
souliane <souliane@mailoo.org>
parents: 1687
diff changeset
164
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1861
diff changeset
165 def start(self):
814
59c7bc51c323 jp: refactoring using ArgParse
Dal <kedals0@gmail.com>
parents: 811
diff changeset
166 """Create a new profile"""
2146
1bb9bf1b4150 core, frontends: getProfilesList renamed to profilesGetList + behaviour change:
Goffi <goffi@goffi.org>
parents: 2144
diff changeset
167 if self.args.profile in self.host.bridge.profilesListGet():
1596
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
168 log.error("Profile %s already exists." % self.args.profile)
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
169 self.host.quit(1)
2144
1d3f73e065e1 core, jp: component handling + client handling refactoring:
Goffi <goffi@goffi.org>
parents: 1969
diff changeset
170 self.host.bridge.profileCreate(self.args.profile, self.args.password, self.args.component, callback=self._profile_created, errback=None)
0
goffi@necton2
parents:
diff changeset
171
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
172
1404
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
173 class ProfileModify(base.CommandBase):
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
174 def __init__(self, host):
2179
e42c6c131b52 jp (profile): fixed help gettext calls
Goffi <goffi@goffi.org>
parents: 2174
diff changeset
175 super(ProfileModify, self).__init__(host, 'modify', need_connect=False, help=_(u'modify an existing profile'))
1404
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
176
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
177 def add_parser_options(self):
1687
de9cc4d62a4a jp (profile): fixed profile/modify command:
Goffi <goffi@goffi.org>
parents: 1597
diff changeset
178 profile_pwd_group = self.parser.add_mutually_exclusive_group()
2179
e42c6c131b52 jp (profile): fixed help gettext calls
Goffi <goffi@goffi.org>
parents: 2174
diff changeset
179 profile_pwd_group.add_argument('-w', '--password', type=base.unicode_decoder, help=_(u'change the password of the profile'))
e42c6c131b52 jp (profile): fixed help gettext calls
Goffi <goffi@goffi.org>
parents: 2174
diff changeset
180 profile_pwd_group.add_argument('--disable-password', action='store_true', help=_(u'disable profile password (dangerous!)'))
e42c6c131b52 jp (profile): fixed help gettext calls
Goffi <goffi@goffi.org>
parents: 2174
diff changeset
181 self.parser.add_argument('-j', '--jid', type=base.unicode_decoder, help=_(u'the jid of the profile'))
e42c6c131b52 jp (profile): fixed help gettext calls
Goffi <goffi@goffi.org>
parents: 2174
diff changeset
182 self.parser.add_argument('-x', '--xmpp-password', type=base.unicode_decoder, help=_(u'change the password of the XMPP account'),
1404
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
183 metavar='PASSWORD')
1596
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
184 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
185
1864
96ba685162f6 jp: all commands now use the new start method and set need_loop in __init__ when needed
Goffi <goffi@goffi.org>
parents: 1861
diff changeset
186 def start(self):
1687
de9cc4d62a4a jp (profile): fixed profile/modify command:
Goffi <goffi@goffi.org>
parents: 1597
diff changeset
187 if self.args.disable_password:
de9cc4d62a4a jp (profile): fixed profile/modify command:
Goffi <goffi@goffi.org>
parents: 1597
diff changeset
188 self.args.password = ''
1404
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
189 if self.args.password is not None:
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
190 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
191 if self.args.jid is not None:
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
192 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
193 if self.args.xmpp_password is not None:
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
194 self.host.bridge.setParam("Password", self.args.xmpp_password, "Connection", profile_key=self.host.profile)
1596
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
195 if self.args.default:
b7ee113183fc jp: better profile commands:
Goffi <goffi@goffi.org>
parents: 1404
diff changeset
196 self.host.bridge.profileSetDefault(self.host.profile)
1404
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
197
e4e960d285b0 jp (profile): added "profile modify" command
Goffi <goffi@goffi.org>
parents: 1403
diff changeset
198
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
199 class Profile(base.CommandBase):
2336
a7438fe4e24d jp (profile): added disconnect command
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
200 subcommands = (ProfileConnect, ProfileDisconnect, ProfileCreate, ProfileDefault, ProfileDelete, ProfileInfo, ProfileList, ProfileModify)
817
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
201
c39117d00f35 jp: refactoring:
Goffi <goffi@goffi.org>
parents: 815
diff changeset
202 def __init__(self, host):
2179
e42c6c131b52 jp (profile): fixed help gettext calls
Goffi <goffi@goffi.org>
parents: 2174
diff changeset
203 super(Profile, self).__init__(host, 'profile', use_profile=False, help=_(u'profile commands'))