annotate sat_frontends/jp/cmd_event.py @ 3254:6cf4bd6972c2

core, frontends: avatar refactoring: /!\ huge commit Avatar logic has been reworked around the IDENTITY plugin: plugins able to handle avatar or other identity related metadata (like nicknames) register to IDENTITY plugin in the same way as for other features like download/upload. Once registered, IDENTITY plugin will call them when suitable in order of priority, and handle caching. Methods to manage those metadata from frontend now use serialised data. For now `avatar` and `nicknames` are handled: - `avatar` is now a dict with `path` + metadata like `media_type`, instead of just a string path - `nicknames` is now a list of nicknames in order of priority. This list is never empty, and `nicknames[0]` should be the preferred nickname to use by frontends in most cases. In addition to contact specified nicknames, user set nickname (the one set in roster) is used in priority when available. Among the side changes done with this commit, there are: - a new `contactGet` bridge method to get roster metadata for a single contact - SatPresenceProtocol.send returns a Deferred to check when it has actually been sent - memory's methods to handle entities data now use `client` as first argument - metadata filter can be specified with `getIdentity` - `getAvatar` and `setAvatar` are now part of the IDENTITY plugin instead of XEP-0054 (and there signature has changed) - `isRoom` and `getBareOrFull` are now part of XEP-0045 plugin - jp avatar/get command uses `xdg-open` first when available for `--show` flag - `--no-cache` has been added to jp avatar/get and identity/get - jp identity/set has been simplified, explicit options (`--nickname` only for now) are used instead of `--field`. `--field` may come back in the future if necessary for extra data. - QuickContactList `SetContact` now handle None as a value, and doesn't use it to delete the metadata anymore - improved cache handling for `metadata` and `nicknames` in quick frontend - new `default` argument in QuickContactList `getCache`
author Goffi <goffi@goffi.org>
date Tue, 14 Apr 2020 21:00:33 +0200
parents 559a625a236b
children 81c8910db91f
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
3137
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
1 #!/usr/bin/env python3
559a625a236b fixed shebangs
Goffi <goffi@goffi.org>
parents: 3136
diff changeset
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
9d0df638c8b4 dates update
Goffi <goffi@goffi.org>
parents: 3121
diff changeset
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
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
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
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 class Get(base.CommandBase):
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
40 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
41 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
42 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
43 "get",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
44 use_output=C.OUTPUT_DICT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
45 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
46 pubsub_flags={C.SINGLE_ITEM},
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
47 use_verbose=True,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
48 help=_("get event data"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
49 )
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
50
9d49e66bdbf2 jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents: 2236
diff changeset
51 def add_parser_options(self):
2532
772447ec070f jp: pubsub options refactoring:
Goffi <goffi@goffi.org>
parents: 2491
diff changeset
52 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
53
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
54 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
55 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
56 event_tuple = await self.host.bridge.eventGet(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
57 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
58 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
59 self.args.item,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
60 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
61 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
62 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
63 self.disp(f"can't get event data: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
64 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
65 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
66 event_date, event_data = event_tuple
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
67 event_data["date"] = event_date
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
68 await self.output(event_data)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
69 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
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
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 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
73 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
74 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
75 "-i",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
76 "--id",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
77 default="",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
78 help=_("ID of the PubSub Item"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
79 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
80 self.parser.add_argument(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
81 "-d", "--date", type=str, help=_("date of the event")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
82 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
83 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
84 "-f",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
85 "--field",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
86 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
87 nargs=2,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
88 dest="fields",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
89 metavar=("KEY", "VALUE"),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
90 help=_("configuration field to set"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
91 )
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
92
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 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
94 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
95
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 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
97 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
98 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
99 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
100 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
101 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
102 date_time = du_parser.parse(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
103 self.args.date, dayfirst=not ("-" in self.args.date)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
104 )
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
105 except ValueError as e:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
106 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
107 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
108 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
109 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
110 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
111 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
112 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
113 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
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
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 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
117 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
118 super(Create, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
119 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
120 "create",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
121 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
122 help=_("create or replace event"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
123 )
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
124 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
125
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
126 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
127 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
128 date = self.parseDate()
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
129 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
130 node = await self.host.bridge.eventCreate(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
131 date,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
132 fields,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
133 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
134 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
135 self.args.id,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
136 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
137 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
138 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
139 self.disp(f"can't create event: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
140 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
141 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
142 self.disp(_(f"Event created successfuly on node {node}"))
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
143 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
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 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
147 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
148 super(Modify, 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 "modify",
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 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
153 help=_("modify an existing event"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
154 )
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
155 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
156
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
157 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
158 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
159 date = 0 if not self.args.date else self.parseDate()
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
160 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
161 self.host.bridge.eventModify(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
162 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
163 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
164 self.args.id,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
165 date,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
166 fields,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
167 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
168 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
169 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
170 self.disp(f"can't update event data: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
171 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
172 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
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 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
177 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
178 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
179 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
180 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
181 "get",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
182 use_output=C.OUTPUT_DICT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
183 use_pubsub=True,
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
184 pubsub_flags={C.NODE},
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
185 use_verbose=True,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
186 help=_("get event attendance"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
187 )
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
188
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
189 def add_parser_options(self):
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
190 self.parser.add_argument(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
191 "-j", "--jid", default="", help=_("bare jid of the invitee")
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
192 )
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
193
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
194 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
195 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
196 event_data = await self.host.bridge.eventInviteeGet(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
197 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
198 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
199 self.args.jid,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
200 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
201 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
202 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
203 self.disp(f"can't get event data: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
204 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
205 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
206 await self.output(event_data)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
207 self.host.quit()
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
208
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
209
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
210 class InviteeSet(base.CommandBase):
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
211 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
212 super(InviteeSet, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
213 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
214 "set",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
215 use_output=C.OUTPUT_DICT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
216 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
217 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
218 help=_("set event attendance"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
219 )
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
220
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
221 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
222 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
223 "-f",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
224 "--field",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
225 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
226 nargs=2,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
227 dest="fields",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
228 metavar=("KEY", "VALUE"),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
229 help=_("configuration field to set"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
230 )
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
231
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
232 async def start(self):
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
233 fields = dict(self.args.fields) if self.args.fields else {}
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
234 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
235 self.host.bridge.eventInviteeSet(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
236 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
237 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
238 fields,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
239 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
240 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
241 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
242 self.disp(f"can't set event data: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
243 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
244 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
245 self.host.quit()
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
246
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
247
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
248 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
249 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
250 extra_outputs = {"default": self.default_output}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
251 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
252 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
253 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
254 "list",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
255 use_output=C.OUTPUT_DICT_DICT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
256 extra_outputs=extra_outputs,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
257 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
258 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
259 use_verbose=True,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
260 help=_("get event attendance"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
261 )
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
262
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
263 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
264 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
265 "-m",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
266 "--missing",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
267 action="store_true",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
268 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
269 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
270 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
271 "-R",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
272 "--no-rsvp",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
273 action="store_true",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
274 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
275 )
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
276
2491
5895e4daae8c jp (event): added missing arg to _attend_filter
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
277 def _attend_filter(self, attend, row):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
278 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
279 attend_color = C.A_SUCCESS
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
280 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
281 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
282 else:
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
283 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
284 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
285
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
286 def _guests_filter(self, guests):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
287 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
288
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
289 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
290 data = []
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
291 attendees_yes = 0
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
292 attendees_maybe = 0
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
293 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
294 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
295 guests = 0
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
296 guests_maybe = 0
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
297 for jid_, jid_data in event_data.items():
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
298 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
299 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
300 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
301 except (ValueError, KeyError):
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
302 pass
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
303 attend = jid_data.get("attend", "")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
304 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
305 attendees_yes += 1
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
306 guests += guests_int
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
307 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
308 attendees_maybe += 1
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
309 guests_maybe += guests_int
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
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 attendees_no += 1
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
312 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
313 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
314 attendees_missing += 1
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
315 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
316 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
317
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
318 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
319
3121
040ca99e25fe jp (common): various Table fixes:
Goffi <goffi@goffi.org>
parents: 3040
diff changeset
320 table = common.Table.fromListDict(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
321 self.host,
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
322 data,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
323 ("nick",)
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
324 + (("jid",) if self.host.verbosity else ())
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
325 + ("attend", "guests"),
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
326 headers=None,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
327 filters={
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
328 "nick": A.color(C.A_HEADER, "{}" if show_table else "{} "),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
329 "jid": "{}" if show_table else "{} ",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
330 "attend": self._attend_filter,
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
331 "guests": "{}" if show_table else self._guests_filter,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
332 },
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
333 defaults={"nick": "", "attend": "", "guests": 1},
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
334 )
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
335 if show_table:
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
336 table.display()
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
337 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
338 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
339
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
340 if not self.args.no_rsvp:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
341 self.disp("")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
342 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
343 A.color(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
344 C.A_SUBHEADER,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
345 _("Attendees: "),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
346 A.RESET,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
347 str(len(data)),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
348 _(" ("),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
349 C.A_SUCCESS,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
350 _("yes: "),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
351 str(attendees_yes),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
352 A.FG_WHITE,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
353 _(", maybe: "),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
354 str(attendees_maybe),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
355 ", ",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
356 C.A_FAILURE,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
357 _("no: "),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
358 str(attendees_no),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
359 A.RESET,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
360 ")",
2624
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 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
363 self.disp(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
364 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
365 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
366 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
367 A.color(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
368 C.A_SUBHEADER,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
369 _("unconfirmed guests: "),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
370 A.RESET,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
371 str(guests_maybe),
2624
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 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
374 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
375 A.color(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
376 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
377 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
378 )
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
379 if attendees_missing:
2624
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 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
382 A.color(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
383 C.A_SUBHEADER,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
384 _("missing people (no reply): "),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
385 A.RESET,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
386 str(attendees_missing),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
387 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
388 )
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
389
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
390 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
391 if self.args.no_rsvp and not self.args.missing:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
392 self.parser.error(_("you need to use --missing if you use --no-rsvp"))
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
393 if not self.args.missing:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
394 prefilled = {}
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
395 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
396 # we get prefilled data with all people
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
397 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
398 affiliations = await self.host.bridge.psNodeAffiliationsGet(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
399 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
400 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
401 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
402 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
403 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
404 self.disp(f"can't get node affiliations: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
405 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
406 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
407 # we fill all affiliations with empty data, answered one will be filled
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
408 # below. We only consider people with "publisher" affiliation as invited,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
409 # creators are not, and members can just observe
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
410 prefilled = {
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
411 jid_: {}
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
412 for jid_, affiliation in affiliations.items()
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
413 if affiliation in ("publisher",)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
414 }
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
415
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
416 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
417 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
418 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
419 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
420 self.profile,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
421 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
422 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
423 self.disp(f"can't get event data: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
424 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
425
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
426 # we fill nicknames and keep only requested people
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
427
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
428 if self.args.no_rsvp:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
429 for jid_ in event_data:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
430 # if there is a jid in event_data it must be there in prefilled too
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
431 # otherwie somebody is not on the invitees list
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
432 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
433 del prefilled[jid_]
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
434 except KeyError:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
435 self.disp(A.color(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
436 C.A_WARNING,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
437 f"We got a RSVP from somebody who was not in invitees "
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
438 f"list: {jid_}"
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
439 ),
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
440 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
441 else:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
442 # we replace empty dicts for existing people with R.S.V.P. data
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
443 prefilled.update(event_data)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
444
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
445 # we get nicknames for everybody, make it easier for organisers
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
446 for jid_, data in prefilled.items():
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
447 id_data = await self.host.bridge.identityGet(jid_, [], True, self.profile)
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
448 id_data = data_format.deserialise(id_data)
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
449 data["nick"] = id_data['nicknames'][0]
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
450
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
451 await self.output(prefilled)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
452 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
453
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
454
2288
f4d8d83a50e2 jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents: 2284
diff changeset
455 class InviteeInvite(base.CommandBase):
f4d8d83a50e2 jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents: 2284
diff changeset
456 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
457 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
458 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
459 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
460 "invite",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
461 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
462 pubsub_flags={C.NODE, C.SINGLE_ITEM},
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
463 help=_("invite someone to the event through email"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
464 )
2288
f4d8d83a50e2 jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents: 2284
diff changeset
465
f4d8d83a50e2 jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents: 2284
diff changeset
466 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
467 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
468 "-e",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
469 "--email",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
470 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
471 default=[],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
472 help="email(s) to send the invitation to",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
473 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
474 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
475 "-N",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
476 "--name",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
477 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
478 help="name of the invitee",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
479 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
480 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
481 "-H",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
482 "--host-name",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
483 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
484 help="name of the host",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
485 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
486 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
487 "-l",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
488 "--lang",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
489 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
490 help="main language spoken by the invitee",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
491 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
492 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
493 "-U",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
494 "--url-template",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
495 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
496 help="template to construct the URL",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
497 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
498 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
499 "-S",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
500 "--subject",
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="subject of the invitation email (default: generic subject)",
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 "-b",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
506 "--body",
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="body of the invitation email (default: generic body)",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
509 )
2288
f4d8d83a50e2 jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents: 2284
diff changeset
510
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
511 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
512 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
513 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
514
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
515 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
516 await self.host.bridge.eventInviteByEmail(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
517 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
518 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
519 self.args.item,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
520 email,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
521 emails_extra,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
522 self.args.name,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
523 self.args.host_name,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
524 self.args.lang,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
525 self.args.url_template,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
526 self.args.subject,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
527 self.args.body,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
528 self.args.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
529 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
530 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
531 self.disp(f"can't create invitation: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
532 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
533 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
534 self.host.quit()
2288
f4d8d83a50e2 jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents: 2284
diff changeset
535
f4d8d83a50e2 jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents: 2284
diff changeset
536
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 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
538 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
539
9d49e66bdbf2 jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents: 2236
diff changeset
540 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
541 super(Invitee, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
542 host, "invitee", use_profile=False, help=_("manage invities")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
543 )
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
544
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
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
546 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
547 subcommands = (Get, Create, Modify, Invitee)
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
548
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
549 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
550 super(Event, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
551 host, "event", use_profile=False, help=_("event management")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
552 )