Mercurial > libervia-backend
annotate frontends/src/jp/cmd_profile.py @ 853:c2f6ada7858f
core (sqlite): automatic database update:
- new Updater class check database consistency (by calculating a hash on the .schema), and updates base if necessary
- database now has a version (1 for current, 0 will be for 0.3's database), for each change this version will be increased
- creation statements and update statements are in the form of dict of dict with tuples. There is a help text at the top of the module to explain how it works
- if we are on a development version, the updater try to update the database automaticaly (without deleting table or columns). The Updater.generateUpdateData method can be used to ease the creation of update data (i.e. the dictionary at the top, see the one for the key 1 for an example).
- if there is an inconsistency, an exception is raised, and a message indicate the SQL statements that should fix the situation.
- well... this is rather complicated, a KISS method would maybe have been better. The future will say if we need to simplify it :-/
- new DatabaseError exception
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 23 Feb 2014 23:30:32 +0100 |
parents | c39117d00f35 |
children | 308a96bc7c1b |
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 from logging import debug, info, error, warning |
771 | 24 from sat.core.i18n import _ |
817 | 25 from sat_frontends.jp import base |
26 from sat.tools.jid import JID | |
402
f03688bdb858
jp: use with statement to open fifo
Goffi <goffi@goffi.org>
parents:
401
diff
changeset
|
27 |
817 | 28 __commands__ = ["Profile"] |
29 | |
30 PROFILE_HELP = _('The name of the profile') | |
0 | 31 |
32 | |
817 | 33 class ProfileDelete(base.CommandBase): |
34 def __init__(self, host): | |
35 super(ProfileDelete, self).__init__(host, 'delete', use_profile=False, help=_('Delete a profile')) | |
36 | |
37 def add_parser_options(self): | |
38 self.parser.add_argument('profile', type=str, help=PROFILE_HELP) | |
0 | 39 |
814 | 40 def run(self): |
817 | 41 super(ProfileDelete, self).run() |
42 if self.args.profile not in self.host.bridge.getProfilesList(): | |
43 error("Profile %s doesn't exist." % self.args.profile) | |
44 self.host.quit(1) | |
45 self.host.bridge.deleteProfile(self.args.profile) | |
46 | |
0 | 47 |
817 | 48 class ProfileInfo(base.CommandBase): |
49 def __init__(self, host): | |
50 super(ProfileInfo, self).__init__(host, 'info', use_profile=False, help=_('Get informations about a profile')) | |
0 | 51 |
817 | 52 def add_parser_options(self): |
53 self.parser.add_argument('profile', type=str, help=PROFILE_HELP) | |
0 | 54 |
814 | 55 def run(self): |
817 | 56 super(ProfileInfo, self).run() |
57 self.need_loop = True | |
58 | |
814 | 59 def getPassword(password): |
817 | 60 print "pwd: %s" % password |
61 self.host.quit() | |
814 | 62 |
817 | 63 def getJID(jid): |
64 print "jid: %s" % jid | |
65 self.host.bridge.asyncGetParamA("Password", "Connection", profile_key=self.args.profile, callback=getPassword) | |
814 | 66 |
817 | 67 if self.args.profile not in self.host.bridge.getProfilesList(): |
68 error("Profile %s doesn't exist." % self.args.profile) | |
69 self.host.quit(1) | |
814 | 70 |
817 | 71 self.host.bridge.asyncGetParamA("JabberID", "Connection", profile_key=self.args.profile, callback=getJID) |
72 | |
73 | |
74 class ProfileList(base.CommandBase): | |
75 def __init__(self, host): | |
76 super(ProfileList, self).__init__(host, 'list', use_profile=False, help=_('List profiles')) | |
657 | 77 |
817 | 78 def add_parser_options(self): |
79 pass | |
80 | |
81 def run(self): | |
82 super(ProfileList, self).run() | |
83 for profile in self.host.bridge.getProfilesList(): | |
84 print profile | |
85 | |
814 | 86 |
817 | 87 class ProfileCreate(base.CommandBase): |
88 def __init__(self, host): | |
89 super(ProfileCreate, self).__init__(host, 'create', use_profile=False, help=_('Create a new profile')) | |
657 | 90 |
817 | 91 def add_parser_options(self): |
92 self.parser.add_argument('profile', type=str, help=_('the name of the profile')) | |
93 self.parser.add_argument('jid', type=str, help=_('the jid of the profile')) | |
94 self.parser.add_argument('password', type=str, help=_('the password of the profile')) | |
95 | |
96 def _profile_created(self): | |
97 self.host.bridge.setParam("JabberID", self.args.jid, "Connection" ,profile_key=self.args.profile) | |
98 self.host.bridge.setParam("Server", JID(self.args.jid).domain, "Connection", profile_key=self.args.profile) | |
99 self.host.bridge.setParam("Password", self.args.password, "Connection", profile_key=self.args.profile) | |
100 self.host.quit() | |
657 | 101 |
814 | 102 def run(self): |
103 """Create a new profile""" | |
817 | 104 self.need_loop = True |
105 if self.args.profile in self.host.bridge.getProfilesList(): | |
106 error("Profile %s already exists." % self.args.profile) | |
107 self.host.quit(1) | |
108 self.host.bridge.asyncCreateProfile(self.args.profile, self._profile_created, None) | |
0 | 109 |
817 | 110 |
111 class Profile(base.CommandBase): | |
112 subcommands = (ProfileDelete, ProfileInfo, ProfileList, ProfileCreate) | |
113 | |
114 def __init__(self, host): | |
115 super(Profile, self).__init__(host, 'profile', use_profile=False, help=_('Profile commands')) |