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