Mercurial > libervia-backend
annotate libervia/cli/cmd_forums.py @ 4205:17a8168966f9
frontends (tools/webrtc): implement screensharing for Wayland + bug fixes:
- Freedesktop Desktop Screenshare port is now used when Wayland is detected (needs
`xdg-desktop-portal` with the implementation corresponding to desktop environment).
- Add a binding feature to feedback state to application (e.g. if desktop sharing is
cancelled from desktop environment, or at portal's permission request level).
- fix misnaming of video source (was wrongly named `camera` instead of `video`).
- fix desktop sharing pad selection in `input-selector` when it has been added once, then
removed, then added again.
rel 434
author | Goffi <goffi@goffi.org> |
---|---|
date | Thu, 18 Jan 2024 23:29:25 +0100 |
parents | 5d056d524298 |
children |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
4 # Libervia CLI |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
512c443a58ba
jp (forums): forums 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 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
512c443a58ba
jp (forums): forums 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 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
4191
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
21 import sys |
3028 | 22 from . import base |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
23 from libervia.backend.core.i18n import _ |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
24 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
|
25 from libervia.cli import common |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
26 from libervia.backend.tools.common.ansi import ANSI as A |
4191
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
27 from libervia.frontends.bridge.bridge_frontend import BridgeException |
2608
0883bac573fd
jp (forums/edit): fixed unicode when dumping in json
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
28 import codecs |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
29 import json |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
31 __commands__ = ["Forums"] |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
32 |
3028 | 33 FORUMS_TMP_DIR = "forums" |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
34 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
35 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 class Edit(base.CommandBase, common.BaseEdit): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
37 use_items = False |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
38 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
39 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
40 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
41 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
42 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
43 "edit", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
44 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
45 use_draft=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
46 use_verbose=True, |
3028 | 47 help=_("edit forums"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
48 ) |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 common.BaseEdit.__init__(self, self.host, FORUMS_TMP_DIR) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
50 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
52 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
53 "-k", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
54 "--key", |
3028 | 55 default="", |
56 help=_("forum key (DEFAULT: default forums)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
57 ) |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
59 def get_tmp_suff(self): |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 """return suffix used for content file""" |
3028 | 61 return "json" |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 |
3040 | 63 async def publish(self, forums_raw): |
64 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
65 await self.host.bridge.forums_set( |
3040 | 66 forums_raw, |
67 self.args.service, | |
68 self.args.node, | |
69 self.args.key, | |
70 self.profile, | |
71 ) | |
72 except Exception as e: | |
73 self.disp(f"can't set forums: {e}", error=True) | |
74 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
75 else: | |
76 self.disp(_("forums have been edited"), 1) | |
77 self.host.quit() | |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
78 |
3040 | 79 async def start(self): |
80 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
81 forums_json = await self.host.bridge.forums_get( |
3040 | 82 self.args.service, |
83 self.args.node, | |
84 self.args.key, | |
85 self.profile, | |
86 ) | |
4191
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
87 except BridgeException as e: |
3040 | 88 if e.classname == "NotFound": |
89 forums_json = "" | |
90 else: | |
91 self.disp(f"can't get node configuration: {e}", error=True) | |
92 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
94 content_file_obj, content_file_path = self.get_tmp_file() |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 forums_json = forums_json.strip() |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 if forums_json: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 # we loads and dumps to have pretty printed json |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 forums = json.loads(forums_json) |
2608
0883bac573fd
jp (forums/edit): fixed unicode when dumping in json
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
99 # cf. https://stackoverflow.com/a/18337754 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
100 f = codecs.getwriter("utf-8")(content_file_obj) |
2608
0883bac573fd
jp (forums/edit): fixed unicode when dumping in json
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
101 json.dump(forums, f, ensure_ascii=False, indent=4) |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 content_file_obj.seek(0) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
103 await self.run_editor("forums_editor_args", content_file_path, content_file_obj) |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
104 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
105 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 class Get(base.CommandBase): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
108 extra_outputs = {"default": self.default_output} |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
109 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
110 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
111 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
112 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
113 use_output=C.OUTPUT_COMPLEX, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
114 extra_outputs=extra_outputs, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
115 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
116 use_verbose=True, |
3028 | 117 help=_("get forums structure"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
118 ) |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
121 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
122 "-k", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
123 "--key", |
3028 | 124 default="", |
125 help=_("forum key (DEFAULT: default forums)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
126 ) |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 def default_output(self, forums, level=0): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 for forum in forums: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 keys = list(forum.keys()) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 keys.sort() |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 try: |
3028 | 133 keys.remove("title") |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 except ValueError: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 pass |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 else: |
3028 | 137 keys.insert(0, "title") |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 try: |
3028 | 139 keys.remove("sub-forums") |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
140 except ValueError: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
141 pass |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 else: |
3028 | 143 keys.append("sub-forums") |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 for key in keys: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 value = forum[key] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
147 if key == "sub-forums": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
148 self.default_output(value, level + 1) |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 else: |
3028 | 150 if self.host.verbosity < 1 and key != "title": |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 continue |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 head_color = C.A_LEVEL_COLORS[level % len(C.A_LEVEL_COLORS)] |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
153 self.disp( |
3028 | 154 A.color(level * 4 * " ", head_color, key, A.RESET, ": ", value) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
155 ) |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 |
3040 | 157 async def start(self): |
158 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
159 forums_raw = await self.host.bridge.forums_get( |
3040 | 160 self.args.service, |
161 self.args.node, | |
162 self.args.key, | |
163 self.profile, | |
164 ) | |
165 except Exception as e: | |
166 self.disp(f"can't get forums: {e}", error=True) | |
167 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
168 else: | |
169 if not forums_raw: | |
170 self.disp(_("no schema found"), 1) | |
171 self.host.quit(1) | |
172 forums = json.loads(forums_raw) | |
173 await self.output(forums) | |
4191
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
174 |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
175 |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
176 class Set(base.CommandBase): |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
177 |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
178 def __init__(self, host): |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
179 base.CommandBase.__init__( |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
180 self, |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
181 host, |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
182 "set", |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
183 use_pubsub=True, |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
184 help=_("set forums"), |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
185 ) |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
186 |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
187 def add_parser_options(self): |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
188 self.parser.add_argument( |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
189 "-k", |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
190 "--key", |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
191 default="", |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
192 help=_("forum key (DEFAULT: default forums)"), |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
193 ) |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
194 |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
195 async def start(self): |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
196 forums_raw = sys.stdin.read() |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
197 try: |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
198 json.loads(forums_raw) |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
199 except Exception as e: |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
200 self.parser.error(f"Invalid JSON, a valid JSON must be used as input: {e}") |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
201 try: |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
202 await self.host.bridge.forums_set( |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
203 forums_raw, |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
204 self.args.service, |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
205 self.args.node, |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
206 self.args.key, |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
207 self.profile, |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
208 ) |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
209 except Exception as e: |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
210 self.disp(f"can't set forums: {e}", error=True) |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
211 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
212 else: |
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
213 self.disp(_("forums have been set")) |
3040 | 214 self.host.quit() |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
215 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
216 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
217 class Forums(base.CommandBase): |
4191
5d056d524298
core, doc, cli (forums): new `forums set` commands + doc:
Goffi <goffi@goffi.org>
parents:
4075
diff
changeset
|
218 subcommands = (Get, Set, Edit) |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
219 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
220 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
221 super(Forums, self).__init__( |
3028 | 222 host, "forums", use_profile=False, help=_("Forums structure edition") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2608
diff
changeset
|
223 ) |