Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_forums.py @ 2617:81b70eeb710f
quick_frontend(contact list): refactored update:
update is now called with appropriate constant value (C.UPDATE_ADD, C.UPDATE_DELETE, C.UPDATE_MODIFY and so on) when a widget change visibility according to current options.
Before it was linked to cache only (C.UPDATE_ADD was only called when contact was first added to cache).
This make widget handling in frontends more easy.
Renamed entityToShow to entityVisible, which seems to correspond better.
Started reducing lines lenght to 90 chars as a test. May become the new coding style soon.
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 24 Jun 2018 21:59:29 +0200 |
parents | 0883bac573fd |
children | 56f94936df1e |
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 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
5 # Copyright (C) 2009-2018 Jérôme Poisson (goffi@goffi.org) |
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): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
36 use_items=False |
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): |
2532 | 39 base.CommandBase.__init__(self, host, 'edit', use_pubsub=True, use_draft=True, use_verbose=True, help=_(u'edit forums')) |
2485
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 common.BaseEdit.__init__(self, self.host, FORUMS_TMP_DIR) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 self.need_loop=True |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 def add_parser_options(self): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 self.parser.add_argument("-k", "--key", type=base.unicode_decoder, default=u'', |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
45 help=_(u"forum key (DEFAULT: default forums)")) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
46 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
47 def getTmpSuff(self): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
48 """return suffix used for content file""" |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 return u'json' |
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 forumsSetCb(self): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
52 self.disp(_(u'forums have been edited'), 1) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
53 self.host.quit() |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
54 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
55 def publish(self, forums_raw): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
56 self.host.bridge.forumsSet( |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
57 forums_raw, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
58 self.args.service, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
59 self.args.node, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
60 self.args.key, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
61 self.profile, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
62 callback=self.forumsSetCb, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
63 errback=partial(self.errback, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
64 msg=_(u"can't set forums: {}"), |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
65 exit_code=C.EXIT_BRIDGE_ERRBACK)) |
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 forumsGetCb(self, forums_json): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
68 content_file_obj, content_file_path = self.getTmpFile() |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
69 forums_json = forums_json.strip() |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
70 if forums_json: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
71 # we loads and dumps to have pretty printed json |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
72 forums = json.loads(forums_json) |
2608
0883bac573fd
jp (forums/edit): fixed unicode when dumping in json
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
73 # cf. https://stackoverflow.com/a/18337754 |
0883bac573fd
jp (forums/edit): fixed unicode when dumping in json
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
74 f = codecs.getwriter('utf-8')(content_file_obj) |
0883bac573fd
jp (forums/edit): fixed unicode when dumping in json
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
75 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
|
76 content_file_obj.seek(0) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
77 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
|
78 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
79 def forumsGetEb(self, failure_): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
80 # FIXME: error handling with bridge is broken, need to be properly fixed |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
81 if failure_.condition == u'item-not-found': |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
82 self.forumsGetCb(u'') |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
83 else: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
84 self.errback(failure_, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
85 msg=_(u"can't get forums structure: {}"), |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
86 exit_code=C.EXIT_BRIDGE_ERRBACK) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
87 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
88 def start(self): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
89 self.host.bridge.forumsGet( |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
90 self.args.service, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
91 self.args.node, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
92 self.args.key, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
93 self.profile, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
94 callback=self.forumsGetCb, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
95 errback=self.forumsGetEb) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
96 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
97 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
98 class Get(base.CommandBase): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
99 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
100 def __init__(self, host): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
101 extra_outputs = {'default': self.default_output} |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
102 base.CommandBase.__init__(self, host, 'get', use_output=C.OUTPUT_COMPLEX, extra_outputs=extra_outputs, use_pubsub=True, use_verbose=True, help=_(u'get forums structure')) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
103 self.need_loop=True |
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 add_parser_options(self): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
106 self.parser.add_argument("-k", "--key", type=base.unicode_decoder, default=u'', |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
107 help=_(u"forum key (DEFAULT: default forums)")) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
108 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
109 def default_output(self, forums, level=0): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
110 for forum in forums: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
111 keys = list(forum.keys()) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
112 keys.sort() |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
113 try: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
114 keys.remove(u'title') |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
115 except ValueError: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
116 pass |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
117 else: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
118 keys.insert(0, u'title') |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
119 try: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
120 keys.remove(u'sub-forums') |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
121 except ValueError: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
122 pass |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
123 else: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
124 keys.append(u'sub-forums') |
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 for key in keys: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
127 value = forum[key] |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
128 if key == 'sub-forums': |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
129 self.default_output(value, level+1) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
130 else: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
131 if self.host.verbosity < 1 and key != u'title': |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
132 continue |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
133 head_color = C.A_LEVEL_COLORS[level % len(C.A_LEVEL_COLORS)] |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
134 self.disp(A.color(level * 4 * u' ', |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
135 head_color, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
136 key, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
137 A.RESET, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
138 u': ', |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
139 value)) |
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 forumsGetCb(self, forums_raw): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
142 if not forums_raw: |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
143 self.disp(_(u'no schema found'), 1) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
144 self.host.quit(1) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
145 forums = json.loads(forums_raw) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
146 self.output(forums) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
147 self.host.quit() |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
148 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
149 def start(self): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
150 self.host.bridge.forumsGet( |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
151 self.args.service, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
152 self.args.node, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
153 self.args.key, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
154 self.profile, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
155 callback=self.forumsGetCb, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
156 errback=partial(self.errback, |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
157 msg=_(u"can't get forums: {}"), |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
158 exit_code=C.EXIT_BRIDGE_ERRBACK)) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
159 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
160 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
161 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
162 class Forums(base.CommandBase): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
163 subcommands = (Get, Edit) |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
164 |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
165 def __init__(self, host): |
512c443a58ba
jp (forums): forums handling commands, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
166 super(Forums, self).__init__(host, 'forums', use_profile=False, help=_(u'Forums structure edition')) |