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