annotate sat_frontends/jp/cmd_forums.py @ 3074:c2625920e05a

bridge (embedded): typo
author Goffi <goffi@goffi.org>
date Fri, 15 Nov 2019 17:57:49 +0100
parents fee60f17ebac
children 9d0df638c8b4
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1 #!/usr/bin/env python2
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
2 # -*- coding: utf-8 -*-
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
3
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
4 # jp: a SàT command line tool
2771
003b8b4b56a7 date update
Goffi <goffi@goffi.org>
parents: 2624
diff changeset
5 # Copyright (C) 2009-2019 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
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
21 from . import base
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
22 from sat.core.i18n import _
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 from sat_frontends.jp.constants import Const as C
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24 from sat_frontends.jp import common
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 from sat.tools.common.ansi import ANSI as A
2608
0883bac573fd jp (forums/edit): fixed unicode when dumping in json
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
26 import codecs
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27 import json
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 __commands__ = ["Forums"]
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
31 FORUMS_TMP_DIR = "forums"
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
34 class Edit(base.CommandBase, common.BaseEdit):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
35 use_items = False
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
38 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
39 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
40 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
41 "edit",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
42 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
43 use_draft=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
44 use_verbose=True,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
45 help=_("edit forums"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
46 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
47 common.BaseEdit.__init__(self, self.host, FORUMS_TMP_DIR)
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
49 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
50 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
51 "-k",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
52 "--key",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
53 default="",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
54 help=_("forum key (DEFAULT: default forums)"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
55 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
56
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
57 def getTmpSuff(self):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
58 """return suffix used for content file"""
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
59 return "json"
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
61 async def publish(self, forums_raw):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
62 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
63 await self.host.bridge.forumsSet(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
64 forums_raw,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
65 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
66 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
67 self.args.key,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
68 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
69 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
70 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
71 self.disp(f"can't set forums: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
72 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
73 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
74 self.disp(_("forums have been edited"), 1)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
75 self.host.quit()
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
76
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
77 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
78 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
79 forums_json = await self.host.bridge.forumsGet(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
80 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
81 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
82 self.args.key,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
83 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
84 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
85 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
86 if e.classname == "NotFound":
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
87 forums_json = ""
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
88 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
89 self.disp(f"can't get node configuration: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
90 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
91
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 content_file_obj, content_file_path = self.getTmpFile()
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 forums_json = forums_json.strip()
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94 if forums_json:
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 # we loads and dumps to have pretty printed json
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 forums = json.loads(forums_json)
2608
0883bac573fd jp (forums/edit): fixed unicode when dumping in json
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
97 # cf. https://stackoverflow.com/a/18337754
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
98 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
99 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
100 content_file_obj.seek(0)
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
101 await self.runEditor("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
102
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
103
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
104 class Get(base.CommandBase):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
105 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
106 extra_outputs = {"default": self.default_output}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
107 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
108 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
109 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
110 "get",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
111 use_output=C.OUTPUT_COMPLEX,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
112 extra_outputs=extra_outputs,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
113 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
114 use_verbose=True,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
115 help=_("get forums structure"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
116 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
119 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
120 "-k",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
121 "--key",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
122 default="",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
123 help=_("forum key (DEFAULT: default forums)"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
124 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
125
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
126 def default_output(self, forums, level=0):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
127 for forum in forums:
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
128 keys = list(forum.keys())
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
129 keys.sort()
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
131 keys.remove("title")
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 except ValueError:
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
133 pass
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
134 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
135 keys.insert(0, "title")
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
136 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
137 keys.remove("sub-forums")
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
138 except ValueError:
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
139 pass
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
140 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
141 keys.append("sub-forums")
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
142
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143 for key in keys:
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
144 value = forum[key]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
145 if key == "sub-forums":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
146 self.default_output(value, level + 1)
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
147 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
148 if self.host.verbosity < 1 and key != "title":
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149 continue
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
150 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
151 self.disp(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
152 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
153 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
154
3040
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
155 async def start(self):
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
156 try:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
157 forums_raw = await self.host.bridge.forumsGet(
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
158 self.args.service,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
159 self.args.node,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
160 self.args.key,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
161 self.profile,
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
162 )
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
163 except Exception as e:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
164 self.disp(f"can't get forums: {e}", error=True)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
165 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
166 else:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
167 if not forums_raw:
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
168 self.disp(_("no schema found"), 1)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
169 self.host.quit(1)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
170 forums = json.loads(forums_raw)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
171 await self.output(forums)
fee60f17ebac jp: jp asyncio port:
Goffi <goffi@goffi.org>
parents: 3028
diff changeset
172 self.host.quit()
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
173
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
174
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
175 class Forums(base.CommandBase):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
176 subcommands = (Get, Edit)
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
177
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
178 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
179 super(Forums, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
180 host, "forums", use_profile=False, help=_("Forums structure edition")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
181 )