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