annotate sat_frontends/jp/cmd_forums.py @ 2868:5546613f5007

plugin android: workaround to seek() bug, fixing file upload: seek() is bugged on current version of P4A, arguments are inverted. More details can be found at https://github.com/kivy/python-for-android/issues/1768
author Goffi <goffi@goffi.org>
date Mon, 25 Mar 2019 07:06:41 +0100
parents 003b8b4b56a7
children ab2696e34d29
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
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
21 import base
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
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26 from functools import partial
2608
0883bac573fd jp (forums/edit): fixed unicode when dumping in json
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
27 import codecs
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28 import json
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30 __commands__ = ["Forums"]
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
31
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
32 FORUMS_TMP_DIR = u"forums"
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
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
35 class Edit(base.CommandBase, common.BaseEdit):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
36 use_items = False
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
39 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
40 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
41 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
42 "edit",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
43 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
44 use_draft=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
45 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
46 help=_(u"edit forums"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
47 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
48 common.BaseEdit.__init__(self, self.host, FORUMS_TMP_DIR)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
49 self.need_loop = True
2485
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",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
55 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
56 default=u"",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
57 help=_(u"forum key (DEFAULT: default forums)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
58 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 def getTmpSuff(self):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
61 """return suffix used for content file"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
62 return u"json"
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
64 def forumsSetCb(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
65 self.disp(_(u"forums have been edited"), 1)
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66 self.host.quit()
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 def publish(self, forums_raw):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 self.host.bridge.forumsSet(
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 forums_raw,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.args.service,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 self.args.node,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 self.args.key,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 self.profile,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
75 callback=self.forumsSetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
76 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
77 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
78 msg=_(u"can't set forums: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
79 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
80 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
81 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 def forumsGetCb(self, forums_json):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 content_file_obj, content_file_path = self.getTmpFile()
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 forums_json = forums_json.strip()
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86 if forums_json:
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 # we loads and dumps to have pretty printed json
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
88 forums = json.loads(forums_json)
2608
0883bac573fd jp (forums/edit): fixed unicode when dumping in json
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
89 # cf. https://stackoverflow.com/a/18337754
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
90 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
91 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
92 content_file_obj.seek(0)
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
93 self.runEditor("forums_editor_args", content_file_path, content_file_obj)
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 def forumsGetEb(self, failure_):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
96 # FIXME: error handling with bridge is broken, need to be properly fixed
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
97 if failure_.condition == u"item-not-found":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
98 self.forumsGetCb(u"")
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
99 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
100 self.errback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
101 failure_,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
102 msg=_(u"can't get forums structure: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
103 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
104 )
2485
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 def start(self):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 self.host.bridge.forumsGet(
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108 self.args.service,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109 self.args.node,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110 self.args.key,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 self.profile,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
112 callback=self.forumsGetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
113 errback=self.forumsGetEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
114 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
115
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
116
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 class Get(base.CommandBase):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
118 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
119 extra_outputs = {"default": self.default_output}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
120 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
121 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
122 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
123 "get",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
124 use_output=C.OUTPUT_COMPLEX,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
125 extra_outputs=extra_outputs,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
126 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
127 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
128 help=_(u"get forums structure"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
129 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
130 self.need_loop = True
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
132 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
133 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
134 "-k",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
135 "--key",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
136 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
137 default=u"",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
138 help=_(u"forum key (DEFAULT: default forums)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
139 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
140
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141 def default_output(self, forums, level=0):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
142 for forum in forums:
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143 keys = list(forum.keys())
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
144 keys.sort()
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
145 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
146 keys.remove(u"title")
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
147 except ValueError:
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
148 pass
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
150 keys.insert(0, u"title")
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
152 keys.remove(u"sub-forums")
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
153 except ValueError:
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
154 pass
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
155 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
156 keys.append(u"sub-forums")
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
157
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
158 for key in keys:
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
159 value = forum[key]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
160 if key == "sub-forums":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
161 self.default_output(value, level + 1)
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
162 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
163 if self.host.verbosity < 1 and key != u"title":
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
164 continue
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
165 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
166 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
167 A.color(level * 4 * u" ", head_color, key, A.RESET, u": ", value)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
168 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
169
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
170 def forumsGetCb(self, forums_raw):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
171 if not forums_raw:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
172 self.disp(_(u"no schema found"), 1)
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
173 self.host.quit(1)
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
174 forums = json.loads(forums_raw)
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
175 self.output(forums)
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
176 self.host.quit()
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 start(self):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
179 self.host.bridge.forumsGet(
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
180 self.args.service,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
181 self.args.node,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
182 self.args.key,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
183 self.profile,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
184 callback=self.forumsGetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
185 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
186 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
187 msg=_(u"can't get forums: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
188 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
189 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
190 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
191
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
192
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
193 class Forums(base.CommandBase):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
194 subcommands = (Get, Edit)
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
195
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
196 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
197 super(Forums, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
198 host, "forums", use_profile=False, help=_(u"Forums structure edition")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
199 )