annotate libervia/cli/cmd_event.py @ 4167:319a0e47dc8b

plugin ad-hoc D-Bus: fix deprecated use of python-dbus: the plugin was using python-dbus which is deprecated in the backend in the favor of TxDBus. Methods calls have been updated, and the plugin works again, but there seems to be still some issues (warnings in the logs). Those will be fixed later.
author Goffi <goffi@goffi.org>
date Fri, 01 Dec 2023 15:22:55 +0100
parents e9d800b105c1
children 0d7bb4df2343
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
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
4 # libervia-cli: Libervia CLI frontend
3479
be6d91572633 date update
Goffi <goffi@goffi.org>
parents: 3276
diff changeset
5 # Copyright (C) 2009-2021 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
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
21 import argparse
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
22 import sys
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
23
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
24 from sqlalchemy import desc
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
25
4071
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
26 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
27 from libervia.backend.core.i18n import _
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
28 from libervia.backend.tools.common import data_format
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
29 from libervia.backend.tools.common import data_format
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
30 from libervia.backend.tools.common import date_utils
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
31 from libervia.backend.tools.common.ansi import ANSI as A
4b842c1fb686 refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents: 4037
diff changeset
32 from libervia.backend.tools.common.ansi import ANSI as A
4075
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
33 from libervia.cli import common
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
34 from libervia.cli.constants import Const as C
47401850dec6 refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents: 4074
diff changeset
35 from libervia.cli.constants import Const as C
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
36
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
37 from . import base
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
39 __commands__ = ["Event"]
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
40
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
41 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
42
3276
81c8910db91f jp (event): new `list` command to get evens available in a service
Goffi <goffi@goffi.org>
parents: 3254
diff changeset
43
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
44 class Get(base.CommandBase):
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
46 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
47 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
48 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
49 "get",
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
50 use_output=C.OUTPUT_LIST_DICT,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
51 use_pubsub=True,
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
52 pubsub_flags={C.MULTI_ITEMS, C.CACHE},
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
53 use_verbose=True,
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
54 extra_outputs={
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
55 "default": self.default_output,
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
56 },
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
57 help=_("get event(s) data"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
58 )
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
59
9d49e66bdbf2 jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents: 2236
diff changeset
60 def add_parser_options(self):
2532
772447ec070f jp: pubsub options refactoring:
Goffi <goffi@goffi.org>
parents: 2491
diff changeset
61 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
62
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
63 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
64 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3906
diff changeset
65 events_data_s = await self.host.bridge.events_get(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
66 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
67 self.args.node,
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
68 self.args.items,
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3906
diff changeset
69 self.get_pubsub_extra(),
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
70 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
71 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
72 except Exception as e:
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
73 self.disp(f"can't get events data: {e}", error=True)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
74 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
75 else:
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
76 events_data = data_format.deserialise(events_data_s, type_check=list)
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
77 await self.output(events_data)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
78 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
79
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
80 def default_output(self, events):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
81 nb_events = len(events)
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
82 for idx, event in enumerate(events):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
83 names = event["name"]
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
84 name = names.get("") or next(iter(names.values()))
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
85 start = event["start"]
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
86 start_human = date_utils.date_fmt(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
87 start, "medium", tz_info=date_utils.TZ_LOCAL
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
88 )
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
89 end = event["end"]
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
90 self.disp(A.color(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
91 A.BOLD, start_human, A.RESET, " ",
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
92 f"({date_utils.delta2human(start, end)}) ",
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
93 C.A_HEADER, name
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
94 ))
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
95 if self.verbosity > 0:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
96 descriptions = event.get("descriptions", [])
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
97 if descriptions:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
98 self.disp(descriptions[0]["description"])
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
99 if idx < (nb_events-1):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
100 self.disp("")
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
101
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
102
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
103 class CategoryAction(argparse.Action):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
104
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
105 def __init__(self, option_strings, dest, nargs=None, metavar=None, **kwargs):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
106 if nargs is not None or metavar is not None:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
107 raise ValueError("nargs and metavar must not be used")
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
108 if metavar is not None:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
109 metavar="TERM WIKIDATA_ID LANG"
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
110 if "--help" in sys.argv:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
111 # FIXME: dirty workaround to have correct --help message
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
112 # argparse doesn't normally allow variable number of arguments beside "+"
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
113 # and "*", this workaround show METAVAR as 3 arguments were expected, while
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
114 # we can actuall use 1, 2 or 3.
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
115 nargs = 3
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
116 metavar = ("TERM", "[WIKIDATA_ID]", "[LANG]")
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
117 else:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
118 nargs = "+"
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
119
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
120 super().__init__(option_strings, dest, metavar=metavar, nargs=nargs, **kwargs)
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
121
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
122 def __call__(self, parser, namespace, values, option_string=None):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
123 categories = getattr(namespace, self.dest)
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
124 if categories is None:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
125 categories = []
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
126 setattr(namespace, self.dest, categories)
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
127
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
128 if not values:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
129 parser.error("category values must be set")
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
130
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
131 category = {
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
132 "term": values[0]
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
133 }
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
134
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
135 if len(values) == 1:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
136 pass
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
137 elif len(values) == 2:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
138 value = values[1]
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
139 if value.startswith("Q"):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
140 category["wikidata_id"] = value
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
141 else:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
142 category["language"] = value
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
143 elif len(values) == 3:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
144 __, wd, lang = values
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
145 category["wikidata_id"] = wd
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
146 category["language"] = lang
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
147 else:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
148 parser.error("Category can't have more than 3 arguments")
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
149
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
150 categories.append(category)
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
151
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
152
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
153 class EventBase:
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 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
155 self.parser.add_argument(
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
156 "-S", "--start", type=base.date_decoder, metavar="TIME_PATTERN",
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
157 help=_("the start time of the event"))
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
158 end_group = self.parser.add_mutually_exclusive_group()
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
159 end_group.add_argument(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
160 "-E", "--end", type=base.date_decoder, metavar="TIME_PATTERN",
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
161 help=_("the time of the end of the event"))
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
162 end_group.add_argument(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
163 "-D", "--duration", help=_("duration of the event"))
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
164 self.parser.add_argument(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
165 "-H", "--head-picture", help="URL to a picture to use as head-picture"
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
166 )
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
167 self.parser.add_argument(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
168 "-d", "--description", help="plain text description the event"
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
169 )
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
170 self.parser.add_argument(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
171 "-C", "--category", action=CategoryAction, dest="categories",
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
172 help="Category of the event"
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
173 )
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
174 self.parser.add_argument(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
175 "-l", "--location", action="append", nargs="+", metavar="[KEY] VALUE",
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
176 help="Location metadata"
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
177 )
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
178 rsvp_group = self.parser.add_mutually_exclusive_group()
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
179 rsvp_group.add_argument(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
180 "--rsvp", action="store_true", help=_("RSVP is requested"))
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
181 rsvp_group.add_argument(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
182 "--rsvp_json", metavar="JSON", help=_("JSON description of RSVP form"))
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
183 for node_type in ("invitees", "comments", "blog", "schedule"):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
184 self.parser.add_argument(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
185 f"--{node_type}",
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
186 nargs=2,
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
187 metavar=("JID", "NODE"),
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
188 help=_("link {node_type} pubsub node").format(node_type=node_type)
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
189 )
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
190 self.parser.add_argument(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
191 "-a", "--attachment", action="append", dest="attachments",
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
192 help=_("attach a file")
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
193 )
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
194 self.parser.add_argument("--website", help=_("website of the event"))
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
195 self.parser.add_argument(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
196 "--status", choices=["confirmed", "tentative", "cancelled"],
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
197 help=_("status of the event")
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
198 )
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
199 self.parser.add_argument(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
200 "-T", "--language", metavar="LANG", action="append", dest="languages",
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
201 help=_("main languages spoken at the event")
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
202 )
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
203 self.parser.add_argument(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
204 "--wheelchair", choices=["full", "partial", "no"],
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
205 help=_("is the location accessible by wheelchair")
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
206 )
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
207 self.parser.add_argument(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
208 "--external",
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
209 nargs=3,
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
210 metavar=("JID", "NODE", "ITEM"),
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
211 help=_("link to an external event")
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
212 )
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
213
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
214 def get_event_data(self):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
215 if self.args.duration is not None:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
216 if self.args.start is None:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
217 self.parser.error("--start must be send if --duration is used")
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
218 # if duration is used, we simply add it to start time to get end time
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
219 self.args.end = base.date_decoder(f"{self.args.start} + {self.args.duration}")
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
220
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
221 event = {}
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
222 if self.args.name is not None:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
223 event["name"] = {"": self.args.name}
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
224
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
225 if self.args.start is not None:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
226 event["start"] = self.args.start
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
227
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
228 if self.args.end is not None:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
229 event["end"] = self.args.end
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
230
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
231 if self.args.head_picture:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
232 event["head-picture"] = {
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
233 "sources": [{
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
234 "url": self.args.head_picture
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
235 }]
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
236 }
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
237 if self.args.description:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
238 event["descriptions"] = [
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
239 {
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
240 "type": "text",
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
241 "description": self.args.description
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
242 }
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
243 ]
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
244 if self.args.categories:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
245 event["categories"] = self.args.categories
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
246 if self.args.location is not None:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
247 location = {}
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
248 for location_data in self.args.location:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
249 if len(location_data) == 1:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
250 location["description"] = location_data[0]
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
251 else:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
252 key, *values = location_data
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
253 location[key] = " ".join(values)
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
254 event["locations"] = [location]
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
255
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
256 if self.args.rsvp:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
257 event["rsvp"] = [{}]
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
258 elif self.args.rsvp_json:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
259 if isinstance(self.args.rsvp_elt, dict):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
260 event["rsvp"] = [self.args.rsvp_json]
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
261 else:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
262 event["rsvp"] = self.args.rsvp_json
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
263
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
264 for node_type in ("invitees", "comments", "blog", "schedule"):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
265 value = getattr(self.args, node_type)
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
266 if value:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
267 service, node = value
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
268 event[node_type] = {"service": service, "node": node}
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
269
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
270 if self.args.attachments:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
271 attachments = event["attachments"] = []
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
272 for attachment in self.args.attachments:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
273 attachments.append({
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
274 "sources": [{"url": attachment}]
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
275 })
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
276
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
277 extra = {}
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
278
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
279 for arg in ("website", "status", "languages"):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
280 value = getattr(self.args, arg)
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
281 if value is not None:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
282 extra[arg] = value
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
283 if self.args.wheelchair is not None:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
284 extra["accessibility"] = {"wheelchair": self.args.wheelchair}
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
285
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
286 if extra:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
287 event["extra"] = extra
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
288
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
289 if self.args.external:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
290 ext_jid, ext_node, ext_item = self.args.external
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
291 event["external"] = {
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
292 "jid": ext_jid,
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
293 "node": ext_node,
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
294 "item": ext_item
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
295 }
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
296 return event
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
297
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
298
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
299 class Create(EventBase, base.CommandBase):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
300 def __init__(self, host):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
301 super().__init__(
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
302 host,
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
303 "create",
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
304 use_pubsub=True,
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
305 help=_("create or replace event"),
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
306 )
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
307
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
308 def add_parser_options(self):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
309 super().add_parser_options()
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
310 self.parser.add_argument(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
311 "-i",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
312 "--id",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
313 default="",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
314 help=_("ID of the PubSub Item"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
315 )
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
316 # name is mandatory here
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
317 self.parser.add_argument("name", help=_("name of the event"))
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
318
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
319 async def start(self):
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
320 if self.args.start is None:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
321 self.parser.error("--start must be set")
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
322 event_data = self.get_event_data()
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
323 # we check self.args.end after get_event_data because it may be set there id
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
324 # --duration is used
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
325 if self.args.end is None:
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
326 self.parser.error("--end or --duration must be set")
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
327 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3906
diff changeset
328 await self.host.bridge.event_create(
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
329 data_format.serialise(event_data),
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
330 self.args.id,
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
331 self.args.node,
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
332 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
333 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
334 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
335 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
336 self.disp(f"can't create event: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
337 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
338 else:
4090
e9d800b105c1 cli (event): minor typo
Goffi <goffi@goffi.org>
parents: 4075
diff changeset
339 self.disp(_("Event created successfuly"))
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
340 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
341
9d49e66bdbf2 jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents: 2236
diff changeset
342
9d49e66bdbf2 jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents: 2236
diff changeset
343 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
344 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
345 super(Modify, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
346 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
347 "modify",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
348 use_pubsub=True,
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
349 pubsub_flags={C.SINGLE_ITEM},
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
350 help=_("modify an existing event"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
351 )
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
352 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
353
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
354 def add_parser_options(self):
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
355 super().add_parser_options()
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
356 # name is optional here
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
357 self.parser.add_argument("-N", "--name", help=_("name of the event"))
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
358
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
359 async def start(self):
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
360 event_data = self.get_event_data()
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
361 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3906
diff changeset
362 await self.host.bridge.event_modify(
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
363 data_format.serialise(event_data),
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
364 self.args.item,
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
365 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
366 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
367 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
368 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
369 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
370 self.disp(f"can't update event data: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
371 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
372 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
373 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
374
9d49e66bdbf2 jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents: 2236
diff changeset
375
9d49e66bdbf2 jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents: 2236
diff changeset
376 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
377 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
378 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
379 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
380 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
381 "get",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
382 use_output=C.OUTPUT_DICT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
383 use_pubsub=True,
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
384 pubsub_flags={C.SINGLE_ITEM},
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
385 use_verbose=True,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
386 help=_("get event attendance"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
387 )
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
388
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
389 def add_parser_options(self):
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
390 self.parser.add_argument(
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
391 "-j", "--jid", action="append", dest="jids", default=[],
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
392 help=_("only retrieve RSVP from those JIDs")
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
393 )
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
394
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
395 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
396 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3906
diff changeset
397 event_data_s = await self.host.bridge.event_invitee_get(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
398 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
399 self.args.node,
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
400 self.args.item,
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
401 self.args.jids,
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
402 "",
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
403 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
404 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
405 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
406 self.disp(f"can't get event data: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
407 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
408 else:
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
409 event_data = data_format.deserialise(event_data_s)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
410 await self.output(event_data)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
411 self.host.quit()
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
412
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
413
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
414 class InviteeSet(base.CommandBase):
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
415 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
416 super(InviteeSet, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
417 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
418 "set",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
419 use_pubsub=True,
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
420 pubsub_flags={C.SINGLE_ITEM},
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
421 help=_("set event attendance"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
422 )
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
423
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
424 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
425 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
426 "-f",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
427 "--field",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
428 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
429 nargs=2,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
430 dest="fields",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
431 metavar=("KEY", "VALUE"),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
432 help=_("configuration field to set"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
433 )
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
434
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
435 async def start(self):
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
436 # TODO: handle RSVP with XMLUI in a similar way as for `ad-hoc run`
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
437 fields = dict(self.args.fields) if self.args.fields else {}
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
438 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3906
diff changeset
439 self.host.bridge.event_invitee_set(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
440 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
441 self.args.node,
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
442 self.args.item,
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
443 data_format.serialise(fields),
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
444 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
445 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
446 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
447 self.disp(f"can't set event data: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
448 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
449 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
450 self.host.quit()
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
451
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
452
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
453 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
454 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
455 extra_outputs = {"default": self.default_output}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
456 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
457 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
458 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
459 "list",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
460 use_output=C.OUTPUT_DICT_DICT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
461 extra_outputs=extra_outputs,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
462 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
463 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
464 use_verbose=True,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
465 help=_("get event attendance"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
466 )
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
467
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
468 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
469 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
470 "-m",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
471 "--missing",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
472 action="store_true",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
473 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
474 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
475 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
476 "-R",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
477 "--no-rsvp",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
478 action="store_true",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
479 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
480 )
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
481
2491
5895e4daae8c jp (event): added missing arg to _attend_filter
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
482 def _attend_filter(self, attend, row):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
483 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
484 attend_color = C.A_SUCCESS
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
485 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
486 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
487 else:
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
488 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
489 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
490
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
491 def _guests_filter(self, guests):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
492 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
493
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
494 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
495 data = []
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
496 attendees_yes = 0
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
497 attendees_maybe = 0
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
498 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
499 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
500 guests = 0
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
501 guests_maybe = 0
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
502 for jid_, jid_data in event_data.items():
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
503 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
504 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
505 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
506 except (ValueError, KeyError):
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
507 pass
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
508 attend = jid_data.get("attend", "")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
509 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
510 attendees_yes += 1
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
511 guests += guests_int
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
512 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
513 attendees_maybe += 1
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
514 guests_maybe += guests_int
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
515 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
516 attendees_no += 1
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
517 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
518 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
519 attendees_missing += 1
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
520 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
521 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
522
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
523 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
524
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3906
diff changeset
525 table = common.Table.from_list_dict(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
526 self.host,
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
527 data,
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
528 ("nick",) + (("jid",) if self.host.verbosity else ()) + ("attend", "guests"),
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
529 headers=None,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
530 filters={
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
531 "nick": A.color(C.A_HEADER, "{}" if show_table else "{} "),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
532 "jid": "{}" if show_table else "{} ",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
533 "attend": self._attend_filter,
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
534 "guests": "{}" if show_table else self._guests_filter,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
535 },
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
536 defaults={"nick": "", "attend": "", "guests": 1},
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
537 )
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
538 if show_table:
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
539 table.display()
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
540 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
541 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
542
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
543 if not self.args.no_rsvp:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
544 self.disp("")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
545 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
546 A.color(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
547 C.A_SUBHEADER,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
548 _("Attendees: "),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
549 A.RESET,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
550 str(len(data)),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
551 _(" ("),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
552 C.A_SUCCESS,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
553 _("yes: "),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
554 str(attendees_yes),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
555 A.FG_WHITE,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
556 _(", maybe: "),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
557 str(attendees_maybe),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
558 ", ",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
559 C.A_FAILURE,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
560 _("no: "),
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
561 str(attendees_no),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
562 A.RESET,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
563 ")",
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
564 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
565 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
566 self.disp(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
567 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
568 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
569 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
570 A.color(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
571 C.A_SUBHEADER,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
572 _("unconfirmed guests: "),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
573 A.RESET,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
574 str(guests_maybe),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
575 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
576 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
577 self.disp(
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
578 A.color(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
579 )
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
580 if attendees_missing:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
581 self.disp("")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
582 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
583 A.color(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
584 C.A_SUBHEADER,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
585 _("missing people (no reply): "),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
586 A.RESET,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
587 str(attendees_missing),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
588 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
589 )
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
590
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
591 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
592 if self.args.no_rsvp and not self.args.missing:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
593 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
594 if not self.args.missing:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
595 prefilled = {}
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
596 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
597 # we get prefilled data with all people
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
598 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3906
diff changeset
599 affiliations = await self.host.bridge.ps_node_affiliations_get(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
600 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
601 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
602 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
603 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
604 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
605 self.disp(f"can't get node affiliations: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
606 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
607 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
608 # 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
609 # below. We only consider people with "publisher" affiliation as invited,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
610 # creators are not, and members can just observe
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
611 prefilled = {
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
612 jid_: {}
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
613 for jid_, affiliation in affiliations.items()
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
614 if affiliation in ("publisher",)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
615 }
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
616
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
617 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3906
diff changeset
618 event_data = await self.host.bridge.event_invitees_list(
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
619 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
620 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
621 self.profile,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
622 )
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
623 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
624 self.disp(f"can't get event data: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
625 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
626
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
627 # we fill nicknames and keep only requested people
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
628
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
629 if self.args.no_rsvp:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
630 for jid_ in event_data:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
631 # 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
632 # otherwie somebody is not on the invitees list
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
633 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
634 del prefilled[jid_]
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
635 except KeyError:
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
636 self.disp(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
637 A.color(
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
638 C.A_WARNING,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
639 f"We got a RSVP from somebody who was not in invitees "
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
640 f"list: {jid_}",
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
641 ),
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
642 error=True,
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
643 )
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
644 else:
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
645 # 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
646 prefilled.update(event_data)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
647
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
648 # we get nicknames for everybody, make it easier for organisers
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
649 for jid_, data in prefilled.items():
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3906
diff changeset
650 id_data = await self.host.bridge.identity_get(jid_, [], True, self.profile)
3254
6cf4bd6972c2 core, frontends: avatar refactoring:
Goffi <goffi@goffi.org>
parents: 3137
diff changeset
651 id_data = data_format.deserialise(id_data)
3568
04283582966f core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents: 3479
diff changeset
652 data["nick"] = id_data["nicknames"][0]
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
653
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
654 await self.output(prefilled)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
655 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
656
2300
173d56315529 jp (event/invitee): added list command to get R.S.V.P. :
Goffi <goffi@goffi.org>
parents: 2299
diff changeset
657
2288
f4d8d83a50e2 jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents: 2284
diff changeset
658 class InviteeInvite(base.CommandBase):
f4d8d83a50e2 jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents: 2284
diff changeset
659 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
660 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
661 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
662 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
663 "invite",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
664 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
665 pubsub_flags={C.NODE, C.SINGLE_ITEM},
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
666 help=_("invite someone to the event through email"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
667 )
2288
f4d8d83a50e2 jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents: 2284
diff changeset
668
f4d8d83a50e2 jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents: 2284
diff changeset
669 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
670 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
671 "-e",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
672 "--email",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
673 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
674 default=[],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
675 help="email(s) to send the invitation to",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
676 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
677 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
678 "-N",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
679 "--name",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
680 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
681 help="name of the invitee",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
682 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
683 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
684 "-H",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
685 "--host-name",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
686 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
687 help="name of the host",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
688 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
689 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
690 "-l",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
691 "--lang",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
692 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
693 help="main language spoken by the invitee",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
694 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
695 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
696 "-U",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
697 "--url-template",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
698 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
699 help="template to construct the URL",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
700 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
701 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
702 "-S",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
703 "--subject",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
704 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
705 help="subject of the invitation email (default: generic subject)",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
706 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
707 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
708 "-b",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
709 "--body",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
710 default="",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
711 help="body of the invitation email (default: generic body)",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
712 )
2288
f4d8d83a50e2 jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents: 2284
diff changeset
713
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
714 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
715 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
716 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
717
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
718 try:
4037
524856bd7b19 massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents: 3906
diff changeset
719 await self.host.bridge.event_invite_by_email(
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
720 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
721 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
722 self.args.item,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
723 email,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
724 emails_extra,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
725 self.args.name,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
726 self.args.host_name,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
727 self.args.lang,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
728 self.args.url_template,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
729 self.args.subject,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
730 self.args.body,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
731 self.args.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
732 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
733 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
734 self.disp(f"can't create invitation: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
735 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
736 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
737 self.host.quit()
2288
f4d8d83a50e2 jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents: 2284
diff changeset
738
f4d8d83a50e2 jp (event/invitee/invite): command to use new eventInvite backend method
Goffi <goffi@goffi.org>
parents: 2284
diff changeset
739
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
740 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
741 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
742
9d49e66bdbf2 jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents: 2236
diff changeset
743 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
744 super(Invitee, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2910
diff changeset
745 host, "invitee", use_profile=False, help=_("manage invities")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
746 )
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
747
9d49e66bdbf2 jp (event): creation/modification of main event + invitee commands are now in a "invitee" subcommand
Goffi <goffi@goffi.org>
parents: 2236
diff changeset
748
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
749 class Event(base.CommandBase):
3906
d8baf92cb921 cli (event): update commands following changes in events:
Goffi <goffi@goffi.org>
parents: 3568
diff changeset
750 subcommands = (Get, Create, Modify, Invitee)
2236
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
751
4b1873ce6b61 jp (event): event handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
752 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
753 super(Event, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
754 host, "event", use_profile=False, help=_("event management")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2616
diff changeset
755 )