comparison sat_frontends/jp/cmd_identity.py @ 2562:26edcf3a30eb

core, setup: huge cleaning: - moved directories from src and frontends/src to sat and sat_frontends, which is the recommanded naming convention - move twisted directory to root - removed all hacks from setup.py, and added missing dependencies, it is now clean - use https URL for website in setup.py - removed "Environment :: X11 Applications :: GTK", as wix is deprecated and removed - renamed sat.sh to sat and fixed its installation - added python_requires to specify Python version needed - replaced glib2reactor which use deprecated code by gtk3reactor sat can now be installed directly from virtualenv without using --system-site-packages anymore \o/
author Goffi <goffi@goffi.org>
date Mon, 02 Apr 2018 19:44:50 +0200
parents frontends/src/jp/cmd_identity.py@0046283a285d
children 56f94936df1e
comparison
equal deleted inserted replaced
2561:bd30dc3ffe5a 2562:26edcf3a30eb
1 #!/usr/bin/env python2
2 # -*- coding: utf-8 -*-
3
4 # jp: a SàT command line tool
5 # Copyright (C) 2009-2018 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'))