annotate 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
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # jp: a SàT command line tool
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
6
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
7 # This program is free software: you can redistribute it and/or modify
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
8 # it under the terms of the GNU Affero General Public License as published by
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
9 # the Free Software Foundation, either version 3 of the License, or
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
10 # (at your option) any later version.
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
11
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
12 # This program is distributed in the hope that it will be useful,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
15 # GNU Affero General Public License for more details.
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
16
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
17 # You should have received a copy of the GNU Affero General Public License
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
18 # along with this program. If not, see <http://www.gnu.org/licenses/>.
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
19
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
20
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import base
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core.i18n import _
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat_frontends.jp.constants import Const as C
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from functools import partial
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 __commands__ = ["Event"]
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 class Get(base.CommandBase):
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31 def __init__(self, host):
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 base.CommandBase.__init__(self,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33 host,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 'get',
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 use_output=C.OUTPUT_DICT,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36 use_pubsub_node_req=True,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 use_verbose=True,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 help=_(u'get event attendance'))
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 self.need_loop=True
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
41 def add_parser_options(self):
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
42 pass
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
43
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 def eventGetCb(self, event_data):
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 self.output(event_data)
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
46 self.host.quit()
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 def start(self):
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 self.host.bridge.eventGet(
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
50 self.args.service,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
51 self.args.node,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
52 self.profile,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
53 callback=self.eventGetCb,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
54 errback=partial(self.errback,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
55 msg=_(u"can't get event data: {}"),
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56 exit_code=C.EXIT_BRIDGE_ERRBACK))
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 class Set(base.CommandBase):
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 def __init__(self, host):
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 super(Set, self).__init__(host, 'set', use_output=C.OUTPUT_DICT, use_pubsub_node_req=True, help=_('set event attendance'))
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62 self.need_loop=True
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 def add_parser_options(self):
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 self.parser.add_argument("-f", "--field", type=base.unicode_decoder, action='append', nargs=2, dest='fields',
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 metavar=(u"KEY", u"VALUE"), help=_(u"configuration field to set"))
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 def start(self):
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 fields = dict(self.args.fields) if self.args.fields else {}
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self.host.bridge.eventSet(
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.args.service,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 self.args.node,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 fields,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self.profile,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 callback=self.host.quit,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76 errback=partial(self.errback,
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
77 msg=_(u"can't set event data: {}"),
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
78 exit_code=C.EXIT_BRIDGE_ERRBACK))
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
79
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
80
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81 class Event(base.CommandBase):
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 subcommands = (Get, Set)
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 def __init__(self, host):
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 super(Event, self).__init__(host, 'event', use_profile=False, help=_('event management'))