annotate sat_frontends/jp/cmd_forums.py @ 3028:ab2696e34d29

Python 3 port: /!\ this is a huge commit /!\ starting from this commit, SàT is needs Python 3.6+ /!\ SàT maybe be instable or some feature may not work anymore, this will improve with time This patch port backend, bridge and frontends to Python 3. Roughly this has been done this way: - 2to3 tools has been applied (with python 3.7) - all references to python2 have been replaced with python3 (notably shebangs) - fixed files not handled by 2to3 (notably the shell script) - several manual fixes - fixed issues reported by Python 3 that where not handled in Python 2 - replaced "async" with "async_" when needed (it's a reserved word from Python 3.7) - replaced zope's "implements" with @implementer decorator - temporary hack to handle data pickled in database, as str or bytes may be returned, to be checked later - fixed hash comparison for password - removed some code which is not needed anymore with Python 3 - deactivated some code which needs to be checked (notably certificate validation) - tested with jp, fixed reported issues until some basic commands worked - ported Primitivus (after porting dependencies like urwid satext) - more manual fixes
author Goffi <goffi@goffi.org>
date Tue, 13 Aug 2019 19:08:41 +0200
parents 003b8b4b56a7
children fee60f17ebac
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
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
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
32 FORUMS_TMP_DIR = "forums"
2485
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,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
46 help=_("edit forums"),
2624
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",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
55 default="",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
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
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
59 def getTmpSuff(self):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
60 """return suffix used for content file"""
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
61 return "json"
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
62
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
63 def forumsSetCb(self):
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
64 self.disp(_("forums have been edited"), 1)
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
65 self.host.quit()
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
66
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
67 def publish(self, forums_raw):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
68 self.host.bridge.forumsSet(
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
69 forums_raw,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
70 self.args.service,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
71 self.args.node,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
72 self.args.key,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
73 self.profile,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
74 callback=self.forumsSetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
75 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
76 self.errback,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
77 msg=_("can't set forums: {}"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
78 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
79 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
80 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
81
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
82 def forumsGetCb(self, forums_json):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
83 content_file_obj, content_file_path = self.getTmpFile()
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
84 forums_json = forums_json.strip()
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
85 if forums_json:
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
86 # we loads and dumps to have pretty printed json
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
87 forums = json.loads(forums_json)
2608
0883bac573fd jp (forums/edit): fixed unicode when dumping in json
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
88 # cf. https://stackoverflow.com/a/18337754
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
89 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
90 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
91 content_file_obj.seek(0)
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
92 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
93
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
94 def forumsGetEb(self, failure_):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
95 # FIXME: error handling with bridge is broken, need to be properly fixed
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
96 if failure_.condition == "item-not-found":
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
97 self.forumsGetCb("")
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
98 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
99 self.errback(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
100 failure_,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
101 msg=_("can't get forums structure: {}"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
102 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
103 )
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 def start(self):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
106 self.host.bridge.forumsGet(
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
107 self.args.service,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
108 self.args.node,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
109 self.args.key,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
110 self.profile,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
111 callback=self.forumsGetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
112 errback=self.forumsGetEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
113 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
114
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 class Get(base.CommandBase):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
117 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
118 extra_outputs = {"default": self.default_output}
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
119 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
120 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
121 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
122 "get",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
123 use_output=C.OUTPUT_COMPLEX,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
124 extra_outputs=extra_outputs,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
125 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
126 use_verbose=True,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
127 help=_("get forums structure"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
128 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
129 self.need_loop = True
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
130
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
131 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
132 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
133 "-k",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
134 "--key",
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
135 default="",
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
136 help=_("forum key (DEFAULT: default forums)"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
137 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
138
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
139 def default_output(self, forums, level=0):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
140 for forum in forums:
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
141 keys = list(forum.keys())
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
142 keys.sort()
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
143 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
144 keys.remove("title")
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
145 except ValueError:
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
146 pass
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 keys.insert(0, "title")
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149 try:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
150 keys.remove("sub-forums")
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151 except ValueError:
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
152 pass
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
153 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
154 keys.append("sub-forums")
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
155
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
156 for key in keys:
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
157 value = forum[key]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
158 if key == "sub-forums":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
159 self.default_output(value, level + 1)
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
160 else:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
161 if self.host.verbosity < 1 and key != "title":
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
162 continue
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
163 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
164 self.disp(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
165 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
166 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
167
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
168 def forumsGetCb(self, forums_raw):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
169 if not forums_raw:
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
170 self.disp(_("no schema found"), 1)
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
171 self.host.quit(1)
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
172 forums = json.loads(forums_raw)
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
173 self.output(forums)
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
174 self.host.quit()
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
175
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
176 def start(self):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
177 self.host.bridge.forumsGet(
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
178 self.args.service,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
179 self.args.node,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
180 self.args.key,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
181 self.profile,
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
182 callback=self.forumsGetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
183 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
184 self.errback,
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
185 msg=_("can't get forums: {}"),
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
186 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
187 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
188 )
2485
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
189
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
190
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
191 class Forums(base.CommandBase):
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
192 subcommands = (Get, Edit)
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
193
512c443a58ba jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
194 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
195 super(Forums, self).__init__(
3028
ab2696e34d29 Python 3 port:
Goffi <goffi@goffi.org>
parents: 2771
diff changeset
196 host, "forums", use_profile=False, help=_("Forums structure edition")
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2608
diff changeset
197 )