comparison frontends/src/jp/cmd_identity.py @ 2254:6297817c3dc9

jp (identity): new identity command to handle the new plugin identity in backend, and maybe other plugins like vcard in the future
author Goffi <goffi@goffi.org>
date Sun, 21 May 2017 20:06:07 +0200
parents
children 8b37a62336c3
comparison
equal deleted inserted replaced
2253:db468f24b9fc 2254:6297817c3dc9
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3
4 # jp: a SàT command line tool
5 # Copyright (C) 2009-2016 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
20
21 import base
22 from sat.core.i18n import _
23 from sat_frontends.jp.constants import Const as C
24 from functools import partial
25
26 __commands__ = ["Identity"]
27
28 # TODO: move date parsing to base, it may be useful for other commands
29
30
31 class Get(base.CommandBase):
32
33 def __init__(self, host):
34 base.CommandBase.__init__(self,
35 host,
36 'get',
37 use_output=C.OUTPUT_DICT,
38 use_verbose=True,
39 help=_(u'get identity data'))
40 self.need_loop=True
41
42 def add_parser_options(self):
43 self.parser.add_argument("jid", type=base.unicode_decoder, help=_(u"entity to check"))
44
45 def identityGetCb(self, data):
46 self.output(data)
47 self.host.quit()
48
49 def start(self):
50 jid_ = self.host.check_jids([self.args.jid])[0]
51 self.host.bridge.identityGet(
52 jid_,
53 self.profile,
54 callback=self.identityGetCb,
55 errback=partial(self.errback,
56 msg=_(u"can't get identity data: {}"),
57 exit_code=C.EXIT_BRIDGE_ERRBACK))
58
59
60 class Set(base.CommandBase):
61 def __init__(self, host):
62 super(Set, self).__init__(host, 'set', help=_('modify an existing event'))
63
64 def add_parser_options(self):
65 self.parser.add_argument("-f", "--field", type=base.unicode_decoder, action='append', nargs=2, dest='fields',
66 metavar=(u"KEY", u"VALUE"), required=True, help=_(u"identity field(s) to set"))
67 self.need_loop=True
68
69 def start(self):
70 fields = dict(self.args.fields)
71 self.host.bridge.identitySet(
72 fields,
73 self.profile,
74 callback=self.host.quit,
75 errback=partial(self.errback,
76 msg=_(u"can't set identity data data: {}"),
77 exit_code=C.EXIT_BRIDGE_ERRBACK))
78
79
80 class Identity(base.CommandBase):
81 subcommands = (Get, Set)
82
83 def __init__(self, host):
84 super(Identity, self).__init__(host, 'identity', use_profile=False, help=_('identity management'))