Mercurial > libervia-backend
annotate frontends/src/jp/profile.py @ 815:f8d534ed1d1e
jp: added missing license headers
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 05 Feb 2014 14:52:38 +0100 |
parents | 59c7bc51c323 |
children |
rev | line source |
---|---|
815 | 1 #! /usr/bin/python |
2 # -*- coding: utf-8 -*- | |
3 | |
4 # jp: a SAT command line tool | |
5 # Copyright (C) 2009, 2010, 2011, 2012, 2013, 2014 Jérôme Poisson (goffi@goffi.org) | |
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 |
21 and retrieve informations about a profile.""" | |
0 | 22 |
814 | 23 import base |
24 import sys | |
0 | 25 |
814 | 26 from logging import debug, info, error, warning |
771 | 27 from sat.core.i18n import _ |
402
f03688bdb858
jp: use with statement to open fifo
Goffi <goffi@goffi.org>
parents:
401
diff
changeset
|
28 |
814 | 29 profile_parser = base.subparser.add_parser('profile', |
30 help = "Profile Commands") | |
31 profile_subparser = profile_parser.add_subparsers() | |
0 | 32 |
814 | 33 ################################################################################ |
34 # DELETE # | |
35 ################################################################################ | |
36 profile_delete = profile_subparser.add_parser('delete', | |
37 help = "Delete a profile") | |
38 profile_delete.add_argument('profile', type=str, | |
39 help='the name of the profile') | |
40 profile_delete.set_defaults( | |
41 func = lambda args : ProfileDelete(args.profile).go()) | |
0 | 42 |
814 | 43 class ProfileDelete(base.JP): |
44 def __init__(self, profile_name): | |
45 base.JP.__init__(self) | |
46 self.profile_name = profile_name | |
0 | 47 |
814 | 48 def run(self): |
49 if self.profile_name not in self.bridge.getProfilesList(): | |
50 error("Profile %s doesn't exist."%self.profile_name) | |
51 exit(1) | |
52 self.bridge.deleteProfile(self.profile_name) | |
0 | 53 |
814 | 54 ################################################################################ |
55 # INFO # | |
56 ################################################################################ | |
57 profile_info = profile_subparser.add_parser('info', | |
58 help = "Get informations about a profile") | |
59 profile_info.add_argument('profile', type=str, | |
60 help='the name of the profile') | |
61 profile_info.set_defaults( | |
62 func = lambda args : ProfileInfo(args.profile).go()) | |
0 | 63 |
814 | 64 class ProfileInfo(base.JP): |
65 def __init__(self, profile_name): | |
66 base.JP.__init__(self) | |
67 self.profile_name = profile_name | |
0 | 68 |
814 | 69 def run(self): |
70 def getJID(jid): | |
657 | 71 info("jid: %s"%jid) |
814 | 72 self.bridge.asyncGetParamA("Password", "Connection", profile_key=self.profile_name, callback=getPassword) |
73 def getPassword(password): | |
657 | 74 info("pwd: %s"%password) |
75 self.loop.quit() | |
814 | 76 if self.profile_name not in self.bridge.getProfilesList(): |
77 error("Profile %s doesn't exist."%self.profile_name) | |
657 | 78 exit(1) |
814 | 79 |
80 self.start_mainloop() | |
81 self.bridge.asyncGetParamA("JabberID", "Connection", profile_key=self.profile_name, callback=getJID) | |
82 | |
83 ################################################################################ | |
84 # LIST # | |
85 ################################################################################ | |
86 profile_list = profile_subparser.add_parser('list', | |
87 help = "List profiles") | |
88 profile_list.set_defaults( | |
89 func = lambda args : ProfileList().go()) | |
90 | |
91 class ProfileList(base.JP): | |
92 def run(self): | |
93 for p in self.bridge.getProfilesList(): | |
94 info(p) | |
657 | 95 |
814 | 96 ################################################################################ |
97 # CREATE # | |
98 ################################################################################ | |
99 create_parser = profile_subparser.add_parser('create', | |
100 help = "Create a new profile") | |
101 create_parser.add_argument('profile', type=str, | |
102 help='the name of the profile') | |
103 create_parser.add_argument('jid', type=str, | |
104 help='the jid of the profile') | |
105 create_parser.add_argument('password', type=str, | |
106 help='the password of the profile') | |
107 create_parser.set_defaults( | |
108 func = lambda args : ProfileCreate(args.profile, args.jid, args.password).go()) | |
109 | |
110 class ProfileCreate(base.JP): | |
111 def __init__(self, profile_name, jid, password): | |
112 base.JP.__init__(self) | |
113 self.profile_name = profile_name | |
114 self.jid = jid | |
115 self.password = password | |
657 | 116 |
117 def _create_profile(self, profile_name, jid, password): | |
118 self.bridge.setParam("JabberID", jid, "Connection" ,profile_key=profile_name) | |
814 | 119 self.bridge.setParam("Server", base.JID(jid).domain, "Connection", profile_key=profile_name) |
657 | 120 self.bridge.setParam("Password", password, "Connection", profile_key=profile_name) |
121 self.loop.quit() | |
122 | |
814 | 123 def run(self): |
124 """Create a new profile""" | |
125 if self.profile_name in self.bridge.getProfilesList(): | |
126 error("Profile %s already exists."%self.profile_name) | |
0 | 127 exit(1) |
814 | 128 self.start_mainloop() |
129 self.bridge.asyncCreateProfile(self.profile_name, lambda : self._create_profile(self.profile_name, self.jid, self.password), None) | |
0 | 130 |