comparison frontends/src/jp/cmd_event.py @ 2236:4b1873ce6b61

jp (event): event handling commands, first draft
author Goffi <goffi@goffi.org>
date Thu, 27 Apr 2017 01:02:05 +0200
parents
children 9d49e66bdbf2
comparison
equal deleted inserted replaced
2235:4db836386641 2236:4b1873ce6b61
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__ = ["Event"]
27
28
29 class Get(base.CommandBase):
30
31 def __init__(self, host):
32 base.CommandBase.__init__(self,
33 host,
34 'get',
35 use_output=C.OUTPUT_DICT,
36 use_pubsub_node_req=True,
37 use_verbose=True,
38 help=_(u'get event attendance'))
39 self.need_loop=True
40
41 def add_parser_options(self):
42 pass
43
44 def eventGetCb(self, event_data):
45 self.output(event_data)
46 self.host.quit()
47
48 def start(self):
49 self.host.bridge.eventGet(
50 self.args.service,
51 self.args.node,
52 self.profile,
53 callback=self.eventGetCb,
54 errback=partial(self.errback,
55 msg=_(u"can't get event data: {}"),
56 exit_code=C.EXIT_BRIDGE_ERRBACK))
57
58
59 class Set(base.CommandBase):
60 def __init__(self, host):
61 super(Set, self).__init__(host, 'set', use_output=C.OUTPUT_DICT, use_pubsub_node_req=True, help=_('set event attendance'))
62 self.need_loop=True
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"), help=_(u"configuration field to set"))
67
68 def start(self):
69 fields = dict(self.args.fields) if self.args.fields else {}
70 self.host.bridge.eventSet(
71 self.args.service,
72 self.args.node,
73 fields,
74 self.profile,
75 callback=self.host.quit,
76 errback=partial(self.errback,
77 msg=_(u"can't set event data: {}"),
78 exit_code=C.EXIT_BRIDGE_ERRBACK))
79
80
81 class Event(base.CommandBase):
82 subcommands = (Get, Set)
83
84 def __init__(self, host):
85 super(Event, self).__init__(host, 'event', use_profile=False, help=_('event management'))