Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_event.py @ 3101:ab7e8ade848a
plugin XEP-0045: added room statuses to metadata:
room statuses are now sent with other metadata on bridge signals, and saved in Room
instance. They give useful data on the room, for instance they can be used to know if a
full jid is used in this room.
author | Goffi <goffi@goffi.org> |
---|---|
date | Mon, 30 Dec 2019 20:44:02 +0100 |
parents | fee60f17ebac |
children | 040ca99e25fe |
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 |
2771 | 5 # Copyright (C) 2009-2019 Jérôme Poisson (goffi@goffi.org) |
2236
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 |
3028 | 21 from . import base |
2236
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
22 from sat.core.i18n import _ |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
23 from sat.tools.common.ansi import ANSI as A |
2236
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
24 from sat_frontends.jp.constants import Const as C |
2284
4fd010f29f99
jp (blog, event): added checkURI to some command to be able to enter a xmpp: uri as argument
Goffi <goffi@goffi.org>
parents:
2283
diff
changeset
|
25 from sat_frontends.jp import common |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
26 from dateutil import parser as du_parser |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
27 import calendar |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
28 import time |
2236
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 |
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 __commands__ = ["Event"] |
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 |
3028 | 32 OUTPUT_OPT_TABLE = "table" |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
33 |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
34 # TODO: move date parsing to base, it may be useful for other commands |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
35 |
2236
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 |
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
37 class Get(base.CommandBase): |
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
39 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
40 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
41 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
42 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
43 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
44 use_pubsub=True, |
2910
b2f323237fce
jp, plugin merge-requests: used u'' as default for item id in pubsub arguments + fixed some required arguments:
Goffi <goffi@goffi.org>
parents:
2771
diff
changeset
|
45 pubsub_flags={C.SINGLE_ITEM}, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
46 use_verbose=True, |
3028 | 47 help=_("get event data"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
48 ) |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
49 |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
50 def add_parser_options(self): |
2532 | 51 pass |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
52 |
3040 | 53 async def start(self): |
54 try: | |
55 event_tuple = await self.host.bridge.eventGet( | |
56 self.args.service, | |
57 self.args.node, | |
58 self.args.item, | |
59 self.profile, | |
60 ) | |
61 except Exception as e: | |
62 self.disp(f"can't get event data: {e}", error=True) | |
63 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
64 else: | |
65 event_date, event_data = event_tuple | |
66 event_data["date"] = event_date | |
67 await self.output(event_data) | |
68 self.host.quit() | |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
69 |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
70 |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
71 class EventBase(object): |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
72 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
73 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
74 "-i", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
75 "--id", |
3028 | 76 default="", |
77 help=_("ID of the PubSub Item"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
78 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
79 self.parser.add_argument( |
3028 | 80 "-d", "--date", type=str, help=_("date of the event") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
81 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
82 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
83 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
84 "--field", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
85 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
86 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
87 dest="fields", |
3028 | 88 metavar=("KEY", "VALUE"), |
89 help=_("configuration field to set"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
90 ) |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
91 |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
92 def parseFields(self): |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
93 return dict(self.args.fields) if self.args.fields else {} |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
94 |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
95 def parseDate(self): |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
96 if self.args.date: |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
97 try: |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
98 date = int(self.args.date) |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
99 except ValueError: |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
100 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
101 date_time = du_parser.parse( |
3028 | 102 self.args.date, dayfirst=not ("-" in self.args.date) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
103 ) |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
104 except ValueError as e: |
3028 | 105 self.parser.error(_("Can't parse date: {msg}").format(msg=e)) |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
106 if date_time.tzinfo is None: |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
107 date = calendar.timegm(date_time.timetuple()) |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
108 else: |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
109 date = time.mktime(date_time.timetuple()) |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
110 else: |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
111 date = -1 |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
112 return date |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
113 |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
114 |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
115 class Create(EventBase, base.CommandBase): |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
116 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
117 super(Create, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
118 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
119 "create", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
120 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
121 help=_("create or replace event"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
122 ) |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
123 EventBase.__init__(self) |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
124 |
3040 | 125 async def start(self): |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
126 fields = self.parseFields() |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
127 date = self.parseDate() |
3040 | 128 try: |
129 node = await self.host.bridge.eventCreate( | |
130 date, | |
131 fields, | |
132 self.args.service, | |
133 self.args.node, | |
134 self.args.id, | |
135 self.profile, | |
136 ) | |
137 except Exception as e: | |
138 self.disp(f"can't create event: {e}", error=True) | |
139 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
140 else: | |
141 self.disp(_(f"Event created successfuly on node {node}")) | |
142 self.host.quit() | |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
143 |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
144 |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
145 class Modify(EventBase, base.CommandBase): |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
146 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
147 super(Modify, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
148 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
149 "modify", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
150 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
151 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
152 help=_("modify an existing event"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
153 ) |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
154 EventBase.__init__(self) |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
155 |
3040 | 156 async def start(self): |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
157 fields = self.parseFields() |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
158 date = 0 if not self.args.date else self.parseDate() |
3040 | 159 try: |
160 self.host.bridge.eventModify( | |
161 self.args.service, | |
162 self.args.node, | |
163 self.args.id, | |
164 date, | |
165 fields, | |
166 self.profile, | |
167 ) | |
168 except Exception as e: | |
169 self.disp(f"can't update event data: {e}", error=True) | |
170 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
171 else: | |
172 self.host.quit() | |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
173 |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
174 |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
175 class InviteeGet(base.CommandBase): |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
176 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
177 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
178 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
179 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
180 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
181 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
182 use_pubsub=True, |
3040 | 183 pubsub_flags={C.NODE}, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
184 use_verbose=True, |
3028 | 185 help=_("get event attendance"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
186 ) |
2236
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
187 |
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
188 def add_parser_options(self): |
3040 | 189 self.parser.add_argument( |
190 "-j", "--jid", default="", help=_("bare jid of the invitee") | |
191 ) | |
2236
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
192 |
3040 | 193 async def start(self): |
194 try: | |
195 event_data = await self.host.bridge.eventInviteeGet( | |
196 self.args.service, | |
197 self.args.node, | |
198 self.args.jid, | |
199 self.profile, | |
200 ) | |
201 except Exception as e: | |
202 self.disp(f"can't get event data: {e}", error=True) | |
203 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
204 else: | |
205 await self.output(event_data) | |
206 self.host.quit() | |
2236
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
207 |
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
208 |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
209 class InviteeSet(base.CommandBase): |
2236
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
210 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
211 super(InviteeSet, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
212 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
213 "set", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
214 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
215 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
216 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
217 help=_("set event attendance"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
218 ) |
2236
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 |
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
221 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
222 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
223 "--field", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
224 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
225 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
226 dest="fields", |
3028 | 227 metavar=("KEY", "VALUE"), |
228 help=_("configuration field to set"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
229 ) |
2236
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
230 |
3040 | 231 async def start(self): |
2236
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
232 fields = dict(self.args.fields) if self.args.fields else {} |
3040 | 233 try: |
234 self.host.bridge.eventInviteeSet( | |
235 self.args.service, | |
236 self.args.node, | |
237 fields, | |
238 self.profile, | |
239 ) | |
240 except Exception as e: | |
241 self.disp(f"can't set event data: {e}", error=True) | |
242 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
243 else: | |
244 self.host.quit() | |
2236
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
245 |
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
246 |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
247 class InviteesList(base.CommandBase): |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
248 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
249 extra_outputs = {"default": self.default_output} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
250 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
251 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
252 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
253 "list", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
254 use_output=C.OUTPUT_DICT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
255 extra_outputs=extra_outputs, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
256 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
257 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
258 use_verbose=True, |
3028 | 259 help=_("get event attendance"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
260 ) |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
261 |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
262 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
263 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
264 "-m", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
265 "--missing", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
266 action="store_true", |
3028 | 267 help=_("show missing people (invited but no R.S.V.P. so far)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
268 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
269 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
270 "-R", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
271 "--no-rsvp", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
272 action="store_true", |
3028 | 273 help=_("don't show people which gave R.S.V.P."), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
274 ) |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
275 |
2491
5895e4daae8c
jp (event): added missing arg to _attend_filter
Goffi <goffi@goffi.org>
parents:
2483
diff
changeset
|
276 def _attend_filter(self, attend, row): |
3028 | 277 if attend == "yes": |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
278 attend_color = C.A_SUCCESS |
3028 | 279 elif attend == "no": |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
280 attend_color = C.A_FAILURE |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
281 else: |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
282 attend_color = A.FG_WHITE |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
283 return A.color(attend_color, attend) |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
284 |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
285 def _guests_filter(self, guests): |
3028 | 286 return "(" + str(guests) + ")" if guests else "" |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
287 |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
288 def default_output(self, event_data): |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
289 data = [] |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
290 attendees_yes = 0 |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
291 attendees_maybe = 0 |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
292 attendees_no = 0 |
2321
c2a9da96e40b
jp (event/attendee/list): added --missing to show missing people (ones who didn't replied) and --no-rsvp to hide ones who answered
Goffi <goffi@goffi.org>
parents:
2301
diff
changeset
|
293 attendees_missing = 0 |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
294 guests = 0 |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
295 guests_maybe = 0 |
3028 | 296 for jid_, jid_data in event_data.items(): |
297 jid_data["jid"] = jid_ | |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
298 try: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
299 guests_int = int(jid_data["guests"]) |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
300 except (ValueError, KeyError): |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
301 pass |
3028 | 302 attend = jid_data.get("attend", "") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
303 if attend == "yes": |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
304 attendees_yes += 1 |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
305 guests += guests_int |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
306 elif attend == "maybe": |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
307 attendees_maybe += 1 |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
308 guests_maybe += guests_int |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
309 elif attend == "no": |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
310 attendees_no += 1 |
3028 | 311 jid_data["guests"] = "" |
2321
c2a9da96e40b
jp (event/attendee/list): added --missing to show missing people (ones who didn't replied) and --no-rsvp to hide ones who answered
Goffi <goffi@goffi.org>
parents:
2301
diff
changeset
|
312 else: |
c2a9da96e40b
jp (event/attendee/list): added --missing to show missing people (ones who didn't replied) and --no-rsvp to hide ones who answered
Goffi <goffi@goffi.org>
parents:
2301
diff
changeset
|
313 attendees_missing += 1 |
3028 | 314 jid_data["guests"] = "" |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
315 data.append(jid_data) |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
316 |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
317 show_table = OUTPUT_OPT_TABLE in self.args.output_opts |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
318 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
319 table = common.Table.fromDict( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
320 self.host, |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
321 data, |
3028 | 322 ("nick",) |
323 + (("jid",) if self.host.verbosity else ()) | |
324 + ("attend", "guests"), | |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
325 headers=None, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
326 filters={ |
3028 | 327 "nick": A.color(C.A_HEADER, "{}" if show_table else "{} "), |
328 "jid": "{}" if show_table else "{} ", | |
329 "attend": self._attend_filter, | |
330 "guests": "{}" if show_table else self._guests_filter, | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
331 }, |
3028 | 332 defaults={"nick": "", "attend": "", "guests": 1}, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
333 ) |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
334 if show_table: |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
335 table.display() |
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
336 else: |
3028 | 337 table.display_blank(show_header=False, col_sep="") |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
338 |
2321
c2a9da96e40b
jp (event/attendee/list): added --missing to show missing people (ones who didn't replied) and --no-rsvp to hide ones who answered
Goffi <goffi@goffi.org>
parents:
2301
diff
changeset
|
339 if not self.args.no_rsvp: |
3028 | 340 self.disp("") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
341 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
342 A.color( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
343 C.A_SUBHEADER, |
3028 | 344 _("Attendees: "), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
345 A.RESET, |
3028 | 346 str(len(data)), |
347 _(" ("), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
348 C.A_SUCCESS, |
3028 | 349 _("yes: "), |
350 str(attendees_yes), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
351 A.FG_WHITE, |
3028 | 352 _(", maybe: "), |
353 str(attendees_maybe), | |
354 ", ", | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
355 C.A_FAILURE, |
3028 | 356 _("no: "), |
357 str(attendees_no), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
358 A.RESET, |
3028 | 359 ")", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
360 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
361 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
362 self.disp( |
3028 | 363 A.color(C.A_SUBHEADER, _("confirmed guests: "), A.RESET, str(guests)) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
364 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
365 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
366 A.color( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
367 C.A_SUBHEADER, |
3028 | 368 _("unconfirmed guests: "), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
369 A.RESET, |
3028 | 370 str(guests_maybe), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
371 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
372 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
373 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
374 A.color( |
3028 | 375 C.A_SUBHEADER, _("total: "), A.RESET, str(guests + guests_maybe) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
376 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
377 ) |
2321
c2a9da96e40b
jp (event/attendee/list): added --missing to show missing people (ones who didn't replied) and --no-rsvp to hide ones who answered
Goffi <goffi@goffi.org>
parents:
2301
diff
changeset
|
378 if attendees_missing: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
379 self.disp("") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
380 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
381 A.color( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
382 C.A_SUBHEADER, |
3028 | 383 _("missing people (no reply): "), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
384 A.RESET, |
3028 | 385 str(attendees_missing), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
386 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
387 ) |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
388 |
3040 | 389 async def start(self): |
2321
c2a9da96e40b
jp (event/attendee/list): added --missing to show missing people (ones who didn't replied) and --no-rsvp to hide ones who answered
Goffi <goffi@goffi.org>
parents:
2301
diff
changeset
|
390 if self.args.no_rsvp and not self.args.missing: |
3028 | 391 self.parser.error(_("you need to use --missing if you use --no-rsvp")) |
3040 | 392 if not self.args.missing: |
393 prefilled = {} | |
394 else: | |
395 # we get prefilled data with all people | |
396 try: | |
397 affiliations = await self.host.bridge.psNodeAffiliationsGet( | |
398 self.args.service, | |
399 self.args.node, | |
400 self.profile, | |
401 ) | |
402 except Exception as e: | |
403 self.disp(f"can't get node affiliations: {e}", error=True) | |
404 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
405 else: | |
406 # we fill all affiliations with empty data, answered one will be filled | |
407 # below. We only consider people with "publisher" affiliation as invited, | |
408 # creators are not, and members can just observe | |
409 prefilled = { | |
410 jid_: {} | |
411 for jid_, affiliation in affiliations.items() | |
412 if affiliation in ("publisher",) | |
413 } | |
414 | |
415 try: | |
416 event_data = await self.host.bridge.eventInviteesList( | |
2321
c2a9da96e40b
jp (event/attendee/list): added --missing to show missing people (ones who didn't replied) and --no-rsvp to hide ones who answered
Goffi <goffi@goffi.org>
parents:
2301
diff
changeset
|
417 self.args.service, |
c2a9da96e40b
jp (event/attendee/list): added --missing to show missing people (ones who didn't replied) and --no-rsvp to hide ones who answered
Goffi <goffi@goffi.org>
parents:
2301
diff
changeset
|
418 self.args.node, |
c2a9da96e40b
jp (event/attendee/list): added --missing to show missing people (ones who didn't replied) and --no-rsvp to hide ones who answered
Goffi <goffi@goffi.org>
parents:
2301
diff
changeset
|
419 self.profile, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
420 ) |
3040 | 421 except Exception as e: |
422 self.disp(f"can't get event data: {e}", error=True) | |
423 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
424 | |
425 # we fill nicknames and keep only requested people | |
426 | |
427 if self.args.no_rsvp: | |
428 for jid_ in event_data: | |
429 # if there is a jid in event_data it must be there in prefilled too | |
430 # otherwie somebody is not on the invitees list | |
431 try: | |
432 del prefilled[jid_] | |
433 except KeyError: | |
434 self.disp(A.color( | |
435 C.A_WARNING, | |
436 f"We got a RSVP from somebody who was not in invitees " | |
437 f"list: {jid_}" | |
438 ), | |
439 error=True) | |
2321
c2a9da96e40b
jp (event/attendee/list): added --missing to show missing people (ones who didn't replied) and --no-rsvp to hide ones who answered
Goffi <goffi@goffi.org>
parents:
2301
diff
changeset
|
440 else: |
3040 | 441 # we replace empty dicts for existing people with R.S.V.P. data |
442 prefilled.update(event_data) | |
443 | |
444 # we get nicknames for everybody, make it easier for organisers | |
445 for jid_, data in prefilled.items(): | |
446 id_data = await self.host.bridge.identityGet(jid_, self.profile) | |
447 data["nick"] = id_data.get("nick", "") | |
448 | |
449 await self.output(prefilled) | |
450 self.host.quit() | |
2321
c2a9da96e40b
jp (event/attendee/list): added --missing to show missing people (ones who didn't replied) and --no-rsvp to hide ones who answered
Goffi <goffi@goffi.org>
parents:
2301
diff
changeset
|
451 |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
452 |
2288
f4d8d83a50e2
jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents:
2284
diff
changeset
|
453 class InviteeInvite(base.CommandBase): |
f4d8d83a50e2
jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents:
2284
diff
changeset
|
454 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
455 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
456 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
457 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
458 "invite", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
459 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
460 pubsub_flags={C.NODE, C.SINGLE_ITEM}, |
3028 | 461 help=_("invite someone to the event through email"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
462 ) |
2288
f4d8d83a50e2
jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents:
2284
diff
changeset
|
463 |
f4d8d83a50e2
jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents:
2284
diff
changeset
|
464 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
465 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
466 "-e", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
467 "--email", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
468 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
469 default=[], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
470 help="email(s) to send the invitation to", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
471 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
472 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
473 "-N", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
474 "--name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
475 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
476 help="name of the invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
477 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
478 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
479 "-H", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
480 "--host-name", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
481 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
482 help="name of the host", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
483 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
484 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
485 "-l", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
486 "--lang", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
487 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
488 help="main language spoken by the invitee", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
489 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
490 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
491 "-U", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
492 "--url-template", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
493 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
494 help="template to construct the URL", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
495 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
496 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
497 "-S", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
498 "--subject", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
499 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
500 help="subject of the invitation email (default: generic subject)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
501 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
502 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
503 "-b", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
504 "--body", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
505 default="", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
506 help="body of the invitation email (default: generic body)", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
507 ) |
2288
f4d8d83a50e2
jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents:
2284
diff
changeset
|
508 |
3040 | 509 async def start(self): |
2291
c05000d00dbb
plugin events, invitations + jp (event/create, invitation/invitee/invite): several emails addresses can now be specified for a single invitation:
Goffi <goffi@goffi.org>
parents:
2288
diff
changeset
|
510 email = self.args.email[0] if self.args.email else None |
c05000d00dbb
plugin events, invitations + jp (event/create, invitation/invitee/invite): several emails addresses can now be specified for a single invitation:
Goffi <goffi@goffi.org>
parents:
2288
diff
changeset
|
511 emails_extra = self.args.email[1:] |
2288
f4d8d83a50e2
jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents:
2284
diff
changeset
|
512 |
3040 | 513 try: |
514 await self.host.bridge.eventInviteByEmail( | |
515 self.args.service, | |
516 self.args.node, | |
517 self.args.item, | |
518 email, | |
519 emails_extra, | |
520 self.args.name, | |
521 self.args.host_name, | |
522 self.args.lang, | |
523 self.args.url_template, | |
524 self.args.subject, | |
525 self.args.body, | |
526 self.args.profile, | |
527 ) | |
528 except Exception as e: | |
529 self.disp(f"can't create invitation: {e}", error=True) | |
530 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
531 else: | |
532 self.host.quit() | |
2288
f4d8d83a50e2
jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents:
2284
diff
changeset
|
533 |
f4d8d83a50e2
jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents:
2284
diff
changeset
|
534 |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
535 class Invitee(base.CommandBase): |
2300
173d56315529
jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents:
2299
diff
changeset
|
536 subcommands = (InviteeGet, InviteeSet, InviteesList, InviteeInvite) |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
537 |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
538 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
539 super(Invitee, self).__init__( |
3028 | 540 host, "invitee", use_profile=False, help=_("manage invities") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
541 ) |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
542 |
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
543 |
2236
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
544 class Event(base.CommandBase): |
2244
9d49e66bdbf2
jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents:
2236
diff
changeset
|
545 subcommands = (Get, Create, Modify, Invitee) |
2236
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
546 |
4b1873ce6b61
jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
547 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
548 super(Event, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
549 host, "event", use_profile=False, help=_("event management") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2616
diff
changeset
|
550 ) |