Mercurial > libervia-backend
annotate sat_frontends/jp/cmd_pubsub.py @ 3521:62f490eff51c
jp (pubsub, blog): `rename` commands implementation
author | Goffi <goffi@goffi.org> |
---|---|
date | Sat, 01 May 2021 18:39:34 +0200 |
parents | be6d91572633 |
children | 04283582966f |
rev | line source |
---|---|
3137 | 1 #!/usr/bin/env python3 |
2 | |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3 |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
4 # jp: a SàT command line tool |
3479 | 5 # Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org) |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
6 |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
7 # This program is free software: you can redistribute it and/or modify |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
8 # it under the terms of the GNU Affero General Public License as published by |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
9 # the Free Software Foundation, either version 3 of the License, or |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
10 # (at your option) any later version. |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
11 |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
12 # This program is distributed in the hope that it will be useful, |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
15 # GNU Affero General Public License for more details. |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
16 |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
17 # You should have received a copy of the GNU Affero General Public License |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
18 # along with this program. If not, see <http://www.gnu.org/licenses/>. |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
19 |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
20 |
3040 | 21 import argparse |
22 import os.path | |
23 import re | |
24 import sys | |
25 import subprocess | |
26 import asyncio | |
3028 | 27 from . import base |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
28 from sat.core.i18n import _ |
2316 | 29 from sat.core import exceptions |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
30 from sat_frontends.jp.constants import Const as C |
2275
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
31 from sat_frontends.jp import common |
2316 | 32 from sat_frontends.jp import arg_tools |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
33 from sat_frontends.jp import xml_tools |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
34 from functools import partial |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
35 from sat.tools.common import data_format |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
36 from sat.tools.common import uri |
2316 | 37 from sat.tools.common.ansi import ANSI as A |
38 from sat_frontends.tools import jid, strings | |
3413
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
39 from sat_frontends.bridge.bridge_frontend import BridgeException |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
40 |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
41 __commands__ = ["Pubsub"] |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 |
3028 | 43 PUBSUB_TMP_DIR = "pubsub" |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
44 PUBSUB_SCHEMA_TMP_DIR = PUBSUB_TMP_DIR + "_schema" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
45 ALLOWED_SUBSCRIPTIONS_OWNER = ("subscribed", "pending", "none") |
2275
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
46 |
2308
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
47 # TODO: need to split this class in several modules, plugin should handle subcommands |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
48 |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
49 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
50 class NodeInfo(base.CommandBase): |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
51 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
52 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
53 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
54 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 "info", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
56 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
57 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
58 pubsub_flags={C.NODE}, |
3028 | 59 help=_("retrieve node configuration"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
60 ) |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
61 |
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
62 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
63 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
64 "-k", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
65 "--key", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
66 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
67 dest="keys", |
3028 | 68 help=_("data key to filter"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
69 ) |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
70 |
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
71 def removePrefix(self, key): |
3028 | 72 return key[7:] if key.startswith("pubsub#") else key |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
73 |
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
74 def filterKey(self, key): |
3028 | 75 return any((key == k or key == "pubsub#" + k) for k in self.args.keys) |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
76 |
3040 | 77 async def start(self): |
78 try: | |
79 config_dict = await self.host.bridge.psNodeConfigurationGet( | |
80 self.args.service, | |
81 self.args.node, | |
82 self.profile, | |
83 ) | |
3413
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
84 except BridgeException as e: |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
85 if e.condition == 'item-not-found': |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
86 self.disp( |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
87 f"The node {self.args.node} doesn't exist on {self.args.service}", |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
88 error=True |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
89 ) |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
90 self.host.quit(C.EXIT_NOT_FOUND) |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
91 else: |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
92 self.disp(f"can't get node configuration: {e}", error=True) |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
93 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
3040 | 94 except Exception as e: |
3413
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
95 self.disp(f"Internal error: {e}", error=True) |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
96 self.host.quit(C.EXIT_INTERNAL_ERROR) |
3040 | 97 else: |
98 key_filter = (lambda k: True) if not self.args.keys else self.filterKey | |
99 config_dict = { | |
100 self.removePrefix(k): v for k, v in config_dict.items() if key_filter(k) | |
101 } | |
102 await self.output(config_dict) | |
103 self.host.quit() | |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
104 |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
105 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
106 class NodeCreate(base.CommandBase): |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
107 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
108 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
109 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
110 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
111 "create", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
112 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
113 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
114 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
115 use_verbose=True, |
3028 | 116 help=_("create a node"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
117 ) |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
118 |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
119 @staticmethod |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
120 def add_node_config_options(parser): |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
121 parser.add_argument( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
122 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
123 "--field", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
124 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
125 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
126 dest="fields", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
127 default=[], |
3028 | 128 metavar=("KEY", "VALUE"), |
129 help=_("configuration field to set"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
130 ) |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
131 parser.add_argument( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
132 "-F", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
133 "--full-prefix", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
134 action="store_true", |
3028 | 135 help=_('don\'t prepend "pubsub#" prefix to field names'), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
136 ) |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
137 |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
138 def add_parser_options(self): |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
139 self.add_node_config_options(self.parser) |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
140 |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
141 @staticmethod |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
142 def get_config_options(args): |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
143 if not args.full_prefix: |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
144 return {"pubsub#" + k: v for k, v in args.fields} |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
145 else: |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
146 return dict(args.fields) |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
147 |
3040 | 148 async def start(self): |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
149 options = self.get_config_options(self.args) |
3040 | 150 try: |
151 node_id = await self.host.bridge.psNodeCreate( | |
152 self.args.service, | |
153 self.args.node, | |
154 options, | |
155 self.profile, | |
156 ) | |
157 except Exception as e: | |
158 self.disp(msg=_(f"can't create node: {e}"), error=True) | |
159 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
160 else: | |
161 if self.host.verbosity: | |
162 announce = _("node created successfully: ") | |
163 else: | |
164 announce = "" | |
165 self.disp(announce + node_id) | |
166 self.host.quit() | |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
167 |
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
168 |
2802
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
169 class NodePurge(base.CommandBase): |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
170 |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
171 def __init__(self, host): |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
172 super(NodePurge, self).__init__( |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
173 host, |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
174 "purge", |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
175 use_pubsub=True, |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
176 pubsub_flags={C.NODE}, |
3028 | 177 help=_("purge a node (i.e. remove all items from it)"), |
2802
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
178 ) |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
179 |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
180 def add_parser_options(self): |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
181 self.parser.add_argument( |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
182 "-f", |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
183 "--force", |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
184 action="store_true", |
3028 | 185 help=_("purge node without confirmation"), |
2802
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
186 ) |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
187 |
3040 | 188 async def start(self): |
2802
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
189 if not self.args.force: |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
190 if not self.args.service: |
3040 | 191 message = _( |
192 f"Are you sure to purge PEP node [{self.args.node}]? This will " | |
193 f"delete ALL items from it!") | |
2802
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
194 else: |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
195 message = _( |
3040 | 196 f"Are you sure to delete node [{self.args.node}] on service " |
197 f"[{self.args.service}]? This will delete ALL items from it!") | |
198 await self.host.confirmOrQuit(message, _("node purge cancelled")) | |
2802
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
199 |
3040 | 200 try: |
201 await self.host.bridge.psNodePurge( | |
202 self.args.service, | |
203 self.args.node, | |
204 self.profile, | |
205 ) | |
206 except Exception as e: | |
207 self.disp(msg=_(f"can't purge node: {e}"), error=True) | |
208 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
209 else: | |
210 self.disp(_(f"node [{self.args.node}] purged successfully")) | |
211 self.host.quit() | |
2802
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
212 |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
213 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
214 class NodeDelete(base.CommandBase): |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
215 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
216 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
217 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
218 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
219 "delete", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
220 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
221 pubsub_flags={C.NODE}, |
3028 | 222 help=_("delete a node"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
223 ) |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
224 |
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
225 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
226 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
227 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
228 "--force", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
229 action="store_true", |
3028 | 230 help=_("delete node without confirmation"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
231 ) |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
232 |
3040 | 233 async def start(self): |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
234 if not self.args.force: |
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
235 if not self.args.service: |
3040 | 236 message = _(f"Are you sure to delete PEP node [{self.args.node}] ?") |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
237 else: |
3040 | 238 message = _(f"Are you sure to delete node [{self.args.node}] on " |
239 f"service [{self.args.service}]?") | |
240 await self.host.confirmOrQuit(message, _("node deletion cancelled")) | |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
241 |
3040 | 242 try: |
243 await self.host.bridge.psNodeDelete( | |
244 self.args.service, | |
245 self.args.node, | |
246 self.profile, | |
247 ) | |
248 except Exception as e: | |
249 self.disp(f"can't delete node: {e}", error=True) | |
250 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
251 else: | |
252 self.disp(_(f"node [{self.args.node}] deleted successfully")) | |
253 self.host.quit() | |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
254 |
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
255 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
256 class NodeSet(base.CommandBase): |
2199
ea0d0a4e2ad8
jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents:
2197
diff
changeset
|
257 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
258 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
259 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
260 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
261 "set", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
262 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
263 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
264 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
265 use_verbose=True, |
3028 | 266 help=_("set node configuration"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
267 ) |
2199
ea0d0a4e2ad8
jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents:
2197
diff
changeset
|
268 |
ea0d0a4e2ad8
jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents:
2197
diff
changeset
|
269 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
270 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
271 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
272 "--field", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
273 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
274 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
275 dest="fields", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
276 required=True, |
3028 | 277 metavar=("KEY", "VALUE"), |
278 help=_("configuration field to set (required)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
279 ) |
3040 | 280 self.parser.add_argument( |
281 "-F", | |
282 "--full-prefix", | |
283 action="store_true", | |
284 help=_('don\'t prepend "pubsub#" prefix to field names'), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
285 ) |
2199
ea0d0a4e2ad8
jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents:
2197
diff
changeset
|
286 |
ea0d0a4e2ad8
jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents:
2197
diff
changeset
|
287 def getKeyName(self, k): |
3040 | 288 if self.args.full_prefix or k.startswith("pubsub#"): |
289 return k | |
290 else: | |
3028 | 291 return "pubsub#" + k |
2199
ea0d0a4e2ad8
jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents:
2197
diff
changeset
|
292 |
3040 | 293 async def start(self): |
294 try: | |
295 await self.host.bridge.psNodeConfigurationSet( | |
296 self.args.service, | |
297 self.args.node, | |
298 {self.getKeyName(k): v for k, v in self.args.fields}, | |
299 self.profile, | |
300 ) | |
301 except Exception as e: | |
302 self.disp(f"can't set node configuration: {e}", error=True) | |
303 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
304 else: | |
305 self.disp(_("node configuration successful"), 1) | |
306 self.host.quit() | |
2199
ea0d0a4e2ad8
jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents:
2197
diff
changeset
|
307 |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
308 |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
309 class NodeImport(base.CommandBase): |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
310 |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
311 def __init__(self, host): |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
312 super(NodeImport, self).__init__( |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
313 host, |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
314 "import", |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
315 use_pubsub=True, |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
316 pubsub_flags={C.NODE}, |
3028 | 317 help=_("import raw XML to a node"), |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
318 ) |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
319 |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
320 def add_parser_options(self): |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
321 self.parser.add_argument( |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
322 "--admin", |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
323 action="store_true", |
3028 | 324 help=_("do a pubsub admin request, needed to change publisher"), |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
325 ) |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
326 self.parser.add_argument( |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
327 "import_file", |
3028 | 328 type=argparse.FileType(), |
329 help=_("path to the XML file with data to import. The file must contain " | |
330 "whole XML of each item to import."), | |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
331 ) |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
332 |
3040 | 333 async def start(self): |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
334 try: |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
335 element, etree = xml_tools.etreeParse(self, self.args.import_file, |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
336 reraise=True) |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
337 except Exception as e: |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
338 from lxml.etree import XMLSyntaxError |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
339 if isinstance(e, XMLSyntaxError) and e.code == 5: |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
340 # we have extra content, this probaby means that item are not wrapped |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
341 # so we wrap them here and try again |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
342 self.args.import_file.seek(0) |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
343 xml_buf = "<import>" + self.args.import_file.read() + "</import>" |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
344 element, etree = xml_tools.etreeParse(self, xml_buf) |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
345 |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
346 # we reverse element as we expect to have most recently published element first |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
347 # TODO: make this more explicit and add an option |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
348 element[:] = reversed(element) |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
349 |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
350 if not all([i.tag == '{http://jabber.org/protocol/pubsub}item' for i in element]): |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
351 self.disp( |
3028 | 352 _("You are not using list of pubsub items, we can't import this file"), |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
353 error=True) |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
354 self.host.quit(C.EXIT_DATA_ERROR) |
3040 | 355 return |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
356 |
3040 | 357 items = [etree.tostring(i, encoding="unicode") for i in element] |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
358 if self.args.admin: |
3040 | 359 method = self.host.bridge.psAdminItemsSend |
360 else: | |
361 self.disp(_("Items are imported without using admin mode, publisher can't " | |
362 "be changed")) | |
363 method = self.host.bridge.psItemsSend | |
364 | |
365 try: | |
366 items_ids = await method( | |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
367 self.args.service, |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
368 self.args.node, |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
369 items, |
3028 | 370 "", |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
371 self.profile, |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
372 ) |
3040 | 373 except Exception as e: |
374 self.disp(f"can't send items: {e}", error=True) | |
375 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
376 else: |
3040 | 377 if items_ids: |
378 self.disp(_('items published with id(s) {items_ids}').format( | |
379 items_ids=', '.join(items_ids))) | |
380 else: | |
381 self.disp(_('items published')) | |
382 self.host.quit() | |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
383 |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
384 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
385 class NodeAffiliationsGet(base.CommandBase): |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
386 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
387 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
388 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
389 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
390 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
391 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
392 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
393 pubsub_flags={C.NODE}, |
3028 | 394 help=_("retrieve node affiliations (for node owner)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
395 ) |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
396 |
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
397 def add_parser_options(self): |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
398 pass |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
399 |
3040 | 400 async def start(self): |
401 try: | |
402 affiliations = await self.host.bridge.psNodeAffiliationsGet( | |
403 self.args.service, | |
404 self.args.node, | |
405 self.profile, | |
406 ) | |
407 except Exception as e: | |
408 self.disp(f"can't get node affiliations: {e}", error=True) | |
409 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
410 else: | |
411 await self.output(affiliations) | |
412 self.host.quit() | |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
413 |
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
414 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
415 class NodeAffiliationsSet(base.CommandBase): |
2207
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
416 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
417 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
418 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
419 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
420 "set", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
421 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
422 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
423 use_verbose=True, |
3028 | 424 help=_("set affiliations (for node owner)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
425 ) |
2207
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
426 |
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
427 def add_parser_options(self): |
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
428 # XXX: we use optional argument syntax for a required one because list of list of 2 elements |
3325
7ebda4b54170
jp (file/share): added commands to manage affiliations and configuration + documentation
Goffi <goffi@goffi.org>
parents:
3312
diff
changeset
|
429 # (used to construct dicts) don't work with positional arguments |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
430 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
431 "-a", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
432 "--affiliation", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
433 dest="affiliations", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
434 metavar=("JID", "AFFILIATION"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
435 required=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
436 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
437 nargs=2, |
3028 | 438 help=_("entity/affiliation couple(s)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
439 ) |
2207
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
440 |
3040 | 441 async def start(self): |
2207
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
442 affiliations = dict(self.args.affiliations) |
3040 | 443 try: |
444 await self.host.bridge.psNodeAffiliationsSet( | |
445 self.args.service, | |
446 self.args.node, | |
447 affiliations, | |
448 self.profile, | |
449 ) | |
450 except Exception as e: | |
451 self.disp(f"can't set node affiliations: {e}", error=True) | |
452 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
453 else: | |
454 self.disp(_("affiliations have been set"), 1) | |
455 self.host.quit() | |
2207
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
456 |
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
457 |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
458 class NodeAffiliations(base.CommandBase): |
2207
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
459 subcommands = (NodeAffiliationsGet, NodeAffiliationsSet) |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
460 |
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
461 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
462 super(NodeAffiliations, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
463 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
464 "affiliations", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
465 use_profile=False, |
3028 | 466 help=_("set or retrieve node affiliations"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
467 ) |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
468 |
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
469 |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
470 class NodeSubscriptionsGet(base.CommandBase): |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
471 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
472 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
473 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
474 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
475 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
476 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
477 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
478 pubsub_flags={C.NODE}, |
3028 | 479 help=_("retrieve node subscriptions (for node owner)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
480 ) |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
481 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
482 def add_parser_options(self): |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
483 pass |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
484 |
3040 | 485 async def start(self): |
486 try: | |
487 subscriptions = await self.host.bridge.psNodeSubscriptionsGet( | |
488 self.args.service, | |
489 self.args.node, | |
490 self.profile, | |
491 ) | |
492 except Exception as e: | |
493 self.disp(f"can't get node subscriptions: {e}", error=True) | |
494 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
495 else: | |
496 await self.output(subscriptions) | |
497 self.host.quit() | |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
498 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
499 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
500 class StoreSubscriptionAction(argparse.Action): |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
501 """Action which handle subscription parameter for owner |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
502 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
503 list is given by pairs: jid and subscription state |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
504 if subscription state is not specified, it default to "subscribed" |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
505 """ |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
506 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
507 def __call__(self, parser, namespace, values, option_string): |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
508 dest_dict = getattr(namespace, self.dest) |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
509 while values: |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
510 jid_s = values.pop(0) |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
511 try: |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
512 subscription = values.pop(0) |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
513 except IndexError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
514 subscription = "subscribed" |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
515 if subscription not in ALLOWED_SUBSCRIPTIONS_OWNER: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
516 parser.error( |
3028 | 517 _("subscription must be one of {}").format( |
518 ", ".join(ALLOWED_SUBSCRIPTIONS_OWNER) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
519 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
520 ) |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
521 dest_dict[jid_s] = subscription |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
522 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
523 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
524 class NodeSubscriptionsSet(base.CommandBase): |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
525 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
526 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
527 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
528 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
529 "set", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
530 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
531 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
532 use_verbose=True, |
3028 | 533 help=_("set/modify subscriptions (for node owner)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
534 ) |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
535 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
536 def add_parser_options(self): |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
537 # XXX: we use optional argument syntax for a required one because list of list of 2 elements |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
538 # (uses to construct dicts) don't work with positional arguments |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
539 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
540 "-S", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
541 "--subscription", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
542 dest="subscriptions", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
543 default={}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
544 nargs="+", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
545 metavar=("JID [SUSBSCRIPTION]"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
546 required=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
547 action=StoreSubscriptionAction, |
3028 | 548 help=_("entity/subscription couple(s)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
549 ) |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
550 |
3040 | 551 async def start(self): |
552 try: | |
553 self.host.bridge.psNodeSubscriptionsSet( | |
554 self.args.service, | |
555 self.args.node, | |
556 self.args.subscriptions, | |
557 self.profile, | |
558 ) | |
559 except Exception as e: | |
560 self.disp(f"can't set node subscriptions: {e}", error=True) | |
561 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
562 else: | |
563 self.disp(_("subscriptions have been set"), 1) | |
564 self.host.quit() | |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
565 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
566 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
567 class NodeSubscriptions(base.CommandBase): |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
568 subcommands = (NodeSubscriptionsGet, NodeSubscriptionsSet) |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
569 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
570 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
571 super(NodeSubscriptions, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
572 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
573 "subscriptions", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
574 use_profile=False, |
3028 | 575 help=_("get or modify node subscriptions"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
576 ) |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
577 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
578 |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
579 class NodeSchemaSet(base.CommandBase): |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
580 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
581 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
582 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
583 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
584 "set", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
585 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
586 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
587 use_verbose=True, |
3028 | 588 help=_("set/replace a schema"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
589 ) |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
590 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
591 def add_parser_options(self): |
3028 | 592 self.parser.add_argument("schema", help=_("schema to set (must be XML)")) |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
593 |
3040 | 594 async def start(self): |
595 try: | |
596 await self.host.bridge.psSchemaSet( | |
597 self.args.service, | |
598 self.args.node, | |
599 self.args.schema, | |
600 self.profile, | |
601 ) | |
602 except Exception as e: | |
603 self.disp(f"can't set schema: {e}", error=True) | |
604 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
605 else: | |
606 self.disp(_("schema has been set"), 1) | |
607 self.host.quit() | |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
608 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
609 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
610 class NodeSchemaEdit(base.CommandBase, common.BaseEdit): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
611 use_items = False |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
612 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
613 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
614 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
615 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
616 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
617 "edit", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
618 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
619 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
620 use_draft=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
621 use_verbose=True, |
3028 | 622 help=_("edit a schema"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
623 ) |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
624 common.BaseEdit.__init__(self, self.host, PUBSUB_SCHEMA_TMP_DIR) |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
625 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
626 def add_parser_options(self): |
2532 | 627 pass |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
628 |
3040 | 629 async def publish(self, schema): |
630 try: | |
631 await self.host.bridge.psSchemaSet( | |
632 self.args.service, | |
633 self.args.node, | |
634 schema, | |
635 self.profile, | |
636 ) | |
637 except Exception as e: | |
638 self.disp(f"can't set schema: {e}", error=True) | |
639 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
640 else: | |
641 self.disp(_("schema has been set"), 1) | |
642 self.host.quit() | |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
643 |
3040 | 644 async def psSchemaGetCb(self, schema): |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
645 try: |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
646 from lxml import etree |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
647 except ImportError: |
3028 | 648 self.disp('lxml module must be installed to use edit, please install it ' |
649 'with "pip install lxml"', | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
650 error=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
651 ) |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
652 self.host.quit(1) |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
653 content_file_obj, content_file_path = self.getTmpFile() |
2359
47516e90d26a
jp (pubsub/node/schema): check that a schema exists before parsing it (fix issue on new schema edition)
Goffi <goffi@goffi.org>
parents:
2353
diff
changeset
|
654 schema = schema.strip() |
47516e90d26a
jp (pubsub/node/schema): check that a schema exists before parsing it (fix issue on new schema edition)
Goffi <goffi@goffi.org>
parents:
2353
diff
changeset
|
655 if schema: |
47516e90d26a
jp (pubsub/node/schema): check that a schema exists before parsing it (fix issue on new schema edition)
Goffi <goffi@goffi.org>
parents:
2353
diff
changeset
|
656 parser = etree.XMLParser(remove_blank_text=True) |
47516e90d26a
jp (pubsub/node/schema): check that a schema exists before parsing it (fix issue on new schema edition)
Goffi <goffi@goffi.org>
parents:
2353
diff
changeset
|
657 schema_elt = etree.fromstring(schema, parser) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
658 content_file_obj.write( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
659 etree.tostring(schema_elt, encoding="utf-8", pretty_print=True) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
660 ) |
2359
47516e90d26a
jp (pubsub/node/schema): check that a schema exists before parsing it (fix issue on new schema edition)
Goffi <goffi@goffi.org>
parents:
2353
diff
changeset
|
661 content_file_obj.seek(0) |
3040 | 662 await self.runEditor("pubsub_schema_editor_args", content_file_path, content_file_obj) |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
663 |
3040 | 664 async def start(self): |
665 try: | |
666 schema = await self.host.bridge.psSchemaGet( | |
667 self.args.service, | |
668 self.args.node, | |
669 self.profile, | |
670 ) | |
3453
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
671 except BridgeException as e: |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
672 if e.condition == 'item-not-found' or e.classname=="NotFound": |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
673 schema = "" |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
674 else: |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
675 self.disp(f"can't edit schema: {e}", error=True) |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
676 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
677 |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
678 await self.psSchemaGetCb(schema) |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
679 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
680 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
681 class NodeSchemaGet(base.CommandBase): |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
682 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
683 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
684 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
685 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
686 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
687 use_output=C.OUTPUT_XML, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
688 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
689 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
690 use_verbose=True, |
3028 | 691 help=_("get schema"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
692 ) |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
693 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
694 def add_parser_options(self): |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
695 pass |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
696 |
3040 | 697 async def start(self): |
698 try: | |
699 schema = await self.host.bridge.psSchemaGet( | |
700 self.args.service, | |
701 self.args.node, | |
702 self.profile, | |
703 ) | |
3453
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
704 except BridgeException as e: |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
705 if e.condition == 'item-not-found' or e.classname=="NotFound": |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
706 schema = None |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
707 else: |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
708 self.disp(f"can't get schema: {e}", error=True) |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
709 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
710 |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
711 if schema: |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
712 await self.output(schema) |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
713 self.host.quit() |
3040 | 714 else: |
3453
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
715 self.disp(_("no schema found"), 1) |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
716 self.host.quit(C.EXIT_NOT_FOUND) |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
717 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
718 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
719 class NodeSchema(base.CommandBase): |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
720 subcommands = (NodeSchemaSet, NodeSchemaEdit, NodeSchemaGet) |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
721 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
722 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
723 super(NodeSchema, self).__init__( |
3028 | 724 host, "schema", use_profile=False, help=_("data schema manipulation") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
725 ) |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
726 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
727 |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
728 class Node(base.CommandBase): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
729 subcommands = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
730 NodeInfo, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
731 NodeCreate, |
2802
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
732 NodePurge, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
733 NodeDelete, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
734 NodeSet, |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
735 NodeImport, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
736 NodeAffiliations, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
737 NodeSubscriptions, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
738 NodeSchema, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
739 ) |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
740 |
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
741 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
742 super(Node, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
743 host, "node", use_profile=False, help=_("node handling") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
744 ) |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
745 |
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
746 |
2439
6908fe4c6eca
jp (pubsub): added new "set" command tu publish or update an item in a non-interactive way (while "edit" do it interactively).
Goffi <goffi@goffi.org>
parents:
2416
diff
changeset
|
747 class Set(base.CommandBase): |
6908fe4c6eca
jp (pubsub): added new "set" command tu publish or update an item in a non-interactive way (while "edit" do it interactively).
Goffi <goffi@goffi.org>
parents:
2416
diff
changeset
|
748 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
749 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
750 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
751 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
752 "set", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
753 use_pubsub=True, |
3412
7b4ae3dbc041
jp (base, pubsub/set): new `--quiet` argument:
Goffi <goffi@goffi.org>
parents:
3411
diff
changeset
|
754 use_quiet=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
755 pubsub_flags={C.NODE}, |
3028 | 756 help=_("publish a new item or update an existing one"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
757 ) |
2439
6908fe4c6eca
jp (pubsub): added new "set" command tu publish or update an item in a non-interactive way (while "edit" do it interactively).
Goffi <goffi@goffi.org>
parents:
2416
diff
changeset
|
758 |
6908fe4c6eca
jp (pubsub): added new "set" command tu publish or update an item in a non-interactive way (while "edit" do it interactively).
Goffi <goffi@goffi.org>
parents:
2416
diff
changeset
|
759 def add_parser_options(self): |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
760 NodeCreate.add_node_config_options(self.parser) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
761 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
762 "item", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
763 nargs="?", |
3028 | 764 default="", |
765 help=_("id, URL of the item to update, keyword, or nothing for new item"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
766 ) |
2439
6908fe4c6eca
jp (pubsub): added new "set" command tu publish or update an item in a non-interactive way (while "edit" do it interactively).
Goffi <goffi@goffi.org>
parents:
2416
diff
changeset
|
767 |
3040 | 768 async def start(self): |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
769 element, etree = xml_tools.etreeParse(self, sys.stdin) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
770 element = xml_tools.getPayload(self, element) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
771 payload = etree.tostring(element, encoding="unicode") |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
772 extra = {} |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
773 publish_options = NodeCreate.get_config_options(self.args) |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
774 if publish_options: |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
775 extra['publish_options'] = publish_options |
2439
6908fe4c6eca
jp (pubsub): added new "set" command tu publish or update an item in a non-interactive way (while "edit" do it interactively).
Goffi <goffi@goffi.org>
parents:
2416
diff
changeset
|
776 |
3040 | 777 try: |
778 published_id = await self.host.bridge.psItemSend( | |
779 self.args.service, | |
780 self.args.node, | |
781 payload, | |
782 self.args.item, | |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
783 data_format.serialise(extra), |
3040 | 784 self.profile, |
785 ) | |
786 except Exception as e: | |
787 self.disp(_(f"can't send item: {e}"), error=True) | |
788 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
789 else: | |
790 if published_id: | |
3412
7b4ae3dbc041
jp (base, pubsub/set): new `--quiet` argument:
Goffi <goffi@goffi.org>
parents:
3411
diff
changeset
|
791 if self.args.quiet: |
7b4ae3dbc041
jp (base, pubsub/set): new `--quiet` argument:
Goffi <goffi@goffi.org>
parents:
3411
diff
changeset
|
792 self.disp(published_id, end='') |
7b4ae3dbc041
jp (base, pubsub/set): new `--quiet` argument:
Goffi <goffi@goffi.org>
parents:
3411
diff
changeset
|
793 else: |
7b4ae3dbc041
jp (base, pubsub/set): new `--quiet` argument:
Goffi <goffi@goffi.org>
parents:
3411
diff
changeset
|
794 self.disp(f"Item published at {published_id}") |
3040 | 795 else: |
796 self.disp("Item published") | |
797 self.host.quit(C.EXIT_OK) | |
2439
6908fe4c6eca
jp (pubsub): added new "set" command tu publish or update an item in a non-interactive way (while "edit" do it interactively).
Goffi <goffi@goffi.org>
parents:
2416
diff
changeset
|
798 |
6908fe4c6eca
jp (pubsub): added new "set" command tu publish or update an item in a non-interactive way (while "edit" do it interactively).
Goffi <goffi@goffi.org>
parents:
2416
diff
changeset
|
799 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
800 class Get(base.CommandBase): |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
801 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
802 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
803 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
804 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
805 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
806 use_output=C.OUTPUT_LIST_XML, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
807 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
808 pubsub_flags={C.NODE, C.MULTI_ITEMS}, |
3028 | 809 help=_("get pubsub item(s)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
810 ) |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
811 |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
812 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
813 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
814 "-S", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
815 "--sub-id", |
3028 | 816 default="", |
817 help=_("subscription id"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
818 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
819 # TODO: a key(s) argument to select keys to display |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
820 # TODO: add MAM filters |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
821 |
3040 | 822 async def start(self): |
823 try: | |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
824 ps_result = data_format.deserialise( |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
825 await self.host.bridge.psItemsGet( |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
826 self.args.service, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
827 self.args.node, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
828 self.args.max, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
829 self.args.items, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
830 self.args.sub_id, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
831 self.getPubsubExtra(), |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
832 self.profile, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
833 ) |
3040 | 834 ) |
3413
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
835 except BridgeException as e: |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
836 if e.condition == 'item-not-found' or e.classname=="NotFound": |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
837 self.disp( |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
838 f"The node {self.args.node} doesn't exist on {self.args.service}", |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
839 error=True |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
840 ) |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
841 self.host.quit(C.EXIT_NOT_FOUND) |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
842 else: |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
843 self.disp(f"can't get pubsub items: {e}", error=True) |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
844 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
3040 | 845 except Exception as e: |
3413
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
846 self.disp(f"Internal error: {e}", error=True) |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
847 self.host.quit(C.EXIT_INTERNAL_ERROR) |
3040 | 848 else: |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
849 await self.output(ps_result['items']) |
3040 | 850 self.host.quit(C.EXIT_OK) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
851 |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
852 |
2281
4af1805cc6df
jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents:
2280
diff
changeset
|
853 class Delete(base.CommandBase): |
4af1805cc6df
jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents:
2280
diff
changeset
|
854 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
855 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
856 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
857 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
858 "delete", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
859 use_pubsub=True, |
2910
b2f323237fce
jp, plugin merge-requests: used u'' as default for item id in pubsub arguments + fixed some required arguments:
Goffi <goffi@goffi.org>
parents:
2805
diff
changeset
|
860 pubsub_flags={C.NODE, C.ITEM, C.SINGLE_ITEM}, |
3028 | 861 help=_("delete an item"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
862 ) |
2281
4af1805cc6df
jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents:
2280
diff
changeset
|
863 |
4af1805cc6df
jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents:
2280
diff
changeset
|
864 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
865 self.parser.add_argument( |
3028 | 866 "-f", "--force", action="store_true", help=_("delete without confirmation") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
867 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
868 self.parser.add_argument( |
3028 | 869 "-N", "--notify", action="store_true", help=_("notify deletion") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
870 ) |
2281
4af1805cc6df
jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents:
2280
diff
changeset
|
871 |
3040 | 872 async def start(self): |
2281
4af1805cc6df
jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents:
2280
diff
changeset
|
873 if not self.args.item: |
3028 | 874 self.parser.error(_("You need to specify an item to delete")) |
2281
4af1805cc6df
jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents:
2280
diff
changeset
|
875 if not self.args.force: |
3028 | 876 message = _("Are you sure to delete item {item_id} ?").format( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
877 item_id=self.args.item |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
878 ) |
3040 | 879 await self.host.confirmOrQuit(message, _("item deletion cancelled")) |
880 try: | |
3467
5901a7170528
plugin XEP-0060: renamed `psRetractItem(s)` to `psItem(s)Retract` for consistency.
Goffi <goffi@goffi.org>
parents:
3453
diff
changeset
|
881 await self.host.bridge.psItemRetract( |
3040 | 882 self.args.service, |
883 self.args.node, | |
884 self.args.item, | |
885 self.args.notify, | |
886 self.profile, | |
887 ) | |
888 except Exception as e: | |
889 self.disp(_(f"can't delete item: {e}"), error=True) | |
890 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
891 else: | |
892 self.disp(_(f"item {self.args.item} has been deleted")) | |
893 self.host.quit(C.EXIT_OK) | |
2281
4af1805cc6df
jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents:
2280
diff
changeset
|
894 |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
895 |
2275
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
896 class Edit(base.CommandBase, common.BaseEdit): |
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
897 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
898 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
899 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
900 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
901 "edit", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
902 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
903 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
904 pubsub_flags={C.NODE, C.SINGLE_ITEM}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
905 use_draft=True, |
3028 | 906 help=_("edit an existing or new pubsub item"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
907 ) |
2275
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
908 common.BaseEdit.__init__(self, self.host, PUBSUB_TMP_DIR) |
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
909 |
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
910 def add_parser_options(self): |
2532 | 911 pass |
2275
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
912 |
3040 | 913 async def publish(self, content): |
914 published_id = await self.host.bridge.psItemSend( | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
915 self.pubsub_service, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
916 self.pubsub_node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
917 content, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
918 self.pubsub_item or "", |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
919 "", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
920 self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
921 ) |
2275
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
922 if published_id: |
3028 | 923 self.disp("Item published at {pub_id}".format(pub_id=published_id)) |
2275
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
924 else: |
3028 | 925 self.disp("Item published") |
2275
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
926 |
3040 | 927 async def getItemData(self, service, node, item): |
2275
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
928 try: |
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
929 from lxml import etree |
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
930 except ImportError: |
3028 | 931 self.disp('lxml module must be installed to use edit, please install it ' |
932 'with "pip install lxml"', | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
933 error=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
934 ) |
2275
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
935 self.host.quit(1) |
2910
b2f323237fce
jp, plugin merge-requests: used u'' as default for item id in pubsub arguments + fixed some required arguments:
Goffi <goffi@goffi.org>
parents:
2805
diff
changeset
|
936 items = [item] if item else [] |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
937 ps_result = data_format.deserialise( |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
938 await self.host.bridge.psItemsGet( |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
939 service, node, 1, items, "", {}, self.profile |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
940 ) |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
941 ) |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
942 item_raw = ps_result['items'][0] |
3040 | 943 parser = etree.XMLParser(remove_blank_text=True, recover=True) |
2275
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
944 item_elt = etree.fromstring(item_raw, parser) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
945 item_id = item_elt.get("id") |
2275
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
946 try: |
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
947 payload = item_elt[0] |
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
948 except IndexError: |
3028 | 949 self.disp(_("Item has not payload"), 1) |
3275
55eeb0dfd313
jp (pubsub): fixed arguments returned when item has no payload
Goffi <goffi@goffi.org>
parents:
3137
diff
changeset
|
950 return "", item_id |
2280
4bc9a2c2d6c9
jp (pubsub, common): fixed last item edition (keep item id instead of creating a new one)
Goffi <goffi@goffi.org>
parents:
2279
diff
changeset
|
951 return etree.tostring(payload, encoding="unicode", pretty_print=True), item_id |
2275
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
952 |
3040 | 953 async def start(self): |
954 (self.pubsub_service, | |
955 self.pubsub_node, | |
956 self.pubsub_item, | |
957 content_file_path, | |
958 content_file_obj) = await self.getItemPath() | |
959 await self.runEditor("pubsub_editor_args", content_file_path, content_file_obj) | |
960 self.host.quit() | |
2275
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
961 |
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
962 |
3521
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
963 class Rename(base.CommandBase): |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
964 |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
965 def __init__(self, host): |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
966 base.CommandBase.__init__( |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
967 self, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
968 host, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
969 "rename", |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
970 use_pubsub=True, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
971 pubsub_flags={C.NODE, C.SINGLE_ITEM}, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
972 help=_("rename a pubsub item"), |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
973 ) |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
974 |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
975 def add_parser_options(self): |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
976 self.parser.add_argument( |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
977 "new_id", |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
978 help=_("new item id to use") |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
979 ) |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
980 |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
981 async def start(self): |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
982 try: |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
983 await self.host.bridge.psItemRename( |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
984 self.args.service, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
985 self.args.node, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
986 self.args.item, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
987 self.args.new_id, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
988 self.profile, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
989 ) |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
990 except Exception as e: |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
991 self.disp( |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
992 f"can't rename item: {e}", error=True |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
993 ) |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
994 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
995 else: |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
996 self.disp("Item renamed") |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
997 self.host.quit(C.EXIT_OK) |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
998 |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
999 |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1000 class Subscribe(base.CommandBase): |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1001 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1002 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1003 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1004 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1005 "subscribe", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1006 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1007 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1008 use_verbose=True, |
3028 | 1009 help=_("subscribe to a node"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1010 ) |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1011 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1012 def add_parser_options(self): |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1013 pass |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1014 |
3040 | 1015 async def start(self): |
1016 try: | |
1017 sub_id = await self.host.bridge.psSubscribe( | |
1018 self.args.service, | |
1019 self.args.node, | |
1020 {}, | |
1021 self.profile, | |
1022 ) | |
1023 except Exception as e: | |
1024 self.disp(_(f"can't subscribe to node: {e}"), error=True) | |
1025 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
1026 else: | |
1027 self.disp(_("subscription done"), 1) | |
1028 if sub_id: | |
1029 self.disp(_("subscription id: {sub_id}").format(sub_id=sub_id)) | |
1030 self.host.quit() | |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1031 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1032 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1033 class Unsubscribe(base.CommandBase): |
3040 | 1034 # FIXME: check why we get a a NodeNotFound on subscribe just after unsubscribe |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1035 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1036 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1037 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1038 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1039 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1040 "unsubscribe", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1041 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1042 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1043 use_verbose=True, |
3028 | 1044 help=_("unsubscribe from a node"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1045 ) |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1046 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1047 def add_parser_options(self): |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1048 pass |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1049 |
3040 | 1050 async def start(self): |
1051 try: | |
1052 await self.host.bridge.psUnsubscribe( | |
1053 self.args.service, | |
1054 self.args.node, | |
1055 self.profile, | |
1056 ) | |
1057 except Exception as e: | |
1058 self.disp(_(f"can't unsubscribe from node: {e}"), error=True) | |
1059 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
1060 else: | |
1061 self.disp(_("subscription removed"), 1) | |
1062 self.host.quit() | |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1063 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1064 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1065 class Subscriptions(base.CommandBase): |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1066 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1067 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1068 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1069 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1070 "subscriptions", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1071 use_output=C.OUTPUT_LIST_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1072 use_pubsub=True, |
3028 | 1073 help=_("retrieve all subscriptions on a service"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1074 ) |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1075 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1076 def add_parser_options(self): |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1077 pass |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1078 |
3040 | 1079 async def start(self): |
1080 try: | |
1081 subscriptions = await self.host.bridge.psSubscriptionsGet( | |
1082 self.args.service, | |
1083 self.args.node, | |
1084 self.profile, | |
1085 ) | |
1086 except Exception as e: | |
1087 self.disp(_(f"can't retrieve subscriptions: {e}"), error=True) | |
1088 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
1089 else: | |
1090 await self.output(subscriptions) | |
1091 self.host.quit() | |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1092 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1093 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
1094 class Affiliations(base.CommandBase): |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
1095 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1096 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1097 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1098 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1099 "affiliations", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1100 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1101 use_pubsub=True, |
3028 | 1102 help=_("retrieve all affiliations on a service"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1103 ) |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
1104 |
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
1105 def add_parser_options(self): |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
1106 pass |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
1107 |
3040 | 1108 async def start(self): |
1109 try: | |
1110 affiliations = await self.host.bridge.psAffiliationsGet( | |
1111 self.args.service, | |
1112 self.args.node, | |
1113 self.profile, | |
1114 ) | |
1115 except Exception as e: | |
1116 self.disp( | |
1117 f"can't get node affiliations: {e}", error=True | |
1118 ) | |
1119 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
1120 else: | |
1121 await self.output(affiliations) | |
1122 self.host.quit() | |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
1123 |
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
1124 |
2316 | 1125 class Search(base.CommandBase): |
3040 | 1126 """This command do a search without using MAM |
2764
92af49cde255
jp (base): MAM and RSM arguments can now be used for pubsub commands:
Goffi <goffi@goffi.org>
parents:
2761
diff
changeset
|
1127 |
92af49cde255
jp (base): MAM and RSM arguments can now be used for pubsub commands:
Goffi <goffi@goffi.org>
parents:
2761
diff
changeset
|
1128 This commands checks every items it finds by itself, |
92af49cde255
jp (base): MAM and RSM arguments can now be used for pubsub commands:
Goffi <goffi@goffi.org>
parents:
2761
diff
changeset
|
1129 so it may be heavy in resources both for server and client |
92af49cde255
jp (base): MAM and RSM arguments can now be used for pubsub commands:
Goffi <goffi@goffi.org>
parents:
2761
diff
changeset
|
1130 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1131 |
2316 | 1132 RE_FLAGS = re.MULTILINE | re.UNICODE |
3028 | 1133 EXEC_ACTIONS = ("exec", "external") |
2316 | 1134 |
1135 def __init__(self, host): | |
2764
92af49cde255
jp (base): MAM and RSM arguments can now be used for pubsub commands:
Goffi <goffi@goffi.org>
parents:
2761
diff
changeset
|
1136 # FIXME: C.NO_MAX is not needed here, and this can be globally removed from consts |
92af49cde255
jp (base): MAM and RSM arguments can now be used for pubsub commands:
Goffi <goffi@goffi.org>
parents:
2761
diff
changeset
|
1137 # the only interest is to change the help string, but this can be explained |
92af49cde255
jp (base): MAM and RSM arguments can now be used for pubsub commands:
Goffi <goffi@goffi.org>
parents:
2761
diff
changeset
|
1138 # extensively in man pages (max is for each node found) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1139 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1140 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1141 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1142 "search", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1143 use_output=C.OUTPUT_XML, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1144 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1145 pubsub_flags={C.MULTI_ITEMS, C.NO_MAX}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1146 use_verbose=True, |
3028 | 1147 help=_("search items corresponding to filters"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1148 ) |
2316 | 1149 |
1150 @property | |
1151 def etree(self): | |
1152 """load lxml.etree only if needed""" | |
1153 if self._etree is None: | |
1154 from lxml import etree | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1155 |
2316 | 1156 self._etree = etree |
1157 return self._etree | |
1158 | |
1159 def filter_opt(self, value, type_): | |
1160 return (type_, value) | |
1161 | |
1162 def filter_flag(self, value, type_): | |
1163 value = C.bool(value) | |
1164 return (type_, value) | |
1165 | |
1166 def add_parser_options(self): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1167 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1168 "-D", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1169 "--max-depth", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1170 type=int, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1171 default=0, |
3028 | 1172 help=_("maximum depth of recursion (will search linked nodes if > 0, " |
1173 "DEFAULT: 0)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1174 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1175 self.parser.add_argument( |
2764
92af49cde255
jp (base): MAM and RSM arguments can now be used for pubsub commands:
Goffi <goffi@goffi.org>
parents:
2761
diff
changeset
|
1176 "-M", |
92af49cde255
jp (base): MAM and RSM arguments can now be used for pubsub commands:
Goffi <goffi@goffi.org>
parents:
2761
diff
changeset
|
1177 "--node-max", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1178 type=int, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1179 default=30, |
3028 | 1180 help=_("maximum number of items to get per node ({} to get all items, " |
1181 "DEFAULT: 30)".format( C.NO_LIMIT)), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1182 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1183 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1184 "-N", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1185 "--namespace", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1186 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1187 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1188 default=[], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1189 metavar="NAME NAMESPACE", |
3028 | 1190 help=_("namespace to use for xpath"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1191 ) |
2316 | 1192 |
1193 # filters | |
3028 | 1194 filter_text = partial(self.filter_opt, type_="text") |
1195 filter_re = partial(self.filter_opt, type_="regex") | |
1196 filter_xpath = partial(self.filter_opt, type_="xpath") | |
1197 filter_python = partial(self.filter_opt, type_="python") | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1198 filters = self.parser.add_argument_group( |
3028 | 1199 _("filters"), |
1200 _("only items corresponding to following filters will be kept"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1201 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1202 filters.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1203 "-t", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1204 "--text", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1205 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1206 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1207 type=filter_text, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1208 metavar="TEXT", |
3028 | 1209 help=_("full text filter, item must contain this string (XML included)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1210 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1211 filters.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1212 "-r", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1213 "--regex", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1214 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1215 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1216 type=filter_re, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1217 metavar="EXPRESSION", |
3028 | 1218 help=_("like --text but using a regular expression"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1219 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1220 filters.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1221 "-x", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1222 "--xpath", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1223 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1224 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1225 type=filter_xpath, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1226 metavar="XPATH", |
3028 | 1227 help=_("filter items which has elements matching this xpath"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1228 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1229 filters.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1230 "-P", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1231 "--python", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1232 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1233 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1234 type=filter_python, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1235 metavar="PYTHON_CODE", |
3028 | 1236 help=_('Python expression which much return a bool (True to keep item, ' |
1237 'False to reject it). "item" is raw text item, "item_xml" is ' | |
1238 'lxml\'s etree.Element' | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1239 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1240 ) |
2316 | 1241 |
1242 # filters flags | |
3028 | 1243 flag_case = partial(self.filter_flag, type_="ignore-case") |
1244 flag_invert = partial(self.filter_flag, type_="invert") | |
1245 flag_dotall = partial(self.filter_flag, type_="dotall") | |
1246 flag_matching = partial(self.filter_flag, type_="only-matching") | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1247 flags = self.parser.add_argument_group( |
3028 | 1248 _("filters flags"), |
1249 _("filters modifiers (change behaviour of following filters)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1250 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1251 flags.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1252 "-C", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1253 "--ignore-case", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1254 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1255 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1256 type=flag_case, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1257 const=("ignore-case", True), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1258 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1259 metavar="BOOLEAN", |
3028 | 1260 help=_("(don't) ignore case in following filters (DEFAULT: case sensitive)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1261 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1262 flags.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1263 "-I", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1264 "--invert", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1265 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1266 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1267 type=flag_invert, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1268 const=("invert", True), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1269 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1270 metavar="BOOLEAN", |
3028 | 1271 help=_("(don't) invert effect of following filters (DEFAULT: don't invert)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1272 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1273 flags.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1274 "-A", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1275 "--dot-all", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1276 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1277 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1278 type=flag_dotall, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1279 const=("dotall", True), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1280 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1281 metavar="BOOLEAN", |
3028 | 1282 help=_("(don't) use DOTALL option for regex (DEFAULT: don't use)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1283 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1284 flags.add_argument( |
2764
92af49cde255
jp (base): MAM and RSM arguments can now be used for pubsub commands:
Goffi <goffi@goffi.org>
parents:
2761
diff
changeset
|
1285 "-k", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1286 "--only-matching", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1287 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1288 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1289 type=flag_matching, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1290 const=("only-matching", True), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1291 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1292 metavar="BOOLEAN", |
3028 | 1293 help=_("keep only the matching part of the item"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1294 ) |
2316 | 1295 |
1296 # action | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1297 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1298 "action", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1299 default="print", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1300 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1301 choices=("print", "exec", "external"), |
3028 | 1302 help=_("action to do on found items (DEFAULT: print)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1303 ) |
2316 | 1304 self.parser.add_argument("command", nargs=argparse.REMAINDER) |
1305 | |
3040 | 1306 async def getItems(self, depth, service, node, items): |
2316 | 1307 self.to_get += 1 |
3040 | 1308 try: |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1309 ps_result = data_format.deserialise( |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1310 await self.host.bridge.psItemsGet( |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1311 service, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1312 node, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1313 self.args.node_max, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1314 items, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1315 "", |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1316 self.getPubsubExtra(), |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1317 self.profile, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1318 ) |
3040 | 1319 ) |
1320 except Exception as e: | |
1321 self.disp( | |
1322 f"can't get pubsub items at {service} (node: {node}): {e}", | |
1323 error=True, | |
1324 ) | |
1325 self.to_get -= 1 | |
1326 else: | |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1327 await self.search(ps_result, depth) |
2316 | 1328 |
1329 def _checkPubsubURL(self, match, found_nodes): | |
1330 """check that the matched URL is an xmpp: one | |
1331 | |
1332 @param found_nodes(list[unicode]): found_nodes | |
1333 this list will be filled while xmpp: URIs are discovered | |
1334 """ | |
1335 url = match.group(0) | |
3028 | 1336 if url.startswith("xmpp"): |
2316 | 1337 try: |
1338 url_data = uri.parseXMPPUri(url) | |
1339 except ValueError: | |
1340 return | |
3028 | 1341 if url_data["type"] == "pubsub": |
1342 found_node = {"service": url_data["path"], "node": url_data["node"]} | |
1343 if "item" in url_data: | |
1344 found_node["item"] = url_data["item"] | |
2316 | 1345 found_nodes.append(found_node) |
1346 | |
3040 | 1347 async def getSubNodes(self, item, depth): |
2316 | 1348 """look for pubsub URIs in item, and getItems on the linked nodes""" |
1349 found_nodes = [] | |
1350 checkURI = partial(self._checkPubsubURL, found_nodes=found_nodes) | |
1351 strings.RE_URL.sub(checkURI, item) | |
1352 for data in found_nodes: | |
3040 | 1353 await self.getItems( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1354 depth + 1, |
3028 | 1355 data["service"], |
1356 data["node"], | |
1357 [data["item"]] if "item" in data else [], | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1358 ) |
2316 | 1359 |
1360 def parseXml(self, item): | |
1361 try: | |
1362 return self.etree.fromstring(item) | |
1363 except self.etree.XMLSyntaxError: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1364 self.disp( |
3028 | 1365 _("item doesn't looks like XML, you have probably used --only-matching " |
1366 "somewhere before and we have no more XML"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1367 error=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1368 ) |
2316 | 1369 self.host.quit(C.EXIT_BAD_ARG) |
1370 | |
1371 def filter(self, item): | |
1372 """apply filters given on command line | |
1373 | |
1374 if only-matching is used, item may be modified | |
1375 @return (tuple[bool, unicode]): a tuple with: | |
1376 - keep: True if item passed the filters | |
1377 - item: it is returned in case of modifications | |
1378 """ | |
1379 ignore_case = False | |
1380 invert = False | |
1381 dotall = False | |
1382 only_matching = False | |
1383 item_xml = None | |
1384 for type_, value in self.args.filters: | |
1385 keep = True | |
1386 | |
1387 ## filters | |
1388 | |
3028 | 1389 if type_ == "text": |
2316 | 1390 if ignore_case: |
1391 if value.lower() not in item.lower(): | |
1392 keep = False | |
1393 else: | |
1394 if value not in item: | |
1395 keep = False | |
1396 if keep and only_matching: | |
1397 # doesn't really make sens to keep a fixed string | |
1398 # so we raise an error | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1399 self.host.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1400 _( |
3028 | 1401 "--only-matching used with fixed --text string, are you sure?" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1402 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1403 error=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1404 ) |
2316 | 1405 self.host.quit(C.EXIT_BAD_ARG) |
3028 | 1406 elif type_ == "regex": |
2316 | 1407 flags = self.RE_FLAGS |
1408 if ignore_case: | |
1409 flags |= re.IGNORECASE | |
1410 if dotall: | |
1411 flags |= re.DOTALL | |
1412 match = re.search(value, item, flags) | |
1413 keep = match != None | |
1414 if keep and only_matching: | |
1415 item = match.group() | |
1416 item_xml = None | |
3028 | 1417 elif type_ == "xpath": |
2316 | 1418 if item_xml is None: |
1419 item_xml = self.parseXml(item) | |
1420 try: | |
1421 elts = item_xml.xpath(value, namespaces=self.args.namespace) | |
1422 except self.etree.XPathEvalError as e: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1423 self.disp( |
3028 | 1424 _("can't use xpath: {reason}").format(reason=e), error=True |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1425 ) |
2316 | 1426 self.host.quit(C.EXIT_BAD_ARG) |
1427 keep = bool(elts) | |
1428 if keep and only_matching: | |
1429 item_xml = elts[0] | |
1430 try: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1431 item = self.etree.tostring(item_xml, encoding="unicode") |
2316 | 1432 except TypeError: |
1433 # we have a string only, not an element | |
3028 | 1434 item = str(item_xml) |
2316 | 1435 item_xml = None |
3028 | 1436 elif type_ == "python": |
2316 | 1437 if item_xml is None: |
1438 item_xml = self.parseXml(item) | |
3040 | 1439 cmd_ns = { |
1440 "etree": self.etree, | |
1441 "item": item, | |
1442 "item_xml": item_xml | |
1443 } | |
2316 | 1444 try: |
1445 keep = eval(value, cmd_ns) | |
1446 except SyntaxError as e: | |
3028 | 1447 self.disp(str(e), error=True) |
2316 | 1448 self.host.quit(C.EXIT_BAD_ARG) |
1449 | |
1450 ## flags | |
1451 | |
3028 | 1452 elif type_ == "ignore-case": |
2316 | 1453 ignore_case = value |
3028 | 1454 elif type_ == "invert": |
2316 | 1455 invert = value |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1456 # we need to continue, else loop would end here |
2316 | 1457 continue |
3028 | 1458 elif type_ == "dotall": |
2316 | 1459 dotall = value |
3028 | 1460 elif type_ == "only-matching": |
2316 | 1461 only_matching = value |
1462 else: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1463 raise exceptions.InternalError( |
3028 | 1464 _("unknown filter type {type}").format(type=type_) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1465 ) |
2316 | 1466 |
1467 if invert: | |
1468 keep = not keep | |
1469 if not keep: | |
1470 return False, item | |
1471 | |
1472 return True, item | |
1473 | |
3040 | 1474 async def doItemAction(self, item, metadata): |
2316 | 1475 """called when item has been kepts and the action need to be done |
1476 | |
1477 @param item(unicode): accepted item | |
1478 """ | |
1479 action = self.args.action | |
3028 | 1480 if action == "print" or self.host.verbosity > 0: |
2316 | 1481 try: |
3040 | 1482 await self.output(item) |
2316 | 1483 except self.etree.XMLSyntaxError: |
1484 # item is not valid XML, but a string | |
1485 # can happen when --only-matching is used | |
1486 self.disp(item) | |
1487 if action in self.EXEC_ACTIONS: | |
1488 item_elt = self.parseXml(item) | |
3028 | 1489 if action == "exec": |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1490 use = { |
3028 | 1491 "service": metadata["service"], |
1492 "node": metadata["node"], | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1493 "item": item_elt.get("id"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1494 "profile": self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1495 } |
2317
f4e05600577b
jp (arg_tools): args is not modified anymore in get_use_args + fixed args returned + parser_args are returned separatly (return is now a tuple)
Goffi <goffi@goffi.org>
parents:
2316
diff
changeset
|
1496 # we need to send a copy of self.args.command |
f4e05600577b
jp (arg_tools): args is not modified anymore in get_use_args + fixed args returned + parser_args are returned separatly (return is now a tuple)
Goffi <goffi@goffi.org>
parents:
2316
diff
changeset
|
1497 # else it would be modified |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1498 parser_args, use_args = arg_tools.get_use_args( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1499 self.host, self.args.command, use, verbose=self.host.verbosity > 1 |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1500 ) |
2317
f4e05600577b
jp (arg_tools): args is not modified anymore in get_use_args + fixed args returned + parser_args are returned separatly (return is now a tuple)
Goffi <goffi@goffi.org>
parents:
2316
diff
changeset
|
1501 cmd_args = sys.argv[0:1] + parser_args + use_args |
2316 | 1502 else: |
1503 cmd_args = self.args.command | |
1504 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1505 self.disp( |
3028 | 1506 "COMMAND: {command}".format( |
1507 command=" ".join([arg_tools.escape(a) for a in cmd_args]) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1508 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1509 2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1510 ) |
3028 | 1511 if action == "exec": |
3040 | 1512 p = await asyncio.create_subprocess_exec(*cmd_args) |
1513 ret = await p.wait() | |
2316 | 1514 else: |
3040 | 1515 p = await asyncio.create_subprocess_exec(*cmd_args, |
1516 stdin=subprocess.PIPE) | |
1517 await p.communicate(item.encode(sys.getfilesystemencoding())) | |
1518 ret = p.returncode | |
2316 | 1519 if ret != 0: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1520 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1521 A.color( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1522 C.A_FAILURE, |
3040 | 1523 _(f"executed command failed with exit code {ret}"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1524 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1525 ) |
2316 | 1526 |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1527 async def search(self, ps_result, depth): |
2316 | 1528 """callback of getItems |
1529 | |
1530 this method filters items, get sub nodes if needed, | |
1531 do the requested action, and exit the command when everything is done | |
1532 @param items_data(tuple): result of getItems | |
1533 @param depth(int): current depth level | |
1534 0 for first node, 1 for first children, and so on | |
1535 """ | |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1536 for item in ps_result['items']: |
2316 | 1537 if depth < self.args.max_depth: |
3040 | 1538 await self.getSubNodes(item, depth) |
2316 | 1539 keep, item = self.filter(item) |
1540 if not keep: | |
1541 continue | |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1542 await self.doItemAction(item, ps_result) |
2316 | 1543 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1544 # we check if we got all getItems results |
2316 | 1545 self.to_get -= 1 |
1546 if self.to_get == 0: | |
1547 # yes, we can quit | |
1548 self.host.quit() | |
1549 assert self.to_get > 0 | |
1550 | |
3040 | 1551 async def start(self): |
2316 | 1552 if self.args.command: |
1553 if self.args.action not in self.EXEC_ACTIONS: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1554 self.parser.error( |
3028 | 1555 _("Command can only be used with {actions} actions").format( |
1556 actions=", ".join(self.EXEC_ACTIONS) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1557 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1558 ) |
2316 | 1559 else: |
1560 if self.args.action in self.EXEC_ACTIONS: | |
3028 | 1561 self.parser.error(_("you need to specify a command to execute")) |
2316 | 1562 if not self.args.node: |
1563 # TODO: handle get service affiliations when node is not set | |
3028 | 1564 self.parser.error(_("empty node is not handled yet")) |
2316 | 1565 # to_get is increased on each get and decreased on each answer |
1566 # when it reach 0 again, the command is finished | |
1567 self.to_get = 0 | |
1568 self._etree = None | |
1569 if self.args.filters is None: | |
1570 self.args.filters = [] | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1571 self.args.namespace = dict( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1572 self.args.namespace + [("pubsub", "http://jabber.org/protocol/pubsub")] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1573 ) |
3040 | 1574 await self.getItems(0, self.args.service, self.args.node, self.args.items) |
2316 | 1575 |
1576 | |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1577 class Transform(base.CommandBase): |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1578 def __init__(self, host): |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1579 base.CommandBase.__init__( |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1580 self, |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1581 host, |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1582 "transform", |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1583 use_pubsub=True, |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1584 pubsub_flags={C.NODE, C.MULTI_ITEMS}, |
3028 | 1585 help=_("modify items of a node using an external command/script"), |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1586 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1587 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1588 def add_parser_options(self): |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1589 self.parser.add_argument( |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1590 "--apply", |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1591 action="store_true", |
3028 | 1592 help=_("apply transformation (DEFAULT: do a dry run)"), |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1593 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1594 self.parser.add_argument( |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1595 "--admin", |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1596 action="store_true", |
3028 | 1597 help=_("do a pubsub admin request, needed to change publisher"), |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1598 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1599 self.parser.add_argument( |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1600 "-I", |
3411
f30b238d9c45
jp: follow best practices and use a dash (`-`) instead of underscore (`_`) for long options.
Goffi <goffi@goffi.org>
parents:
3325
diff
changeset
|
1601 "--ignore-errors", |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1602 action="store_true", |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1603 help=_( |
3028 | 1604 "if command return a non zero exit code, ignore the item and continue"), |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1605 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1606 self.parser.add_argument( |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1607 "-A", |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1608 "--all", |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1609 action="store_true", |
3028 | 1610 help=_("get all items by looping over all pages using RSM") |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1611 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1612 self.parser.add_argument( |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1613 "command_path", |
3028 | 1614 help=_("path to the command to use. Will be called repetitivly with an " |
1615 "item as input. Output (full item XML) will be used as new one. " | |
1616 'Return "DELETE" string to delete the item, and "SKIP" to ignore it'), | |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1617 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1618 |
3040 | 1619 async def psItemsSendCb(self, item_ids, metadata): |
2803
d4a9a60bc650
jp (pubsub/transform): use new psItemsSend method, it is not needed anymore to send items one by one when --admin is not used
Goffi <goffi@goffi.org>
parents:
2802
diff
changeset
|
1620 if item_ids: |
3028 | 1621 self.disp(_('items published with ids {item_ids}').format( |
1622 item_ids=', '.join(item_ids))) | |
2803
d4a9a60bc650
jp (pubsub/transform): use new psItemsSend method, it is not needed anymore to send items one by one when --admin is not used
Goffi <goffi@goffi.org>
parents:
2802
diff
changeset
|
1623 else: |
3028 | 1624 self.disp(_('items published')) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1625 if self.args.all: |
3040 | 1626 return await self.handleNextPage(metadata) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1627 else: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1628 self.host.quit() |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1629 |
3040 | 1630 async def handleNextPage(self, metadata): |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1631 """Retrieve new page through RSM or quit if we're in the last page |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1632 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1633 use to handle --all option |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1634 @param metadata(dict): metadata as returned by psItemsGet |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1635 """ |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1636 try: |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1637 last = metadata['rsm']['last'] |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1638 index = int(metadata['rsm']['index']) |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1639 count = int(metadata['rsm']['count']) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1640 except KeyError: |
3028 | 1641 self.disp(_("Can't retrieve all items, RSM metadata not available"), |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1642 error=True) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1643 self.host.quit(C.EXIT_MISSING_FEATURE) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1644 except ValueError as e: |
3028 | 1645 self.disp(_("Can't retrieve all items, bad RSM metadata: {msg}") |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1646 .format(msg=e), error=True) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1647 self.host.quit(C.EXIT_ERROR) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1648 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1649 if index + self.args.rsm_max >= count: |
3028 | 1650 self.disp(_('All items transformed')) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1651 self.host.quit(0) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1652 |
3028 | 1653 self.disp(_('Retrieving next page ({page_idx}/{page_total})').format( |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1654 page_idx = int(index/self.args.rsm_max) + 1, |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1655 page_total = int(count/self.args.rsm_max), |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1656 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1657 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1658 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1659 extra = self.getPubsubExtra() |
3028 | 1660 extra['rsm_after'] = last |
3040 | 1661 try: |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1662 ps_result = await data_format.deserialise( |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1663 self.host.bridge.psItemsGet( |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1664 self.args.service, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1665 self.args.node, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1666 self.args.rsm_max, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1667 self.args.items, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1668 "", |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1669 extra, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1670 self.profile, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1671 ) |
3040 | 1672 ) |
1673 except Exception as e: | |
1674 self.disp( | |
1675 f"can't retrieve items: {e}", error=True | |
1676 ) | |
1677 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
1678 else: | |
1679 await self.psItemsGetCb(ps_result) | |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1680 |
3040 | 1681 async def psItemsGetCb(self, ps_result): |
1682 encoding = 'utf-8' | |
2803
d4a9a60bc650
jp (pubsub/transform): use new psItemsSend method, it is not needed anymore to send items one by one when --admin is not used
Goffi <goffi@goffi.org>
parents:
2802
diff
changeset
|
1683 new_items = [] |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1684 |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1685 for item in ps_result['items']: |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1686 if self.check_duplicates: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1687 # this is used when we are not ordering by creation |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1688 # to avoid infinite loop |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1689 item_elt, __ = xml_tools.etreeParse(self, item) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1690 item_id = item_elt.get('id') |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1691 if item_id in self.items_ids: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1692 self.disp(_( |
3028 | 1693 "Duplicate found on item {item_id}, we have probably handled " |
1694 "all items.").format(item_id=item_id)) | |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1695 self.host.quit() |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1696 self.items_ids.append(item_id) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1697 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1698 # we launch the command to filter the item |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1699 try: |
3040 | 1700 p = await asyncio.create_subprocess_exec( |
1701 self.args.command_path, | |
1702 stdin=subprocess.PIPE, | |
1703 stdout=subprocess.PIPE) | |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1704 except OSError as e: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1705 exit_code = C.EXIT_CMD_NOT_FOUND if e.errno == 2 else C.EXIT_ERROR |
3040 | 1706 self.disp(f"Can't execute the command: {e}", error=True) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1707 self.host.quit(exit_code) |
3040 | 1708 encoding = "utf-8" |
1709 cmd_std_out, cmd_std_err = await p.communicate(item.encode(encoding)) | |
1710 ret = p.returncode | |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1711 if ret != 0: |
3040 | 1712 self.disp(f"The command returned a non zero status while parsing the " |
1713 f"following item:\n\n{item}", error=True) | |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1714 if self.args.ignore_errors: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1715 continue |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1716 else: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1717 self.host.quit(C.EXIT_CMD_ERROR) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1718 if cmd_std_err is not None: |
3040 | 1719 cmd_std_err = cmd_std_err.decode(encoding, errors='ignore') |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1720 self.disp(cmd_std_err, error=True) |
3040 | 1721 cmd_std_out = cmd_std_out.decode(encoding).strip() |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1722 if cmd_std_out == "DELETE": |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1723 item_elt, __ = xml_tools.etreeParse(self, item) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1724 item_id = item_elt.get('id') |
3040 | 1725 self.disp(_(f"Deleting item {item_id}")) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1726 if self.args.apply: |
3040 | 1727 try: |
3467
5901a7170528
plugin XEP-0060: renamed `psRetractItem(s)` to `psItem(s)Retract` for consistency.
Goffi <goffi@goffi.org>
parents:
3453
diff
changeset
|
1728 await self.host.bridge.psItemRetract( |
3040 | 1729 self.args.service, |
1730 self.args.node, | |
1731 item_id, | |
1732 False, | |
1733 self.profile, | |
1734 ) | |
1735 except Exception as e: | |
1736 self.disp( | |
1737 f"can't delete item {item_id}: {e}", error=True | |
1738 ) | |
1739 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1740 continue |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1741 elif cmd_std_out == "SKIP": |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1742 item_elt, __ = xml_tools.etreeParse(self, item) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1743 item_id = item_elt.get('id') |
3028 | 1744 self.disp(_("Skipping item {item_id}").format(item_id=item_id)) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1745 continue |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1746 element, etree = xml_tools.etreeParse(self, cmd_std_out) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1747 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1748 # at this point command has been run and we have a etree.Element object |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1749 if element.tag not in ("item", "{http://jabber.org/protocol/pubsub}item"): |
3028 | 1750 self.disp("your script must return a whole item, this is not:\n{xml}" |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1751 .format(xml=etree.tostring(element, encoding="unicode")), error=True) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1752 self.host.quit(C.EXIT_DATA_ERROR) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1753 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1754 if not self.args.apply: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1755 # we have a dry run, we just display filtered items |
3028 | 1756 serialised = etree.tostring(element, encoding='unicode', |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1757 pretty_print=True) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1758 self.disp(serialised) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1759 else: |
2803
d4a9a60bc650
jp (pubsub/transform): use new psItemsSend method, it is not needed anymore to send items one by one when --admin is not used
Goffi <goffi@goffi.org>
parents:
2802
diff
changeset
|
1760 new_items.append(etree.tostring(element, encoding="unicode")) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1761 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1762 if not self.args.apply: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1763 # on dry run we have nothing to wait for, we can quit |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1764 if self.args.all: |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1765 return await self.handleNextPage(ps_result) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1766 self.host.quit() |
2803
d4a9a60bc650
jp (pubsub/transform): use new psItemsSend method, it is not needed anymore to send items one by one when --admin is not used
Goffi <goffi@goffi.org>
parents:
2802
diff
changeset
|
1767 else: |
d4a9a60bc650
jp (pubsub/transform): use new psItemsSend method, it is not needed anymore to send items one by one when --admin is not used
Goffi <goffi@goffi.org>
parents:
2802
diff
changeset
|
1768 if self.args.admin: |
3040 | 1769 bridge_method = self.host.bridge.psAdminItemsSend |
1770 else: | |
1771 bridge_method = self.host.bridge.psItemsSend | |
1772 | |
1773 try: | |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1774 ps_items_send_result = await bridge_method( |
2803
d4a9a60bc650
jp (pubsub/transform): use new psItemsSend method, it is not needed anymore to send items one by one when --admin is not used
Goffi <goffi@goffi.org>
parents:
2802
diff
changeset
|
1775 self.args.service, |
d4a9a60bc650
jp (pubsub/transform): use new psItemsSend method, it is not needed anymore to send items one by one when --admin is not used
Goffi <goffi@goffi.org>
parents:
2802
diff
changeset
|
1776 self.args.node, |
d4a9a60bc650
jp (pubsub/transform): use new psItemsSend method, it is not needed anymore to send items one by one when --admin is not used
Goffi <goffi@goffi.org>
parents:
2802
diff
changeset
|
1777 new_items, |
3028 | 1778 "", |
2803
d4a9a60bc650
jp (pubsub/transform): use new psItemsSend method, it is not needed anymore to send items one by one when --admin is not used
Goffi <goffi@goffi.org>
parents:
2802
diff
changeset
|
1779 self.profile, |
d4a9a60bc650
jp (pubsub/transform): use new psItemsSend method, it is not needed anymore to send items one by one when --admin is not used
Goffi <goffi@goffi.org>
parents:
2802
diff
changeset
|
1780 ) |
3040 | 1781 except Exception as e: |
1782 self.disp(f"can't send item: {e}", error=True) | |
1783 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2803
d4a9a60bc650
jp (pubsub/transform): use new psItemsSend method, it is not needed anymore to send items one by one when --admin is not used
Goffi <goffi@goffi.org>
parents:
2802
diff
changeset
|
1784 else: |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1785 await self.psItemsSendCb(ps_items_send_result, metadata=ps_result) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1786 |
3040 | 1787 async def start(self): |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1788 if self.args.all and self.args.order_by != C.ORDER_BY_CREATION: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1789 self.check_duplicates = True |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1790 self.items_ids = [] |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1791 self.disp(A.color( |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1792 A.FG_RED, A.BOLD, |
3028 | 1793 '/!\\ "--all" should be used with "--order-by creation" /!\\\n', |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1794 A.RESET, |
3028 | 1795 "We'll update items, so order may change during transformation,\n" |
1796 "we'll try to mitigate that by stopping on first duplicate,\n" | |
1797 "but this method is not safe, and some items may be missed.\n---\n")) | |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1798 else: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1799 self.check_duplicates = False |
3040 | 1800 |
1801 try: | |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1802 ps_result = data_format.deserialise( |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1803 await self.host.bridge.psItemsGet( |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1804 self.args.service, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1805 self.args.node, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1806 self.args.max, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1807 self.args.items, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1808 "", |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1809 self.getPubsubExtra(), |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1810 self.profile, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1811 ) |
3040 | 1812 ) |
1813 except Exception as e: | |
1814 self.disp(f"can't retrieve items: {e}", error=True) | |
1815 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
1816 else: | |
1817 await self.psItemsGetCb(ps_result) | |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1818 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
1819 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
1820 class Uri(base.CommandBase): |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1821 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1822 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1823 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1824 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1825 "uri", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1826 use_profile=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1827 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1828 pubsub_flags={C.NODE, C.SINGLE_ITEM}, |
3028 | 1829 help=_("build URI"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1830 ) |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1831 |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1832 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1833 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1834 "-p", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1835 "--profile", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1836 default=C.PROF_KEY_DEFAULT, |
3028 | 1837 help=_("profile (used when no server is specified)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1838 ) |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1839 |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1840 def display_uri(self, jid_): |
2239
17502e74c046
jp (pubsub/uri): fixed URI generation
Goffi <goffi@goffi.org>
parents:
2235
diff
changeset
|
1841 uri_args = {} |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1842 if not self.args.service: |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1843 self.args.service = jid.JID(jid_).bare |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1844 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1845 for key in ("node", "service", "item"): |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1846 value = getattr(self.args, key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1847 if key == "service": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1848 key = "path" |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1849 if value: |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1850 uri_args[key] = value |
3028 | 1851 self.disp(uri.buildXMPPUri("pubsub", **uri_args)) |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1852 self.host.quit() |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1853 |
3040 | 1854 async def start(self): |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1855 if not self.args.service: |
3040 | 1856 try: |
1857 jid_ = await self.host.bridge.asyncGetParamA( | |
1858 "JabberID", | |
1859 "Connection", | |
1860 profile_key=self.args.profile | |
1861 ) | |
1862 except Exception as e: | |
1863 self.disp(f"can't retrieve jid: {e}", error=True) | |
1864 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
1865 else: | |
1866 self.display_uri(jid_) | |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1867 else: |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1868 self.display_uri(None) |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1869 |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
1870 |
2308
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1871 class HookCreate(base.CommandBase): |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1872 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1873 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1874 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1875 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1876 "create", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1877 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1878 pubsub_flags={C.NODE}, |
3028 | 1879 help=_("create a Pubsub hook"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1880 ) |
2308
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1881 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1882 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1883 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1884 "-t", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1885 "--type", |
3028 | 1886 default="python", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1887 choices=("python", "python_file", "python_code"), |
3028 | 1888 help=_("hook type"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1889 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1890 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1891 "-P", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1892 "--persistent", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1893 action="store_true", |
3028 | 1894 help=_("make hook persistent across restarts"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1895 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1896 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1897 "hook_arg", |
3028 | 1898 help=_("argument of the hook (depend of the type)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1899 ) |
2308
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1900 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1901 @staticmethod |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1902 def checkArgs(self): |
3028 | 1903 if self.args.type == "python_file": |
2308
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1904 self.args.hook_arg = os.path.abspath(self.args.hook_arg) |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1905 if not os.path.isfile(self.args.hook_arg): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1906 self.parser.error( |
3028 | 1907 _("{path} is not a file").format(path=self.args.hook_arg) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1908 ) |
2308
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1909 |
3040 | 1910 async def start(self): |
2308
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1911 self.checkArgs(self) |
3040 | 1912 try: |
1913 await self.host.bridge.psHookAdd( | |
1914 self.args.service, | |
1915 self.args.node, | |
1916 self.args.type, | |
1917 self.args.hook_arg, | |
1918 self.args.persistent, | |
1919 self.profile, | |
1920 ) | |
1921 except Exception as e: | |
1922 self.disp(f"can't create hook: {e}", error=True) | |
1923 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
1924 else: | |
1925 self.host.quit() | |
2308
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1926 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1927 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1928 class HookDelete(base.CommandBase): |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1929 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1930 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1931 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1932 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1933 "delete", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1934 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1935 pubsub_flags={C.NODE}, |
3028 | 1936 help=_("delete a Pubsub hook"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1937 ) |
2308
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1938 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1939 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1940 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1941 "-t", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1942 "--type", |
3028 | 1943 default="", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1944 choices=("", "python", "python_file", "python_code"), |
3028 | 1945 help=_("hook type to remove, empty to remove all (DEFAULT: remove all)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1946 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1947 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1948 "-a", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1949 "--arg", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1950 dest="hook_arg", |
3028 | 1951 default="", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1952 help=_( |
3028 | 1953 "argument of the hook to remove, empty to remove all (DEFAULT: remove all)" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1954 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1955 ) |
2308
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1956 |
3040 | 1957 async def start(self): |
2308
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1958 HookCreate.checkArgs(self) |
3040 | 1959 try: |
1960 nb_deleted = await self.host.bridge.psHookRemove( | |
1961 self.args.service, | |
1962 self.args.node, | |
1963 self.args.type, | |
1964 self.args.hook_arg, | |
1965 self.profile, | |
1966 ) | |
1967 except Exception as e: | |
1968 self.disp(f"can't delete hook: {e}", error=True) | |
1969 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
1970 else: | |
1971 self.disp(_(f"{nb_deleted} hook(s) have been deleted")) | |
1972 self.host.quit() | |
2308
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1973 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1974 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1975 class HookList(base.CommandBase): |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1976 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1977 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1978 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1979 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1980 "list", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1981 use_output=C.OUTPUT_LIST_DICT, |
3028 | 1982 help=_("list hooks of a profile"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1983 ) |
2308
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1984 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1985 def add_parser_options(self): |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1986 pass |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
1987 |
3040 | 1988 async def start(self): |
1989 try: | |
1990 data = await self.host.bridge.psHookList( | |
1991 self.profile, | |
1992 ) | |
1993 except Exception as e: | |
1994 self.disp(f"can't list hooks: {e}", error=True) | |
1995 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
1996 else: | |
1997 if not data: | |
1998 self.disp(_("No hook found.")) | |
1999 await self.output(data) | |
2000 self.host.quit() | |
2308
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2001 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2002 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2003 class Hook(base.CommandBase): |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2004 subcommands = (HookCreate, HookDelete, HookList) |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2005 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2006 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2007 super(Hook, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2008 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2009 "hook", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2010 use_profile=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2011 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2012 help=_("trigger action on Pubsub notifications"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2013 ) |
2308
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2014 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2015 |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2016 class Pubsub(base.CommandBase): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2017 subcommands = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2018 Set, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2019 Get, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2020 Delete, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2021 Edit, |
3521
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
2022 Rename, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2023 Subscribe, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2024 Unsubscribe, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2025 Subscriptions, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2026 Node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2027 Affiliations, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2028 Search, |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2029 Transform, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2030 Hook, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2031 Uri, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2032 ) |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2033 |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
2034 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2035 super(Pubsub, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2036 host, "pubsub", use_profile=False, help=_("PubSub nodes/items management") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2037 ) |