Mercurial > libervia-backend
annotate libervia/cli/cmd_pubsub.py @ 4156:2729d424dee7
plugin XEP-0359: use same ID as <message> for `origin_id`:
even if the XEP doesn't specify if Message ID must be the same as `origin_id`, using a
different one makes little sense, and is leading to bugs in other implementation (e.g.
Movim using the wrong ID for reactions).
author | Goffi <goffi@goffi.org> |
---|---|
date | Wed, 22 Nov 2023 15:05:41 +0100 |
parents | 47401850dec6 |
children | 3f7ca590a5da |
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 |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
4 # Libervia CLI |
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 | |
3668
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
27 import json |
3028 | 28 from . import base |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
29 from libervia.backend.core.i18n import _ |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
30 from libervia.backend.core import exceptions |
4075
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
31 from libervia.cli.constants import Const as C |
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
32 from libervia.cli import common |
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
33 from libervia.cli import arg_tools |
47401850dec6
refactoring: rename `libervia.frontends.jp` to `libervia.cli`
Goffi <goffi@goffi.org>
parents:
4074
diff
changeset
|
34 from libervia.cli import xml_tools |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
35 from functools import partial |
4071
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
36 from libervia.backend.tools.common import data_format |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
37 from libervia.backend.tools.common import uri |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
38 from libervia.backend.tools.common.ansi import ANSI as A |
4b842c1fb686
refactoring: renamed `sat` package to `libervia.backend`
Goffi <goffi@goffi.org>
parents:
4037
diff
changeset
|
39 from libervia.backend.tools.common import date_utils |
4074
26b7ed2817da
refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
40 from libervia.frontends.tools import jid, strings |
26b7ed2817da
refactoring: rename `sat_frontends` to `libervia.frontends`
Goffi <goffi@goffi.org>
parents:
4071
diff
changeset
|
41 from libervia.frontends.bridge.bridge_frontend import BridgeException |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
42 |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
43 __commands__ = ["Pubsub"] |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
44 |
3028 | 45 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
|
46 PUBSUB_SCHEMA_TMP_DIR = PUBSUB_TMP_DIR + "_schema" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
47 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
|
48 |
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
|
49 # 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
|
50 |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
51 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
52 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
|
53 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
54 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
55 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
56 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
57 "info", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
58 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
59 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
60 pubsub_flags={C.NODE}, |
3028 | 61 help=_("retrieve node configuration"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
62 ) |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
63 |
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
64 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
65 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
66 "-k", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
67 "--key", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
68 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
69 dest="keys", |
3028 | 70 help=_("data key to filter"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
71 ) |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
72 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
73 def remove_prefix(self, key): |
3028 | 74 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
|
75 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
76 def filter_key(self, key): |
3028 | 77 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
|
78 |
3040 | 79 async def start(self): |
80 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
81 config_dict = await self.host.bridge.ps_node_configuration_get( |
3040 | 82 self.args.service, |
83 self.args.node, | |
84 self.profile, | |
85 ) | |
3413
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
86 except BridgeException as e: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
87 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
|
88 self.disp( |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
89 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
|
90 error=True, |
3413
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
91 ) |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
92 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
|
93 else: |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
94 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
|
95 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
3040 | 96 except Exception as e: |
3413
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
97 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
|
98 self.host.quit(C.EXIT_INTERNAL_ERROR) |
3040 | 99 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
100 key_filter = (lambda k: True) if not self.args.keys else self.filter_key |
3040 | 101 config_dict = { |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
102 self.remove_prefix(k): v for k, v in config_dict.items() if key_filter(k) |
3040 | 103 } |
104 await self.output(config_dict) | |
105 self.host.quit() | |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
106 |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
107 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
108 class NodeCreate(base.CommandBase): |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
109 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
110 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
111 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
112 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
113 "create", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
114 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
115 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
116 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
117 use_verbose=True, |
3028 | 118 help=_("create a node"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
119 ) |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
120 |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
121 @staticmethod |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
122 def add_node_config_options(parser): |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
123 parser.add_argument( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
124 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
125 "--field", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
126 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
127 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
128 dest="fields", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
129 default=[], |
3028 | 130 metavar=("KEY", "VALUE"), |
131 help=_("configuration field to set"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
132 ) |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
133 parser.add_argument( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
134 "-F", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
135 "--full-prefix", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
136 action="store_true", |
3028 | 137 help=_('don\'t prepend "pubsub#" prefix to field names'), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
138 ) |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
139 |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
140 def add_parser_options(self): |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
141 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
|
142 |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
143 @staticmethod |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
144 def get_config_options(args): |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
145 if not args.full_prefix: |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
146 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
|
147 else: |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
148 return dict(args.fields) |
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
149 |
3040 | 150 async def start(self): |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
151 options = self.get_config_options(self.args) |
3040 | 152 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
153 node_id = await self.host.bridge.ps_node_create( |
3040 | 154 self.args.service, |
155 self.args.node, | |
156 options, | |
157 self.profile, | |
158 ) | |
159 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
160 self.disp(msg=_("can't create node: {e}").format(e=e), error=True) |
3040 | 161 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
162 else: | |
163 if self.host.verbosity: | |
164 announce = _("node created successfully: ") | |
165 else: | |
166 announce = "" | |
167 self.disp(announce + node_id) | |
168 self.host.quit() | |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
169 |
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
170 |
2802
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
171 class NodePurge(base.CommandBase): |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
172 def __init__(self, host): |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
173 super(NodePurge, self).__init__( |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
174 host, |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
175 "purge", |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
176 use_pubsub=True, |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
177 pubsub_flags={C.NODE}, |
3028 | 178 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
|
179 ) |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
180 |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
181 def add_parser_options(self): |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
182 self.parser.add_argument( |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
183 "-f", |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
184 "--force", |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
185 action="store_true", |
3028 | 186 help=_("purge node without confirmation"), |
2802
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
187 ) |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
188 |
3040 | 189 async def start(self): |
2802
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
190 if not self.args.force: |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
191 if not self.args.service: |
3040 | 192 message = _( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
193 "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
|
194 "delete ALL items from it!" |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
195 ).format(node=self.args.node) |
2802
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
196 else: |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
197 message = _( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
198 "Are you sure to delete node [{node}] on service " |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
199 "[{service}]? This will delete ALL items from it!" |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
200 ).format(node=self.args.node, service=self.args.service) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
201 await self.host.confirm_or_quit(message, _("node purge cancelled")) |
2802
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
202 |
3040 | 203 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
204 await self.host.bridge.ps_node_purge( |
3040 | 205 self.args.service, |
206 self.args.node, | |
207 self.profile, | |
208 ) | |
209 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
210 self.disp(msg=_("can't purge node: {e}").format(e=e), error=True) |
3040 | 211 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
212 else: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
213 self.disp(_("node [{node}] purged successfully").format(node=self.args.node)) |
3040 | 214 self.host.quit() |
2802
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
215 |
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
216 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
217 class NodeDelete(base.CommandBase): |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
218 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
219 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
220 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
221 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
222 "delete", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
223 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
224 pubsub_flags={C.NODE}, |
3028 | 225 help=_("delete a node"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
226 ) |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
227 |
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
228 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
229 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
230 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
231 "--force", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
232 action="store_true", |
3028 | 233 help=_("delete node without confirmation"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
234 ) |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
235 |
3040 | 236 async def start(self): |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
237 if not self.args.force: |
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
238 if not self.args.service: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
239 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
|
240 node=self.args.node |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
241 ) |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
242 else: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
243 message = _( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
244 "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
|
245 ).format(node=self.args.node, service=self.args.service) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
246 await self.host.confirm_or_quit(message, _("node deletion cancelled")) |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
247 |
3040 | 248 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
249 await self.host.bridge.ps_node_delete( |
3040 | 250 self.args.service, |
251 self.args.node, | |
252 self.profile, | |
253 ) | |
254 except Exception as e: | |
255 self.disp(f"can't delete node: {e}", error=True) | |
256 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
257 else: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
258 self.disp(_("node [{node}] deleted successfully").format(node=self.args.node)) |
3040 | 259 self.host.quit() |
2221
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
260 |
a6c9bc4d1de0
jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents:
2214
diff
changeset
|
261 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
262 class NodeSet(base.CommandBase): |
2199
ea0d0a4e2ad8
jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents:
2197
diff
changeset
|
263 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
264 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
265 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
266 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
267 "set", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
268 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
269 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
270 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
271 use_verbose=True, |
3028 | 272 help=_("set node configuration"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
273 ) |
2199
ea0d0a4e2ad8
jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents:
2197
diff
changeset
|
274 |
ea0d0a4e2ad8
jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents:
2197
diff
changeset
|
275 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
276 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
277 "-f", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
278 "--field", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
279 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
280 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
281 dest="fields", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
282 required=True, |
3028 | 283 metavar=("KEY", "VALUE"), |
284 help=_("configuration field to set (required)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
285 ) |
3040 | 286 self.parser.add_argument( |
287 "-F", | |
288 "--full-prefix", | |
289 action="store_true", | |
290 help=_('don\'t prepend "pubsub#" prefix to field names'), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
291 ) |
2199
ea0d0a4e2ad8
jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents:
2197
diff
changeset
|
292 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
293 def get_key_name(self, k): |
3040 | 294 if self.args.full_prefix or k.startswith("pubsub#"): |
295 return k | |
296 else: | |
3028 | 297 return "pubsub#" + k |
2199
ea0d0a4e2ad8
jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents:
2197
diff
changeset
|
298 |
3040 | 299 async def start(self): |
300 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
301 await self.host.bridge.ps_node_configuration_set( |
3040 | 302 self.args.service, |
303 self.args.node, | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
304 {self.get_key_name(k): v for k, v in self.args.fields}, |
3040 | 305 self.profile, |
306 ) | |
307 except Exception as e: | |
308 self.disp(f"can't set node configuration: {e}", error=True) | |
309 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
310 else: | |
311 self.disp(_("node configuration successful"), 1) | |
312 self.host.quit() | |
2199
ea0d0a4e2ad8
jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents:
2197
diff
changeset
|
313 |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
314 |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
315 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
|
316 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
|
317 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
|
318 host, |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
319 "import", |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
320 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
|
321 pubsub_flags={C.NODE}, |
3028 | 322 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
|
323 ) |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
324 |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
325 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
|
326 self.parser.add_argument( |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
327 "--admin", |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
328 action="store_true", |
3028 | 329 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
|
330 ) |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
331 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
|
332 "import_file", |
3028 | 333 type=argparse.FileType(), |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
334 help=_( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
335 "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
|
336 "whole XML of each item to import." |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
337 ), |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
338 ) |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
339 |
3040 | 340 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
|
341 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
342 element, etree = xml_tools.etree_parse( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
343 self, self.args.import_file, reraise=True |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
344 ) |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
345 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
|
346 from lxml.etree import XMLSyntaxError |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
347 |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
348 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
|
349 # 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
|
350 # 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
|
351 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
|
352 xml_buf = "<import>" + self.args.import_file.read() + "</import>" |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
353 element, etree = xml_tools.etree_parse(self, xml_buf) |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
354 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
355 # 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
|
356 # 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
|
357 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
|
358 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
359 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
|
360 self.disp( |
3028 | 361 _("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
|
362 error=True, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
363 ) |
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 self.host.quit(C.EXIT_DATA_ERROR) |
3040 | 365 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
|
366 |
3040 | 367 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
|
368 if self.args.admin: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
369 method = self.host.bridge.ps_admin_items_send |
3040 | 370 else: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
371 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
372 _( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
373 "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
|
374 "be changed" |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
375 ) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
376 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
377 method = self.host.bridge.ps_items_send |
3040 | 378 |
379 try: | |
380 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
|
381 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
|
382 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
|
383 items, |
3028 | 384 "", |
2804
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
385 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
|
386 ) |
3040 | 387 except Exception as e: |
388 self.disp(f"can't send items: {e}", error=True) | |
389 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
|
390 else: |
3040 | 391 if items_ids: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
392 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
393 _("items published with id(s) {items_ids}").format( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
394 items_ids=", ".join(items_ids) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
395 ) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
396 ) |
3040 | 397 else: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
398 self.disp(_("items published")) |
3040 | 399 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
|
400 |
710de41da2f2
jp (pubsub/node): new "import" command, to publish many nodes from an XML file
Goffi <goffi@goffi.org>
parents:
2803
diff
changeset
|
401 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
402 class NodeAffiliationsGet(base.CommandBase): |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
403 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
404 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
405 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
406 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
407 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
408 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
409 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
410 pubsub_flags={C.NODE}, |
3028 | 411 help=_("retrieve node affiliations (for node owner)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
412 ) |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
413 |
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
414 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
|
415 pass |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
416 |
3040 | 417 async def start(self): |
418 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
419 affiliations = await self.host.bridge.ps_node_affiliations_get( |
3040 | 420 self.args.service, |
421 self.args.node, | |
422 self.profile, | |
423 ) | |
424 except Exception as e: | |
425 self.disp(f"can't get node affiliations: {e}", error=True) | |
426 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
427 else: | |
428 await self.output(affiliations) | |
429 self.host.quit() | |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
430 |
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
431 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
432 class NodeAffiliationsSet(base.CommandBase): |
2207
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
433 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
434 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
435 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
436 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
437 "set", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
438 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
439 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
440 use_verbose=True, |
3028 | 441 help=_("set affiliations (for node owner)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
442 ) |
2207
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
443 |
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
444 def add_parser_options(self): |
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
445 # 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
|
446 # (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
|
447 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
448 "-a", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
449 "--affiliation", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
450 dest="affiliations", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
451 metavar=("JID", "AFFILIATION"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
452 required=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
453 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
454 nargs=2, |
3028 | 455 help=_("entity/affiliation couple(s)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
456 ) |
2207
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
457 |
3040 | 458 async def start(self): |
2207
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
459 affiliations = dict(self.args.affiliations) |
3040 | 460 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
461 await self.host.bridge.ps_node_affiliations_set( |
3040 | 462 self.args.service, |
463 self.args.node, | |
464 affiliations, | |
465 self.profile, | |
466 ) | |
467 except Exception as e: | |
468 self.disp(f"can't set node affiliations: {e}", error=True) | |
469 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
470 else: | |
471 self.disp(_("affiliations have been set"), 1) | |
472 self.host.quit() | |
2207
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
473 |
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
474 |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
475 class NodeAffiliations(base.CommandBase): |
2207
d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents:
2204
diff
changeset
|
476 subcommands = (NodeAffiliationsGet, NodeAffiliationsSet) |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
477 |
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
478 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
479 super(NodeAffiliations, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
480 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
481 "affiliations", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
482 use_profile=False, |
3028 | 483 help=_("set or retrieve node affiliations"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
484 ) |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
485 |
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
486 |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
487 class NodeSubscriptionsGet(base.CommandBase): |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
488 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
489 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
490 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
491 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
492 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
493 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
494 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
495 pubsub_flags={C.NODE}, |
3028 | 496 help=_("retrieve node subscriptions (for node owner)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
497 ) |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
498 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
499 def add_parser_options(self): |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
500 self.parser.add_argument( |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
501 "--public", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
502 action="store_true", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
503 help=_("get public subscriptions"), |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
504 ) |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
505 |
3040 | 506 async def start(self): |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
507 if self.args.public: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
508 method = self.host.bridge.ps_public_node_subscriptions_get |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
509 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
510 method = self.host.bridge.ps_node_subscriptions_get |
3040 | 511 try: |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
512 subscriptions = await method( |
3040 | 513 self.args.service, |
514 self.args.node, | |
515 self.profile, | |
516 ) | |
517 except Exception as e: | |
518 self.disp(f"can't get node subscriptions: {e}", error=True) | |
519 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
520 else: | |
521 await self.output(subscriptions) | |
522 self.host.quit() | |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
523 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
524 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
525 class StoreSubscriptionAction(argparse.Action): |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
526 """Action which handle subscription parameter for owner |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
527 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
528 list is given by pairs: jid and subscription state |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
529 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
|
530 """ |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
531 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
532 def __call__(self, parser, namespace, values, option_string): |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
533 dest_dict = getattr(namespace, self.dest) |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
534 while values: |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
535 jid_s = values.pop(0) |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
536 try: |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
537 subscription = values.pop(0) |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
538 except IndexError: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
539 subscription = "subscribed" |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
540 if subscription not in ALLOWED_SUBSCRIPTIONS_OWNER: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
541 parser.error( |
3028 | 542 _("subscription must be one of {}").format( |
543 ", ".join(ALLOWED_SUBSCRIPTIONS_OWNER) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
544 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
545 ) |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
546 dest_dict[jid_s] = subscription |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
547 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
548 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
549 class NodeSubscriptionsSet(base.CommandBase): |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
550 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
551 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
552 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
553 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
554 "set", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
555 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
556 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
557 use_verbose=True, |
3028 | 558 help=_("set/modify subscriptions (for node owner)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
559 ) |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
560 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
561 def add_parser_options(self): |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
562 # 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
|
563 # (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
|
564 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
565 "-S", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
566 "--subscription", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
567 dest="subscriptions", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
568 default={}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
569 nargs="+", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
570 metavar=("JID [SUSBSCRIPTION]"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
571 required=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
572 action=StoreSubscriptionAction, |
3028 | 573 help=_("entity/subscription couple(s)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
574 ) |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
575 |
3040 | 576 async def start(self): |
577 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
578 self.host.bridge.ps_node_subscriptions_set( |
3040 | 579 self.args.service, |
580 self.args.node, | |
581 self.args.subscriptions, | |
582 self.profile, | |
583 ) | |
584 except Exception as e: | |
585 self.disp(f"can't set node subscriptions: {e}", error=True) | |
586 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
587 else: | |
588 self.disp(_("subscriptions have been set"), 1) | |
589 self.host.quit() | |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
590 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
591 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
592 class NodeSubscriptions(base.CommandBase): |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
593 subcommands = (NodeSubscriptionsGet, NodeSubscriptionsSet) |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
594 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
595 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
596 super(NodeSubscriptions, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
597 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
598 "subscriptions", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
599 use_profile=False, |
3028 | 600 help=_("get or modify node subscriptions"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
601 ) |
2339
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
602 |
d94e932be8b3
jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents:
2320
diff
changeset
|
603 |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
604 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
|
605 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
606 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
607 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
608 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
609 "set", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
610 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
611 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
612 use_verbose=True, |
3028 | 613 help=_("set/replace a schema"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
614 ) |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
615 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
616 def add_parser_options(self): |
3028 | 617 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
|
618 |
3040 | 619 async def start(self): |
620 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
621 await self.host.bridge.ps_schema_set( |
3040 | 622 self.args.service, |
623 self.args.node, | |
624 self.args.schema, | |
625 self.profile, | |
626 ) | |
627 except Exception as e: | |
628 self.disp(f"can't set schema: {e}", error=True) | |
629 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
630 else: | |
631 self.disp(_("schema has been set"), 1) | |
632 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
|
633 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
634 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
635 class NodeSchemaEdit(base.CommandBase, common.BaseEdit): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
636 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
|
637 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
638 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
639 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
640 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
641 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
642 "edit", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
643 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
644 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
645 use_draft=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
646 use_verbose=True, |
3028 | 647 help=_("edit a schema"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
648 ) |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
649 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
|
650 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
651 def add_parser_options(self): |
2532 | 652 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
|
653 |
3040 | 654 async def publish(self, schema): |
655 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
656 await self.host.bridge.ps_schema_set( |
3040 | 657 self.args.service, |
658 self.args.node, | |
659 schema, | |
660 self.profile, | |
661 ) | |
662 except Exception as e: | |
663 self.disp(f"can't set schema: {e}", error=True) | |
664 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
665 else: | |
666 self.disp(_("schema has been set"), 1) | |
667 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
|
668 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
669 async def ps_schema_get_cb(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
|
670 try: |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
671 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
|
672 except ImportError: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
673 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
674 "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
|
675 'with "pip install lxml"', |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
676 error=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
677 ) |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
678 self.host.quit(1) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
679 content_file_obj, content_file_path = self.get_tmp_file() |
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
|
680 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
|
681 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
|
682 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
|
683 schema_elt = etree.fromstring(schema, parser) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
684 content_file_obj.write( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
685 etree.tostring(schema_elt, encoding="utf-8", pretty_print=True) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
686 ) |
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
|
687 content_file_obj.seek(0) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
688 await self.run_editor( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
689 "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
|
690 ) |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
691 |
3040 | 692 async def start(self): |
693 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
694 schema = await self.host.bridge.ps_schema_get( |
3040 | 695 self.args.service, |
696 self.args.node, | |
697 self.profile, | |
698 ) | |
3453
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
699 except BridgeException as e: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
700 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
|
701 schema = "" |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
702 else: |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
703 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
|
704 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
|
705 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
706 await self.ps_schema_get_cb(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
|
707 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
708 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
709 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
|
710 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
711 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
712 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
713 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
714 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
715 use_output=C.OUTPUT_XML, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
716 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
717 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
718 use_verbose=True, |
3028 | 719 help=_("get schema"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
720 ) |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
721 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
722 def 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
|
723 pass |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
724 |
3040 | 725 async def start(self): |
726 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
727 schema = await self.host.bridge.ps_schema_get( |
3040 | 728 self.args.service, |
729 self.args.node, | |
730 self.profile, | |
731 ) | |
3453
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
732 except BridgeException as e: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
733 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
|
734 schema = None |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
735 else: |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
736 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
|
737 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
|
738 |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
739 if schema: |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
740 await self.output(schema) |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
741 self.host.quit() |
3040 | 742 else: |
3453
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
743 self.disp(_("no schema found"), 1) |
864485605d12
jp (pubsub/node/schema): handle not-found conditions properly
Goffi <goffi@goffi.org>
parents:
3413
diff
changeset
|
744 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
|
745 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
746 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
747 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
|
748 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
|
749 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
750 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
751 super(NodeSchema, self).__init__( |
3028 | 752 host, "schema", use_profile=False, help=_("data schema manipulation") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
753 ) |
2351
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
754 |
3c0a3fae1862
jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents:
2339
diff
changeset
|
755 |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
756 class Node(base.CommandBase): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
757 subcommands = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
758 NodeInfo, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
759 NodeCreate, |
2802
f61a50790fae
jp (pubsub/node): added purge command
Goffi <goffi@goffi.org>
parents:
2777
diff
changeset
|
760 NodePurge, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
761 NodeDelete, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
762 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
|
763 NodeImport, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
764 NodeAffiliations, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
765 NodeSubscriptions, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
766 NodeSchema, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
767 ) |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
768 |
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
769 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
770 super(Node, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
771 host, "node", use_profile=False, help=_("node handling") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
772 ) |
2197
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
773 |
e0e06391ce91
jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents:
2195
diff
changeset
|
774 |
3602
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
775 class CacheGet(base.CommandBase): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
776 def __init__(self, host): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
777 super().__init__( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
778 host, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
779 "get", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
780 use_output=C.OUTPUT_LIST_XML, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
781 use_pubsub=True, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
782 pubsub_flags={C.NODE, C.MULTI_ITEMS, C.CACHE}, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
783 help=_("get pubsub item(s) from cache"), |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
784 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
785 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
786 def add_parser_options(self): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
787 self.parser.add_argument( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
788 "-S", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
789 "--sub-id", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
790 default="", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
791 help=_("subscription id"), |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
792 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
793 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
794 async def start(self): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
795 try: |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
796 ps_result = data_format.deserialise( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
797 await self.host.bridge.ps_cache_get( |
3602
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
798 self.args.service, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
799 self.args.node, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
800 self.args.max, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
801 self.args.items, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
802 self.args.sub_id, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
803 self.get_pubsub_extra(), |
3602
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
804 self.profile, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
805 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
806 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
807 except BridgeException as e: |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
808 if e.classname == "NotFound": |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
809 self.disp( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
810 f"The node {self.args.node} from {self.args.service} is not in cache " |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
811 f"for {self.profile}", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
812 error=True, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
813 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
814 self.host.quit(C.EXIT_NOT_FOUND) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
815 else: |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
816 self.disp(f"can't get pubsub items from cache: {e}", error=True) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
817 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
818 except Exception as e: |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
819 self.disp(f"Internal error: {e}", error=True) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
820 self.host.quit(C.EXIT_INTERNAL_ERROR) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
821 else: |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
822 await self.output(ps_result["items"]) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
823 self.host.quit(C.EXIT_OK) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
824 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
825 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
826 class CacheSync(base.CommandBase): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
827 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
828 def __init__(self, host): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
829 super().__init__( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
830 host, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
831 "sync", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
832 use_pubsub=True, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
833 pubsub_flags={C.NODE}, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
834 help=_("(re)synchronise a pubsub node"), |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
835 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
836 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
837 def add_parser_options(self): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
838 pass |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
839 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
840 async def start(self): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
841 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
842 await self.host.bridge.ps_cache_sync( |
3602
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
843 self.args.service, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
844 self.args.node, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
845 self.profile, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
846 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
847 except BridgeException as e: |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
848 if e.condition == "item-not-found" or e.classname == "NotFound": |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
849 self.disp( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
850 f"The node {self.args.node} doesn't exist on {self.args.service}", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
851 error=True, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
852 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
853 self.host.quit(C.EXIT_NOT_FOUND) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
854 else: |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
855 self.disp(f"can't synchronise pubsub node: {e}", error=True) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
856 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
857 except Exception as e: |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
858 self.disp(f"Internal error: {e}", error=True) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
859 self.host.quit(C.EXIT_INTERNAL_ERROR) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
860 else: |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
861 self.host.quit(C.EXIT_OK) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
862 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
863 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
864 class CachePurge(base.CommandBase): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
865 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
866 def __init__(self, host): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
867 super().__init__( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
868 host, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
869 "purge", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
870 use_profile=False, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
871 help=_("purge (delete) items from cache"), |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
872 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
873 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
874 def add_parser_options(self): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
875 self.parser.add_argument( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
876 "-s", "--service", action="append", metavar="JID", dest="services", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
877 help="purge items only for these services. If not specified, items from ALL " |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
878 "services will be purged. May be used several times." |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
879 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
880 self.parser.add_argument( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
881 "-n", "--node", action="append", dest="nodes", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
882 help="purge items only for these nodes. If not specified, items from ALL " |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
883 "nodes will be purged. May be used several times." |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
884 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
885 self.parser.add_argument( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
886 "-p", "--profile", action="append", dest="profiles", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
887 help="purge items only for these profiles. If not specified, items from ALL " |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
888 "profiles will be purged. May be used several times." |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
889 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
890 self.parser.add_argument( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
891 "-b", "--updated-before", type=base.date_decoder, metavar="TIME_PATTERN", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
892 help="purge items which have been last updated before given time." |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
893 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
894 self.parser.add_argument( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
895 "-C", "--created-before", type=base.date_decoder, metavar="TIME_PATTERN", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
896 help="purge items which have been last created before given time." |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
897 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
898 self.parser.add_argument( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
899 "-t", "--type", action="append", dest="types", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
900 help="purge items flagged with TYPE. May be used several times." |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
901 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
902 self.parser.add_argument( |
3618
7f503b20597e
jp (pubsub/cache/purge): fix conflict with `subtype` short option
Goffi <goffi@goffi.org>
parents:
3602
diff
changeset
|
903 "-S", "--subtype", action="append", dest="subtypes", |
3602
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
904 help="purge items flagged with SUBTYPE. May be used several times." |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
905 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
906 self.parser.add_argument( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
907 "-f", "--force", action="store_true", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
908 help=_("purge items without confirmation") |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
909 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
910 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
911 async def start(self): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
912 if not self.args.force: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
913 await self.host.confirm_or_quit( |
3602
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
914 _( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
915 "Are you sure to purge items from cache? You'll have to bypass cache " |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
916 "or resynchronise nodes to access deleted items again." |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
917 ), |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
918 _("Items purgins has been cancelled.") |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
919 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
920 purge_data = {} |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
921 for key in ( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
922 "services", "nodes", "profiles", "updated_before", "created_before", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
923 "types", "subtypes" |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
924 ): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
925 value = getattr(self.args, key) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
926 if value is not None: |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
927 purge_data[key] = value |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
928 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
929 await self.host.bridge.ps_cache_purge( |
3602
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
930 data_format.serialise( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
931 purge_data |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
932 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
933 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
934 except Exception as e: |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
935 self.disp(f"Internal error: {e}", error=True) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
936 self.host.quit(C.EXIT_INTERNAL_ERROR) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
937 else: |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
938 self.host.quit(C.EXIT_OK) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
939 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
940 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
941 class CacheReset(base.CommandBase): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
942 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
943 def __init__(self, host): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
944 super().__init__( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
945 host, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
946 "reset", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
947 use_profile=False, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
948 help=_("remove everything from cache"), |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
949 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
950 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
951 def add_parser_options(self): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
952 self.parser.add_argument( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
953 "-f", "--force", action="store_true", |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
954 help=_("reset cache without confirmation") |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
955 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
956 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
957 async def start(self): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
958 if not self.args.force: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
959 await self.host.confirm_or_quit( |
3602
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
960 _( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
961 "Are you sure to reset cache? All nodes and items will be removed " |
3668
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
962 "from it, then it will be progressively refilled as if it were new. " |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
963 "This may be resources intensive." |
3602
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
964 ), |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
965 _("Pubsub cache reset has been cancelled.") |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
966 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
967 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
968 await self.host.bridge.ps_cache_reset() |
3602
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
969 except Exception as e: |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
970 self.disp(f"Internal error: {e}", error=True) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
971 self.host.quit(C.EXIT_INTERNAL_ERROR) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
972 else: |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
973 self.host.quit(C.EXIT_OK) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
974 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
975 |
3668
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
976 class CacheSearch(base.CommandBase): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
977 def __init__(self, host): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
978 extra_outputs = { |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
979 "default": self.default_output, |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
980 "xml": self.xml_output, |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
981 "xml-raw": self.xml_raw_output, |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
982 } |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
983 super().__init__( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
984 host, |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
985 "search", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
986 use_profile=False, |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
987 use_output=C.OUTPUT_LIST_DICT, |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
988 extra_outputs=extra_outputs, |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
989 help=_("search for pubsub items in cache"), |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
990 ) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
991 |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
992 def add_parser_options(self): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
993 self.parser.add_argument( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
994 "-f", "--fts", help=_("Full-Text Search query"), metavar="FTS_QUERY" |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
995 ) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
996 self.parser.add_argument( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
997 "-p", "--profile", action="append", dest="profiles", metavar="PROFILE", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
998 help="search items only from these profiles. May be used several times." |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
999 ) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1000 self.parser.add_argument( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1001 "-s", "--service", action="append", dest="services", metavar="SERVICE", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1002 help="items must be from specified service. May be used several times." |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1003 ) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1004 self.parser.add_argument( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1005 "-n", "--node", action="append", dest="nodes", metavar="NODE", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1006 help="items must be in the specified node. May be used several times." |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1007 ) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1008 self.parser.add_argument( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1009 "-t", "--type", action="append", dest="types", metavar="TYPE", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1010 help="items must be of specified type. May be used several times." |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1011 ) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1012 self.parser.add_argument( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1013 "-S", "--subtype", action="append", dest="subtypes", metavar="SUBTYPE", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1014 help="items must be of specified subtype. May be used several times." |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1015 ) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1016 self.parser.add_argument( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1017 "-P", "--payload", action="store_true", help=_("include item XML payload") |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1018 ) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1019 self.parser.add_argument( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1020 "-o", "--order-by", action="append", nargs="+", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1021 metavar=("ORDER", "[FIELD] [DIRECTION]"), |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1022 help=_("how items must be ordered. May be used several times.") |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1023 ) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1024 self.parser.add_argument( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1025 "-l", "--limit", type=int, help=_("maximum number of items to return") |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1026 ) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1027 self.parser.add_argument( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1028 "-i", "--index", type=int, help=_("return results starting from this index") |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1029 ) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1030 self.parser.add_argument( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1031 "-F", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1032 "--field", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1033 action="append", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1034 nargs=3, |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1035 dest="fields", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1036 default=[], |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1037 metavar=("PATH", "OPERATOR", "VALUE"), |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1038 help=_("parsed data field filter. May be used several times."), |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1039 ) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1040 self.parser.add_argument( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1041 "-k", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1042 "--key", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1043 action="append", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1044 dest="keys", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1045 metavar="KEY", |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1046 help=_( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1047 "data key(s) to display. May be used several times. DEFAULT: show all " |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1048 "keys" |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1049 ), |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1050 ) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1051 |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1052 async def start(self): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1053 query = {} |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1054 for arg in ("fts", "profiles", "services", "nodes", "types", "subtypes"): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1055 value = getattr(self.args, arg) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1056 if value: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1057 if arg in ("types", "subtypes"): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1058 # empty string is used to find items without type and/or subtype |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1059 value = [v or None for v in value] |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1060 query[arg] = value |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1061 for arg in ("limit", "index"): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1062 value = getattr(self.args, arg) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1063 if value is not None: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1064 query[arg] = value |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1065 if self.args.order_by is not None: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1066 for order_data in self.args.order_by: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1067 order, *args = order_data |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1068 if order == "field": |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1069 if not args: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1070 self.parser.error(_("field data must be specified in --order-by")) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1071 elif len(args) == 1: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1072 path = args[0] |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1073 direction = "asc" |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1074 elif len(args) == 2: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1075 path, direction = args |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1076 else: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1077 self.parser.error(_( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1078 "You can't specify more that 2 arguments for a field in " |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1079 "--order-by" |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1080 )) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1081 try: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1082 path = json.loads(path) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1083 except json.JSONDecodeError: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1084 pass |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1085 order_query = { |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1086 "path": path, |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1087 } |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1088 else: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1089 order_query = { |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1090 "order": order |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1091 } |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1092 if not args: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1093 direction = "asc" |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1094 elif len(args) == 1: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1095 direction = args[0] |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1096 else: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1097 self.parser.error(_( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1098 "there are too many arguments in --order-by option" |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1099 )) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1100 if direction.lower() not in ("asc", "desc"): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1101 self.parser.error(_("invalid --order-by direction: {direction!r}")) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1102 order_query["direction"] = direction |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1103 query.setdefault("order-by", []).append(order_query) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1104 |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1105 if self.args.fields: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1106 parsed = [] |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1107 for field in self.args.fields: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1108 path, operator, value = field |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1109 try: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1110 path = json.loads(path) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1111 except json.JSONDecodeError: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1112 # this is not a JSON encoded value, we keep it as a string |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1113 pass |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1114 |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1115 if not isinstance(path, list): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1116 path = [path] |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1117 |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1118 # handling of TP(<time pattern>) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1119 if operator in (">", "gt", "<", "le", "between"): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1120 def datetime_sub(match): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1121 return str(date_utils.date_parse_ext( |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1122 match.group(1), default_tz=date_utils.TZ_LOCAL |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1123 )) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1124 value = re.sub(r"\bTP\(([^)]+)\)", datetime_sub, value) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1125 |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1126 try: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1127 value = json.loads(value) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1128 except json.JSONDecodeError: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1129 # not JSON, as above we keep it as string |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1130 pass |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1131 |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1132 if operator in ("overlap", "ioverlap", "disjoint", "idisjoint"): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1133 if not isinstance(value, list): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1134 value = [value] |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1135 |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1136 parsed.append({ |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1137 "path": path, |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1138 "op": operator, |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1139 "value": value |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1140 }) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1141 |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1142 query["parsed"] = parsed |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1143 |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1144 if self.args.payload or "xml" in self.args.output: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1145 query["with_payload"] = True |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1146 if self.args.keys: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1147 self.args.keys.append("item_payload") |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1148 try: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1149 found_items = data_format.deserialise( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1150 await self.host.bridge.ps_cache_search( |
3668
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1151 data_format.serialise(query) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1152 ), |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1153 type_check=list, |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1154 ) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1155 except BridgeException as e: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1156 self.disp(f"can't search for pubsub items in cache: {e}", error=True) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1157 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1158 except Exception as e: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1159 self.disp(f"Internal error: {e}", error=True) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1160 self.host.quit(C.EXIT_INTERNAL_ERROR) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1161 else: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1162 if self.args.keys: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1163 found_items = [ |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1164 {k: v for k,v in item.items() if k in self.args.keys} |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1165 for item in found_items |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1166 ] |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1167 await self.output(found_items) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1168 self.host.quit(C.EXIT_OK) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1169 |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1170 def default_output(self, found_items): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1171 for item in found_items: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1172 for field in ("created", "published", "updated"): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1173 try: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1174 timestamp = item[field] |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1175 except KeyError: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1176 pass |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1177 else: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1178 try: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1179 item[field] = common.format_time(timestamp) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1180 except ValueError: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1181 pass |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1182 self.host._outputs[C.OUTPUT_LIST_DICT]["simple"]["callback"](found_items) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1183 |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1184 def xml_output(self, found_items): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1185 """Output prettified item payload""" |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1186 cb = self.host._outputs[C.OUTPUT_XML][C.OUTPUT_NAME_XML]["callback"] |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1187 for item in found_items: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1188 cb(item["item_payload"]) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1189 |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1190 def xml_raw_output(self, found_items): |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1191 """Output item payload without prettifying""" |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1192 cb = self.host._outputs[C.OUTPUT_XML][C.OUTPUT_NAME_XML_RAW]["callback"] |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1193 for item in found_items: |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1194 cb(item["item_payload"]) |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1195 |
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1196 |
3602
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
1197 class Cache(base.CommandBase): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
1198 subcommands = ( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
1199 CacheGet, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
1200 CacheSync, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
1201 CachePurge, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
1202 CacheReset, |
3668
0eacda79b5d1
CLI (pubsub/cache): `search` implementation
Goffi <goffi@goffi.org>
parents:
3618
diff
changeset
|
1203 CacheSearch, |
3602
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
1204 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
1205 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
1206 def __init__(self, host): |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
1207 super(Cache, self).__init__( |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
1208 host, "cache", use_profile=False, help=_("pubsub cache handling") |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
1209 ) |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
1210 |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
1211 |
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
|
1212 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
|
1213 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1214 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1215 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1216 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1217 "set", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1218 use_pubsub=True, |
3412
7b4ae3dbc041
jp (base, pubsub/set): new `--quiet` argument:
Goffi <goffi@goffi.org>
parents:
3411
diff
changeset
|
1219 use_quiet=True, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1220 pubsub_flags={C.NODE}, |
3028 | 1221 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
|
1222 ) |
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
|
1223 |
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
|
1224 def add_parser_options(self): |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1225 NodeCreate.add_node_config_options(self.parser) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1226 self.parser.add_argument( |
3947
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1227 "-e", |
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1228 "--encrypt", |
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1229 action="store_true", |
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1230 help=_("end-to-end encrypt the blog item") |
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1231 ) |
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1232 self.parser.add_argument( |
3973
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1233 "--encrypt-for", |
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1234 metavar="JID", |
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1235 action="append", |
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1236 help=_("encrypt a single item for") |
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1237 ) |
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1238 self.parser.add_argument( |
3965
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1239 "-X", |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1240 "--sign", |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1241 action="store_true", |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1242 help=_("cryptographically sign the blog post") |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1243 ) |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1244 self.parser.add_argument( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1245 "item", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1246 nargs="?", |
3028 | 1247 default="", |
1248 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
|
1249 ) |
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
|
1250 |
3040 | 1251 async def start(self): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1252 element, etree = xml_tools.etree_parse(self, sys.stdin) |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1253 element = xml_tools.get_payload(self, element) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1254 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
|
1255 extra = {} |
3947
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1256 if self.args.encrypt: |
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1257 extra["encrypted"] = True |
3973
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1258 if self.args.encrypt_for: |
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1259 extra["encrypted_for"] = {"targets": self.args.encrypt_for} |
3965
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1260 if self.args.sign: |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1261 extra["signed"] = True |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1262 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
|
1263 if publish_options: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1264 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
|
1265 |
3040 | 1266 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1267 published_id = await self.host.bridge.ps_item_send( |
3040 | 1268 self.args.service, |
1269 self.args.node, | |
1270 payload, | |
1271 self.args.item, | |
3100
cea52c9ddfd9
plugin XEP-0060, jp (pubsub/set): publish-options implementation:
Goffi <goffi@goffi.org>
parents:
3040
diff
changeset
|
1272 data_format.serialise(extra), |
3040 | 1273 self.profile, |
1274 ) | |
1275 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1276 self.disp(_("can't send item: {e}").format(e=e), error=True) |
3040 | 1277 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
1278 else: | |
1279 if published_id: | |
3412
7b4ae3dbc041
jp (base, pubsub/set): new `--quiet` argument:
Goffi <goffi@goffi.org>
parents:
3411
diff
changeset
|
1280 if self.args.quiet: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1281 self.disp(published_id, end="") |
3412
7b4ae3dbc041
jp (base, pubsub/set): new `--quiet` argument:
Goffi <goffi@goffi.org>
parents:
3411
diff
changeset
|
1282 else: |
7b4ae3dbc041
jp (base, pubsub/set): new `--quiet` argument:
Goffi <goffi@goffi.org>
parents:
3411
diff
changeset
|
1283 self.disp(f"Item published at {published_id}") |
3040 | 1284 else: |
1285 self.disp("Item published") | |
1286 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
|
1287 |
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
|
1288 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
1289 class Get(base.CommandBase): |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1290 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1291 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1292 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1293 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1294 "get", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1295 use_output=C.OUTPUT_LIST_XML, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1296 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
|
1297 pubsub_flags={C.NODE, C.MULTI_ITEMS, C.CACHE}, |
3028 | 1298 help=_("get pubsub item(s)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1299 ) |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1300 |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1301 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1302 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1303 "-S", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1304 "--sub-id", |
3028 | 1305 default="", |
1306 help=_("subscription id"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1307 ) |
3938
6939594ba77e
cli (pubsub/get): add `--no-decrypt` flag to disable automatic decryption:
Goffi <goffi@goffi.org>
parents:
3889
diff
changeset
|
1308 self.parser.add_argument( |
6939594ba77e
cli (pubsub/get): add `--no-decrypt` flag to disable automatic decryption:
Goffi <goffi@goffi.org>
parents:
3889
diff
changeset
|
1309 "--no-decrypt", |
6939594ba77e
cli (pubsub/get): add `--no-decrypt` flag to disable automatic decryption:
Goffi <goffi@goffi.org>
parents:
3889
diff
changeset
|
1310 action="store_true", |
6939594ba77e
cli (pubsub/get): add `--no-decrypt` flag to disable automatic decryption:
Goffi <goffi@goffi.org>
parents:
3889
diff
changeset
|
1311 help=_("don't do automatic decryption of e2ee items"), |
6939594ba77e
cli (pubsub/get): add `--no-decrypt` flag to disable automatic decryption:
Goffi <goffi@goffi.org>
parents:
3889
diff
changeset
|
1312 ) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1313 # 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
|
1314 |
3040 | 1315 async def start(self): |
3938
6939594ba77e
cli (pubsub/get): add `--no-decrypt` flag to disable automatic decryption:
Goffi <goffi@goffi.org>
parents:
3889
diff
changeset
|
1316 extra = {} |
6939594ba77e
cli (pubsub/get): add `--no-decrypt` flag to disable automatic decryption:
Goffi <goffi@goffi.org>
parents:
3889
diff
changeset
|
1317 if self.args.no_decrypt: |
6939594ba77e
cli (pubsub/get): add `--no-decrypt` flag to disable automatic decryption:
Goffi <goffi@goffi.org>
parents:
3889
diff
changeset
|
1318 extra["decrypt"] = False |
3040 | 1319 try: |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1320 ps_result = data_format.deserialise( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1321 await self.host.bridge.ps_items_get( |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1322 self.args.service, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1323 self.args.node, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1324 self.args.max, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1325 self.args.items, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1326 self.args.sub_id, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1327 self.get_pubsub_extra(extra), |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1328 self.profile, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1329 ) |
3040 | 1330 ) |
3413
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
1331 except BridgeException as e: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1332 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
|
1333 self.disp( |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
1334 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
|
1335 error=True, |
3413
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
1336 ) |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
1337 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
|
1338 else: |
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
1339 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
|
1340 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
3040 | 1341 except Exception as e: |
3413
f4d417593e77
jp (pubsub/node/info, pubsub/get): better exit code:
Goffi <goffi@goffi.org>
parents:
3412
diff
changeset
|
1342 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
|
1343 self.host.quit(C.EXIT_INTERNAL_ERROR) |
3040 | 1344 else: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1345 await self.output(ps_result["items"]) |
3040 | 1346 self.host.quit(C.EXIT_OK) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1347 |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1348 |
2281
4af1805cc6df
jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents:
2280
diff
changeset
|
1349 class Delete(base.CommandBase): |
4af1805cc6df
jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents:
2280
diff
changeset
|
1350 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1351 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1352 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1353 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1354 "delete", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1355 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
|
1356 pubsub_flags={C.NODE, C.ITEM, C.SINGLE_ITEM}, |
3028 | 1357 help=_("delete an item"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1358 ) |
2281
4af1805cc6df
jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents:
2280
diff
changeset
|
1359 |
4af1805cc6df
jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents:
2280
diff
changeset
|
1360 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1361 self.parser.add_argument( |
3028 | 1362 "-f", "--force", action="store_true", help=_("delete without confirmation") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1363 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1364 self.parser.add_argument( |
3601
b46e9791168f
jp (pubsub/delete): make notification the default, `--notify` option is replaced by `--no-notification`
Goffi <goffi@goffi.org>
parents:
3600
diff
changeset
|
1365 "--no-notification", dest="notify", action="store_false", |
b46e9791168f
jp (pubsub/delete): make notification the default, `--notify` option is replaced by `--no-notification`
Goffi <goffi@goffi.org>
parents:
3600
diff
changeset
|
1366 help=_("do not send notification (not recommended)") |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1367 ) |
2281
4af1805cc6df
jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents:
2280
diff
changeset
|
1368 |
3040 | 1369 async def start(self): |
2281
4af1805cc6df
jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents:
2280
diff
changeset
|
1370 if not self.args.item: |
3028 | 1371 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
|
1372 if not self.args.force: |
3028 | 1373 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
|
1374 item_id=self.args.item |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1375 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1376 await self.host.confirm_or_quit(message, _("item deletion cancelled")) |
3040 | 1377 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1378 await self.host.bridge.ps_item_retract( |
3040 | 1379 self.args.service, |
1380 self.args.node, | |
1381 self.args.item, | |
1382 self.args.notify, | |
1383 self.profile, | |
1384 ) | |
1385 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1386 self.disp(_("can't delete item: {e}").format(e=e), error=True) |
3040 | 1387 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
1388 else: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1389 self.disp(_("item {item} has been deleted").format(item=self.args.item)) |
3040 | 1390 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
|
1391 |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
1392 |
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
|
1393 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
|
1394 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1395 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1396 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1397 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1398 "edit", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1399 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1400 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1401 pubsub_flags={C.NODE, C.SINGLE_ITEM}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1402 use_draft=True, |
3028 | 1403 help=_("edit an existing or new pubsub item"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1404 ) |
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
|
1405 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
|
1406 |
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
1407 def add_parser_options(self): |
3947
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1408 self.parser.add_argument( |
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1409 "-e", |
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1410 "--encrypt", |
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1411 action="store_true", |
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1412 help=_("end-to-end encrypt the blog item") |
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1413 ) |
3965
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1414 self.parser.add_argument( |
3973
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1415 "--encrypt-for", |
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1416 metavar="JID", |
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1417 action="append", |
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1418 help=_("encrypt a single item for") |
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1419 ) |
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1420 self.parser.add_argument( |
3965
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1421 "-X", |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1422 "--sign", |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1423 action="store_true", |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1424 help=_("cryptographically sign the blog post") |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1425 ) |
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
|
1426 |
3040 | 1427 async def publish(self, content): |
3947
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1428 extra = {} |
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1429 if self.args.encrypt: |
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1430 extra["encrypted"] = True |
3973
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1431 if self.args.encrypt_for: |
570254d5a798
cli (blog, pubsub): encryption argument for Pubsub Targeted Encryption:
Goffi <goffi@goffi.org>
parents:
3965
diff
changeset
|
1432 extra["encrypted_for"] = {"targets": self.args.encrypt_for} |
3965
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1433 if self.args.sign: |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
1434 extra["signed"] = True |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1435 published_id = await self.host.bridge.ps_item_send( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1436 self.pubsub_service, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1437 self.pubsub_node, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1438 content, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1439 self.pubsub_item or "", |
3947
08c1d5485411
cli (pubsub/set, edit): add `--encrypt` flag:
Goffi <goffi@goffi.org>
parents:
3939
diff
changeset
|
1440 data_format.serialise(extra), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1441 self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1442 ) |
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
|
1443 if published_id: |
3028 | 1444 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
|
1445 else: |
3028 | 1446 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
|
1447 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1448 async def get_item_data(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
|
1449 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
|
1450 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
|
1451 except ImportError: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1452 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1453 "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
|
1454 'with "pip install lxml"', |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1455 error=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1456 ) |
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
|
1457 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
|
1458 items = [item] if item else [] |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1459 ps_result = data_format.deserialise( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1460 await self.host.bridge.ps_items_get( |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
1461 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
|
1462 ) |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1463 ) |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1464 item_raw = ps_result["items"][0] |
3040 | 1465 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
|
1466 item_elt = etree.fromstring(item_raw, parser) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1467 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
|
1468 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
|
1469 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
|
1470 except IndexError: |
3028 | 1471 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
|
1472 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
|
1473 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
|
1474 |
3040 | 1475 async def start(self): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1476 ( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1477 self.pubsub_service, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1478 self.pubsub_node, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1479 self.pubsub_item, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1480 content_file_path, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1481 content_file_obj, |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1482 ) = await self.get_item_path() |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1483 await self.run_editor("pubsub_editor_args", content_file_path, content_file_obj) |
3040 | 1484 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
|
1485 |
64e99bf0dfa2
jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents:
2274
diff
changeset
|
1486 |
3521
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1487 class Rename(base.CommandBase): |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1488 def __init__(self, host): |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1489 base.CommandBase.__init__( |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1490 self, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1491 host, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1492 "rename", |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1493 use_pubsub=True, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1494 pubsub_flags={C.NODE, C.SINGLE_ITEM}, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1495 help=_("rename a pubsub item"), |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1496 ) |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1497 |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1498 def add_parser_options(self): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1499 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
|
1500 |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1501 async def start(self): |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1502 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1503 await self.host.bridge.ps_item_rename( |
3521
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1504 self.args.service, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1505 self.args.node, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1506 self.args.item, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1507 self.args.new_id, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1508 self.profile, |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1509 ) |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1510 except Exception as e: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1511 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
|
1512 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1513 else: |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1514 self.disp("Item renamed") |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1515 self.host.quit(C.EXIT_OK) |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1516 |
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
1517 |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1518 class Subscribe(base.CommandBase): |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1519 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1520 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1521 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1522 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1523 "subscribe", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1524 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1525 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1526 use_verbose=True, |
3028 | 1527 help=_("subscribe to a node"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1528 ) |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1529 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1530 def add_parser_options(self): |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1531 self.parser.add_argument( |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1532 "--public", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1533 action="store_true", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1534 help=_("make the registration visible for everybody"), |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1535 ) |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1536 |
3040 | 1537 async def start(self): |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1538 options = {} |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1539 if self.args.public: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1540 namespaces = await self.host.bridge.namespaces_get() |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1541 try: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1542 ns_pps = namespaces["pps"] |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1543 except KeyError: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1544 self.disp( |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1545 "Pubsub Public Subscription plugin is not loaded, can't use --public " |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1546 "option, subscription stopped", error=True |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1547 ) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1548 self.host.quit(C.EXIT_MISSING_FEATURE) |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1549 else: |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1550 options[f"{{{ns_pps}}}public"] = True |
3040 | 1551 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1552 sub_id = await self.host.bridge.ps_subscribe( |
3040 | 1553 self.args.service, |
1554 self.args.node, | |
3757
5bda9d2e8b35
plugin XEP-0060: use serialised options in `psSubscribe` + triggers update
Goffi <goffi@goffi.org>
parents:
3668
diff
changeset
|
1555 data_format.serialise(options), |
3040 | 1556 self.profile, |
1557 ) | |
1558 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1559 self.disp(_("can't subscribe to node: {e}").format(e=e), error=True) |
3040 | 1560 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
1561 else: | |
1562 self.disp(_("subscription done"), 1) | |
1563 if sub_id: | |
1564 self.disp(_("subscription id: {sub_id}").format(sub_id=sub_id)) | |
1565 self.host.quit() | |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1566 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1567 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1568 class Unsubscribe(base.CommandBase): |
3040 | 1569 # 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
|
1570 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1571 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1572 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1573 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1574 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1575 "unsubscribe", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1576 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1577 pubsub_flags={C.NODE}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1578 use_verbose=True, |
3028 | 1579 help=_("unsubscribe from a node"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1580 ) |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1581 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1582 def add_parser_options(self): |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1583 pass |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1584 |
3040 | 1585 async def start(self): |
1586 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1587 await self.host.bridge.ps_unsubscribe( |
3040 | 1588 self.args.service, |
1589 self.args.node, | |
1590 self.profile, | |
1591 ) | |
1592 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1593 self.disp(_("can't unsubscribe from node: {e}").format(e=e), error=True) |
3040 | 1594 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
1595 else: | |
1596 self.disp(_("subscription removed"), 1) | |
1597 self.host.quit() | |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1598 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1599 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1600 class Subscriptions(base.CommandBase): |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1601 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1602 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1603 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1604 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1605 "subscriptions", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1606 use_output=C.OUTPUT_LIST_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1607 use_pubsub=True, |
3028 | 1608 help=_("retrieve all subscriptions on a service"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1609 ) |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1610 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1611 def add_parser_options(self): |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1612 self.parser.add_argument( |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1613 "--public", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1614 action="store_true", |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1615 help=_("get public subscriptions"), |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1616 ) |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1617 |
3040 | 1618 async def start(self): |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1619 if self.args.public: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1620 method = self.host.bridge.ps_public_subscriptions_get |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1621 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1622 method = self.host.bridge.ps_subscriptions_get |
3040 | 1623 try: |
3758
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1624 subscriptions = data_format.deserialise( |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1625 await method( |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1626 self.args.service, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1627 self.args.node, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1628 self.profile, |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1629 ), |
b7cef1b24f83
plugins XEP-0060, XEP-0376, XEP-0465, CLI: PAM + PSS implementation:
Goffi <goffi@goffi.org>
parents:
3757
diff
changeset
|
1630 type_check=list |
3040 | 1631 ) |
1632 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1633 self.disp(_("can't retrieve subscriptions: {e}").format(e=e), error=True) |
3040 | 1634 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
1635 else: | |
1636 await self.output(subscriptions) | |
1637 self.host.quit() | |
2353
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1638 |
ebc0dfe9c0ca
jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents:
2351
diff
changeset
|
1639 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
1640 class Affiliations(base.CommandBase): |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
1641 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1642 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1643 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1644 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1645 "affiliations", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1646 use_output=C.OUTPUT_DICT, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1647 use_pubsub=True, |
3028 | 1648 help=_("retrieve all affiliations on a service"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1649 ) |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
1650 |
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
1651 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
|
1652 pass |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
1653 |
3040 | 1654 async def start(self): |
1655 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1656 affiliations = await self.host.bridge.ps_affiliations_get( |
3040 | 1657 self.args.service, |
1658 self.args.node, | |
1659 self.profile, | |
1660 ) | |
1661 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1662 self.disp(f"can't get node affiliations: {e}", error=True) |
3040 | 1663 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
1664 else: | |
1665 await self.output(affiliations) | |
1666 self.host.quit() | |
2204
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
1667 |
afc703419186
jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents:
2199
diff
changeset
|
1668 |
3835
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1669 class Reference(base.CommandBase): |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1670 def __init__(self, host): |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1671 super().__init__( |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1672 host, |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1673 "reference", |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1674 use_pubsub=True, |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1675 pubsub_flags={C.NODE, C.SINGLE_ITEM}, |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1676 help=_("send a reference/mention to pubsub item"), |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1677 ) |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1678 |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1679 def add_parser_options(self): |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1680 self.parser.add_argument( |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1681 "-t", |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1682 "--type", |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1683 default="mention", |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1684 choices=("data", "mention"), |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1685 help=_("type of reference to send (DEFAULT: mention)"), |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1686 ) |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1687 self.parser.add_argument( |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1688 "recipient", |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1689 help=_("recipient of the reference") |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1690 ) |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1691 |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1692 async def start(self): |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1693 service = self.args.service or await self.host.get_profile_jid() |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1694 if self.args.item: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1695 anchor = uri.build_xmpp_uri( |
3835
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1696 "pubsub", path=service, node=self.args.node, item=self.args.item |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1697 ) |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1698 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1699 anchor = uri.build_xmpp_uri("pubsub", path=service, node=self.args.node) |
3835
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1700 |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1701 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1702 await self.host.bridge.reference_send( |
3835
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1703 self.args.recipient, |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1704 anchor, |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1705 self.args.type, |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1706 "", |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1707 self.profile, |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1708 ) |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1709 except Exception as e: |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1710 self.disp(f"can't send reference: {e}", error=True) |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1711 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1712 else: |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1713 self.host.quit() |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1714 |
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
1715 |
2316 | 1716 class Search(base.CommandBase): |
3040 | 1717 """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
|
1718 |
92af49cde255
jp (base): MAM and RSM arguments can now be used for pubsub commands:
Goffi <goffi@goffi.org>
parents:
2761
diff
changeset
|
1719 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
|
1720 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
|
1721 """ |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1722 |
2316 | 1723 RE_FLAGS = re.MULTILINE | re.UNICODE |
3028 | 1724 EXEC_ACTIONS = ("exec", "external") |
2316 | 1725 |
1726 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
|
1727 # 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
|
1728 # 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
|
1729 # 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
|
1730 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1731 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1732 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1733 "search", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1734 use_output=C.OUTPUT_XML, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1735 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1736 pubsub_flags={C.MULTI_ITEMS, C.NO_MAX}, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1737 use_verbose=True, |
3028 | 1738 help=_("search items corresponding to filters"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1739 ) |
2316 | 1740 |
1741 @property | |
1742 def etree(self): | |
1743 """load lxml.etree only if needed""" | |
1744 if self._etree is None: | |
1745 from lxml import etree | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1746 |
2316 | 1747 self._etree = etree |
1748 return self._etree | |
1749 | |
1750 def filter_opt(self, value, type_): | |
1751 return (type_, value) | |
1752 | |
1753 def filter_flag(self, value, type_): | |
1754 value = C.bool(value) | |
1755 return (type_, value) | |
1756 | |
1757 def add_parser_options(self): | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1758 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1759 "-D", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1760 "--max-depth", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1761 type=int, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1762 default=0, |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1763 help=_( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1764 "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
|
1765 "DEFAULT: 0)" |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1766 ), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1767 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1768 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
|
1769 "-M", |
92af49cde255
jp (base): MAM and RSM arguments can now be used for pubsub commands:
Goffi <goffi@goffi.org>
parents:
2761
diff
changeset
|
1770 "--node-max", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1771 type=int, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1772 default=30, |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1773 help=_( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1774 "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
|
1775 "DEFAULT: 30)".format(C.NO_LIMIT) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1776 ), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1777 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1778 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1779 "-N", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1780 "--namespace", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1781 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1782 nargs=2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1783 default=[], |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1784 metavar="NAME NAMESPACE", |
3028 | 1785 help=_("namespace to use for xpath"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1786 ) |
2316 | 1787 |
1788 # filters | |
3028 | 1789 filter_text = partial(self.filter_opt, type_="text") |
1790 filter_re = partial(self.filter_opt, type_="regex") | |
1791 filter_xpath = partial(self.filter_opt, type_="xpath") | |
1792 filter_python = partial(self.filter_opt, type_="python") | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1793 filters = self.parser.add_argument_group( |
3028 | 1794 _("filters"), |
1795 _("only items corresponding to following filters will be kept"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1796 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1797 filters.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1798 "-t", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1799 "--text", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1800 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1801 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1802 type=filter_text, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1803 metavar="TEXT", |
3028 | 1804 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
|
1805 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1806 filters.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1807 "-r", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1808 "--regex", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1809 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1810 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1811 type=filter_re, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1812 metavar="EXPRESSION", |
3028 | 1813 help=_("like --text but using a regular expression"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1814 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1815 filters.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1816 "-x", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1817 "--xpath", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1818 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1819 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1820 type=filter_xpath, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1821 metavar="XPATH", |
3028 | 1822 help=_("filter items which has elements matching this xpath"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1823 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1824 filters.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1825 "-P", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1826 "--python", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1827 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1828 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1829 type=filter_python, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1830 metavar="PYTHON_CODE", |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1831 help=_( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1832 "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
|
1833 '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
|
1834 "lxml's etree.Element" |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1835 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1836 ) |
2316 | 1837 |
1838 # filters flags | |
3028 | 1839 flag_case = partial(self.filter_flag, type_="ignore-case") |
1840 flag_invert = partial(self.filter_flag, type_="invert") | |
1841 flag_dotall = partial(self.filter_flag, type_="dotall") | |
1842 flag_matching = partial(self.filter_flag, type_="only-matching") | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1843 flags = self.parser.add_argument_group( |
3028 | 1844 _("filters flags"), |
1845 _("filters modifiers (change behaviour of following filters)"), | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1846 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1847 flags.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1848 "-C", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1849 "--ignore-case", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1850 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1851 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1852 type=flag_case, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1853 const=("ignore-case", True), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1854 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1855 metavar="BOOLEAN", |
3028 | 1856 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
|
1857 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1858 flags.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1859 "-I", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1860 "--invert", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1861 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1862 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1863 type=flag_invert, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1864 const=("invert", True), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1865 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1866 metavar="BOOLEAN", |
3028 | 1867 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
|
1868 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1869 flags.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1870 "-A", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1871 "--dot-all", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1872 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1873 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1874 type=flag_dotall, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1875 const=("dotall", True), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1876 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1877 metavar="BOOLEAN", |
3028 | 1878 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
|
1879 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1880 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
|
1881 "-k", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1882 "--only-matching", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1883 action="append", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1884 dest="filters", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1885 type=flag_matching, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1886 const=("only-matching", True), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1887 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1888 metavar="BOOLEAN", |
3028 | 1889 help=_("keep only the matching part of the item"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1890 ) |
2316 | 1891 |
1892 # action | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1893 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1894 "action", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1895 default="print", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1896 nargs="?", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1897 choices=("print", "exec", "external"), |
3028 | 1898 help=_("action to do on found items (DEFAULT: print)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1899 ) |
2316 | 1900 self.parser.add_argument("command", nargs=argparse.REMAINDER) |
1901 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1902 async def get_items(self, depth, service, node, items): |
2316 | 1903 self.to_get += 1 |
3040 | 1904 try: |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1905 ps_result = data_format.deserialise( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1906 await self.host.bridge.ps_items_get( |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1907 service, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1908 node, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1909 self.args.node_max, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1910 items, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1911 "", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1912 self.get_pubsub_extra(), |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1913 self.profile, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1914 ) |
3040 | 1915 ) |
1916 except Exception as e: | |
1917 self.disp( | |
1918 f"can't get pubsub items at {service} (node: {node}): {e}", | |
1919 error=True, | |
1920 ) | |
1921 self.to_get -= 1 | |
1922 else: | |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
1923 await self.search(ps_result, depth) |
2316 | 1924 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1925 def _check_pubsub_url(self, match, found_nodes): |
2316 | 1926 """check that the matched URL is an xmpp: one |
1927 | |
1928 @param found_nodes(list[unicode]): found_nodes | |
1929 this list will be filled while xmpp: URIs are discovered | |
1930 """ | |
1931 url = match.group(0) | |
3028 | 1932 if url.startswith("xmpp"): |
2316 | 1933 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1934 url_data = uri.parse_xmpp_uri(url) |
2316 | 1935 except ValueError: |
1936 return | |
3028 | 1937 if url_data["type"] == "pubsub": |
1938 found_node = {"service": url_data["path"], "node": url_data["node"]} | |
1939 if "item" in url_data: | |
1940 found_node["item"] = url_data["item"] | |
2316 | 1941 found_nodes.append(found_node) |
1942 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1943 async def get_sub_nodes(self, item, depth): |
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1944 """look for pubsub URIs in item, and get_items on the linked nodes""" |
2316 | 1945 found_nodes = [] |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1946 checkURI = partial(self._check_pubsub_url, found_nodes=found_nodes) |
2316 | 1947 strings.RE_URL.sub(checkURI, item) |
1948 for data in found_nodes: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
1949 await self.get_items( |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1950 depth + 1, |
3028 | 1951 data["service"], |
1952 data["node"], | |
1953 [data["item"]] if "item" in data else [], | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1954 ) |
2316 | 1955 |
1956 def parseXml(self, item): | |
1957 try: | |
1958 return self.etree.fromstring(item) | |
1959 except self.etree.XMLSyntaxError: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1960 self.disp( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1961 _( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1962 "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
|
1963 "somewhere before and we have no more XML" |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1964 ), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1965 error=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1966 ) |
2316 | 1967 self.host.quit(C.EXIT_BAD_ARG) |
1968 | |
1969 def filter(self, item): | |
1970 """apply filters given on command line | |
1971 | |
1972 if only-matching is used, item may be modified | |
1973 @return (tuple[bool, unicode]): a tuple with: | |
1974 - keep: True if item passed the filters | |
1975 - item: it is returned in case of modifications | |
1976 """ | |
1977 ignore_case = False | |
1978 invert = False | |
1979 dotall = False | |
1980 only_matching = False | |
1981 item_xml = None | |
1982 for type_, value in self.args.filters: | |
1983 keep = True | |
1984 | |
1985 ## filters | |
1986 | |
3028 | 1987 if type_ == "text": |
2316 | 1988 if ignore_case: |
1989 if value.lower() not in item.lower(): | |
1990 keep = False | |
1991 else: | |
1992 if value not in item: | |
1993 keep = False | |
1994 if keep and only_matching: | |
1995 # doesn't really make sens to keep a fixed string | |
1996 # so we raise an error | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
1997 self.host.disp( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
1998 _("--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
|
1999 error=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2000 ) |
2316 | 2001 self.host.quit(C.EXIT_BAD_ARG) |
3028 | 2002 elif type_ == "regex": |
2316 | 2003 flags = self.RE_FLAGS |
2004 if ignore_case: | |
2005 flags |= re.IGNORECASE | |
2006 if dotall: | |
2007 flags |= re.DOTALL | |
2008 match = re.search(value, item, flags) | |
2009 keep = match != None | |
2010 if keep and only_matching: | |
2011 item = match.group() | |
2012 item_xml = None | |
3028 | 2013 elif type_ == "xpath": |
2316 | 2014 if item_xml is None: |
2015 item_xml = self.parseXml(item) | |
2016 try: | |
2017 elts = item_xml.xpath(value, namespaces=self.args.namespace) | |
2018 except self.etree.XPathEvalError as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2019 self.disp(_("can't use xpath: {reason}").format(reason=e), error=True) |
2316 | 2020 self.host.quit(C.EXIT_BAD_ARG) |
2021 keep = bool(elts) | |
2022 if keep and only_matching: | |
2023 item_xml = elts[0] | |
2024 try: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2025 item = self.etree.tostring(item_xml, encoding="unicode") |
2316 | 2026 except TypeError: |
2027 # we have a string only, not an element | |
3028 | 2028 item = str(item_xml) |
2316 | 2029 item_xml = None |
3028 | 2030 elif type_ == "python": |
2316 | 2031 if item_xml is None: |
2032 item_xml = self.parseXml(item) | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2033 cmd_ns = {"etree": self.etree, "item": item, "item_xml": item_xml} |
2316 | 2034 try: |
2035 keep = eval(value, cmd_ns) | |
2036 except SyntaxError as e: | |
3028 | 2037 self.disp(str(e), error=True) |
2316 | 2038 self.host.quit(C.EXIT_BAD_ARG) |
2039 | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2040 ## flags |
2316 | 2041 |
3028 | 2042 elif type_ == "ignore-case": |
2316 | 2043 ignore_case = value |
3028 | 2044 elif type_ == "invert": |
2316 | 2045 invert = value |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2046 # we need to continue, else loop would end here |
2316 | 2047 continue |
3028 | 2048 elif type_ == "dotall": |
2316 | 2049 dotall = value |
3028 | 2050 elif type_ == "only-matching": |
2316 | 2051 only_matching = value |
2052 else: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2053 raise exceptions.InternalError( |
3028 | 2054 _("unknown filter type {type}").format(type=type_) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2055 ) |
2316 | 2056 |
2057 if invert: | |
2058 keep = not keep | |
2059 if not keep: | |
2060 return False, item | |
2061 | |
2062 return True, item | |
2063 | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2064 async def do_item_action(self, item, metadata): |
2316 | 2065 """called when item has been kepts and the action need to be done |
2066 | |
2067 @param item(unicode): accepted item | |
2068 """ | |
2069 action = self.args.action | |
3028 | 2070 if action == "print" or self.host.verbosity > 0: |
2316 | 2071 try: |
3040 | 2072 await self.output(item) |
2316 | 2073 except self.etree.XMLSyntaxError: |
2074 # item is not valid XML, but a string | |
2075 # can happen when --only-matching is used | |
2076 self.disp(item) | |
2077 if action in self.EXEC_ACTIONS: | |
2078 item_elt = self.parseXml(item) | |
3028 | 2079 if action == "exec": |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2080 use = { |
3028 | 2081 "service": metadata["service"], |
2082 "node": metadata["node"], | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2083 "item": item_elt.get("id"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2084 "profile": self.profile, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2085 } |
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
|
2086 # 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
|
2087 # else it would be modified |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2088 parser_args, use_args = arg_tools.get_use_args( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2089 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
|
2090 ) |
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
|
2091 cmd_args = sys.argv[0:1] + parser_args + use_args |
2316 | 2092 else: |
2093 cmd_args = self.args.command | |
2094 | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2095 self.disp( |
3028 | 2096 "COMMAND: {command}".format( |
2097 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
|
2098 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2099 2, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2100 ) |
3028 | 2101 if action == "exec": |
3040 | 2102 p = await asyncio.create_subprocess_exec(*cmd_args) |
2103 ret = await p.wait() | |
2316 | 2104 else: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2105 p = await asyncio.create_subprocess_exec(*cmd_args, stdin=subprocess.PIPE) |
3040 | 2106 await p.communicate(item.encode(sys.getfilesystemencoding())) |
2107 ret = p.returncode | |
2316 | 2108 if ret != 0: |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2109 self.disp( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2110 A.color( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2111 C.A_FAILURE, |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2112 _("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
|
2113 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2114 ) |
2316 | 2115 |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2116 async def search(self, ps_result, depth): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2117 """callback of get_items |
2316 | 2118 |
2119 this method filters items, get sub nodes if needed, | |
2120 do the requested action, and exit the command when everything is done | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2121 @param items_data(tuple): result of get_items |
2316 | 2122 @param depth(int): current depth level |
2123 0 for first node, 1 for first children, and so on | |
2124 """ | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2125 for item in ps_result["items"]: |
2316 | 2126 if depth < self.args.max_depth: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2127 await self.get_sub_nodes(item, depth) |
2316 | 2128 keep, item = self.filter(item) |
2129 if not keep: | |
2130 continue | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2131 await self.do_item_action(item, ps_result) |
2316 | 2132 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2133 # we check if we got all get_items results |
2316 | 2134 self.to_get -= 1 |
2135 if self.to_get == 0: | |
2136 # yes, we can quit | |
2137 self.host.quit() | |
2138 assert self.to_get > 0 | |
2139 | |
3040 | 2140 async def start(self): |
2316 | 2141 if self.args.command: |
2142 if self.args.action not in self.EXEC_ACTIONS: | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2143 self.parser.error( |
3028 | 2144 _("Command can only be used with {actions} actions").format( |
2145 actions=", ".join(self.EXEC_ACTIONS) | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2146 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2147 ) |
2316 | 2148 else: |
2149 if self.args.action in self.EXEC_ACTIONS: | |
3028 | 2150 self.parser.error(_("you need to specify a command to execute")) |
2316 | 2151 if not self.args.node: |
2152 # TODO: handle get service affiliations when node is not set | |
3028 | 2153 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
|
2154 # 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
|
2155 # when it reach 0 again, the command is finished |
2316 | 2156 self.to_get = 0 |
2157 self._etree = None | |
2158 if self.args.filters is None: | |
2159 self.args.filters = [] | |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2160 self.args.namespace = dict( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2161 self.args.namespace + [("pubsub", "http://jabber.org/protocol/pubsub")] |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2162 ) |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2163 await self.get_items(0, self.args.service, self.args.node, self.args.items) |
2316 | 2164 |
2165 | |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2166 class Transform(base.CommandBase): |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2167 def __init__(self, host): |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2168 base.CommandBase.__init__( |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2169 self, |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2170 host, |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2171 "transform", |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2172 use_pubsub=True, |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2173 pubsub_flags={C.NODE, C.MULTI_ITEMS}, |
3028 | 2174 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
|
2175 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2176 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2177 def add_parser_options(self): |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2178 self.parser.add_argument( |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2179 "--apply", |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2180 action="store_true", |
3028 | 2181 help=_("apply transformation (DEFAULT: do a dry run)"), |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2182 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2183 self.parser.add_argument( |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2184 "--admin", |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2185 action="store_true", |
3028 | 2186 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
|
2187 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2188 self.parser.add_argument( |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2189 "-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
|
2190 "--ignore-errors", |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2191 action="store_true", |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2192 help=_( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2193 "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
|
2194 ), |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2195 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2196 self.parser.add_argument( |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2197 "-A", |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2198 "--all", |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2199 action="store_true", |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2200 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
|
2201 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2202 self.parser.add_argument( |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2203 "command_path", |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2204 help=_( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2205 "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
|
2206 "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
|
2207 '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
|
2208 ), |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2209 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2210 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2211 async def ps_items_send_cb(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
|
2212 if item_ids: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2213 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2214 _("items published with ids {item_ids}").format( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2215 item_ids=", ".join(item_ids) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2216 ) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2217 ) |
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
|
2218 else: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2219 self.disp(_("items published")) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2220 if self.args.all: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2221 return await self.handle_next_page(metadata) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2222 else: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2223 self.host.quit() |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2224 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2225 async def handle_next_page(self, metadata): |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2226 """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
|
2227 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2228 use to handle --all option |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2229 @param metadata(dict): metadata as returned by ps_items_get |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2230 """ |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2231 try: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2232 last = metadata["rsm"]["last"] |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2233 index = int(metadata["rsm"]["index"]) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2234 count = int(metadata["rsm"]["count"]) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2235 except KeyError: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2236 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2237 _("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
|
2238 ) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2239 self.host.quit(C.EXIT_MISSING_FEATURE) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2240 except ValueError as e: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2241 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2242 _("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
|
2243 error=True, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2244 ) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2245 self.host.quit(C.EXIT_ERROR) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2246 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2247 if index + self.args.rsm_max >= count: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2248 self.disp(_("All items transformed")) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2249 self.host.quit(0) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2250 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2251 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2252 _("Retrieving next page ({page_idx}/{page_total})").format( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2253 page_idx=int(index / self.args.rsm_max) + 1, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2254 page_total=int(count / self.args.rsm_max), |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2255 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2256 ) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2257 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2258 extra = self.get_pubsub_extra() |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2259 extra["rsm_after"] = last |
3040 | 2260 try: |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2261 ps_result = await data_format.deserialise( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2262 self.host.bridge.ps_items_get( |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2263 self.args.service, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2264 self.args.node, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2265 self.args.rsm_max, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2266 self.args.items, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2267 "", |
3586
5f65f4e9f8cb
plugin XEP-0060: getItems extra is now serialised dict
Goffi <goffi@goffi.org>
parents:
3568
diff
changeset
|
2268 data_format.serialise(extra), |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2269 self.profile, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2270 ) |
3040 | 2271 ) |
2272 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2273 self.disp(f"can't retrieve items: {e}", error=True) |
3040 | 2274 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
2275 else: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2276 await self.ps_items_get_cb(ps_result) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2277 |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2278 async def ps_items_get_cb(self, ps_result): |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2279 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
|
2280 new_items = [] |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2281 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2282 for item in ps_result["items"]: |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2283 if self.check_duplicates: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2284 # this is used when we are not ordering by creation |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2285 # to avoid infinite loop |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2286 item_elt, __ = xml_tools.etree_parse(self, item) |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2287 item_id = item_elt.get("id") |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2288 if item_id in self.items_ids: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2289 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2290 _( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2291 "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
|
2292 "all items." |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2293 ).format(item_id=item_id) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2294 ) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2295 self.host.quit() |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2296 self.items_ids.append(item_id) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2297 |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2298 # we launch the command to filter the item |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2299 try: |
3040 | 2300 p = await asyncio.create_subprocess_exec( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2301 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
|
2302 ) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2303 except OSError as e: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2304 exit_code = C.EXIT_CMD_NOT_FOUND if e.errno == 2 else C.EXIT_ERROR |
3040 | 2305 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
|
2306 self.host.quit(exit_code) |
3040 | 2307 encoding = "utf-8" |
2308 cmd_std_out, cmd_std_err = await p.communicate(item.encode(encoding)) | |
2309 ret = p.returncode | |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2310 if ret != 0: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2311 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2312 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
|
2313 f"following item:\n\n{item}", |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2314 error=True, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2315 ) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2316 if self.args.ignore_errors: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2317 continue |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2318 else: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2319 self.host.quit(C.EXIT_CMD_ERROR) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2320 if cmd_std_err is not None: |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2321 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
|
2322 self.disp(cmd_std_err, error=True) |
3040 | 2323 cmd_std_out = cmd_std_out.decode(encoding).strip() |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2324 if cmd_std_out == "DELETE": |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2325 item_elt, __ = xml_tools.etree_parse(self, item) |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2326 item_id = item_elt.get("id") |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2327 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
|
2328 if self.args.apply: |
3040 | 2329 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2330 await self.host.bridge.ps_item_retract( |
3040 | 2331 self.args.service, |
2332 self.args.node, | |
2333 item_id, | |
2334 False, | |
2335 self.profile, | |
2336 ) | |
2337 except Exception as e: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2338 self.disp(f"can't delete item {item_id}: {e}", error=True) |
3040 | 2339 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2340 continue |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2341 elif cmd_std_out == "SKIP": |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2342 item_elt, __ = xml_tools.etree_parse(self, item) |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2343 item_id = item_elt.get("id") |
3028 | 2344 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
|
2345 continue |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2346 element, etree = xml_tools.etree_parse(self, cmd_std_out) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2347 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2348 # 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
|
2349 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
|
2350 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2351 "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
|
2352 xml=etree.tostring(element, encoding="unicode") |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2353 ), |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2354 error=True, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2355 ) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2356 self.host.quit(C.EXIT_DATA_ERROR) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2357 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2358 if not self.args.apply: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2359 # 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
|
2360 serialised = etree.tostring( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2361 element, encoding="unicode", pretty_print=True |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2362 ) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2363 self.disp(serialised) |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2364 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
|
2365 new_items.append(etree.tostring(element, encoding="unicode")) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2366 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2367 if not self.args.apply: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2368 # 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
|
2369 if self.args.all: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2370 return await self.handle_next_page(ps_result) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2371 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
|
2372 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
|
2373 if self.args.admin: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2374 bridge_method = self.host.bridge.ps_admin_items_send |
3040 | 2375 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2376 bridge_method = self.host.bridge.ps_items_send |
3040 | 2377 |
2378 try: | |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2379 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
|
2380 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
|
2381 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
|
2382 new_items, |
3028 | 2383 "", |
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
|
2384 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
|
2385 ) |
3040 | 2386 except Exception as e: |
2387 self.disp(f"can't send item: {e}", error=True) | |
2388 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
|
2389 else: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2390 await self.ps_items_send_cb(ps_items_send_result, metadata=ps_result) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2391 |
3040 | 2392 async def start(self): |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2393 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
|
2394 self.check_duplicates = True |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2395 self.items_ids = [] |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2396 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2397 A.color( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2398 A.FG_RED, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2399 A.BOLD, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2400 '/!\\ "--all" should be used with "--order-by creation" /!\\\n', |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2401 A.RESET, |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2402 "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
|
2403 "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
|
2404 "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
|
2405 ) |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2406 ) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2407 else: |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2408 self.check_duplicates = False |
3040 | 2409 |
2410 try: | |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2411 ps_result = data_format.deserialise( |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2412 await self.host.bridge.ps_items_get( |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2413 self.args.service, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2414 self.args.node, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2415 self.args.max, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2416 self.args.items, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2417 "", |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2418 self.get_pubsub_extra(), |
3312
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2419 self.profile, |
77177b13ff54
plugin XEP-0060: serialise psItemsGet result with data_format
Goffi <goffi@goffi.org>
parents:
3275
diff
changeset
|
2420 ) |
3040 | 2421 ) |
2422 except Exception as e: | |
2423 self.disp(f"can't retrieve items: {e}", error=True) | |
2424 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2425 else: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2426 await self.ps_items_get_cb(ps_result) |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2427 |
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
2428 |
2235
4db836386641
jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents:
2224
diff
changeset
|
2429 class Uri(base.CommandBase): |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2430 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2431 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2432 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2433 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2434 "uri", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2435 use_profile=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2436 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2437 pubsub_flags={C.NODE, C.SINGLE_ITEM}, |
3028 | 2438 help=_("build URI"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2439 ) |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2440 |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2441 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2442 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2443 "-p", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2444 "--profile", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2445 default=C.PROF_KEY_DEFAULT, |
3028 | 2446 help=_("profile (used when no server is specified)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2447 ) |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2448 |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2449 def display_uri(self, jid_): |
2239
17502e74c046
jp (pubsub/uri): fixed URI generation
Goffi <goffi@goffi.org>
parents:
2235
diff
changeset
|
2450 uri_args = {} |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2451 if not self.args.service: |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2452 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
|
2453 |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2454 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
|
2455 value = getattr(self.args, key) |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2456 if key == "service": |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2457 key = "path" |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2458 if value: |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2459 uri_args[key] = value |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2460 self.disp(uri.build_xmpp_uri("pubsub", **uri_args)) |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2461 self.host.quit() |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2462 |
3040 | 2463 async def start(self): |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2464 if not self.args.service: |
3040 | 2465 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2466 jid_ = await self.host.bridge.param_get_a_async( |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2467 "JabberID", "Connection", profile_key=self.args.profile |
3040 | 2468 ) |
2469 except Exception as e: | |
2470 self.disp(f"can't retrieve jid: {e}", error=True) | |
2471 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2472 else: | |
2473 self.display_uri(jid_) | |
2224
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2474 else: |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2475 self.display_uri(None) |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2476 |
87fcd4a7c7e4
jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents:
2221
diff
changeset
|
2477 |
3866
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2478 class AttachmentGet(base.CommandBase): |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2479 def __init__(self, host): |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2480 super().__init__( |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2481 host, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2482 "get", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2483 use_output=C.OUTPUT_LIST_DICT, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2484 use_pubsub=True, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2485 pubsub_flags={C.SERVICE, C.NODE, C.SINGLE_ITEM}, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2486 help=_("get data attached to an item"), |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2487 ) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2488 |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2489 def add_parser_options(self): |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2490 self.parser.add_argument( |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2491 "-j", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2492 "--jid", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2493 action="append", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2494 dest="jids", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2495 help=_( |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2496 "get attached data published only by those JIDs (DEFAULT: get all " |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2497 "attached data)" |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2498 ) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2499 ) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2500 |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2501 async def start(self): |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2502 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2503 attached_data, __ = await self.host.bridge.ps_attachments_get( |
3866
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2504 self.args.service, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2505 self.args.node, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2506 self.args.item, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2507 self.args.jids or [], |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2508 "", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2509 self.profile, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2510 ) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2511 except Exception as e: |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2512 self.disp(f"can't get attached data: {e}", error=True) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2513 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2514 else: |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2515 attached_data = data_format.deserialise(attached_data, type_check=list) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2516 await self.output(attached_data) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2517 self.host.quit(C.EXIT_OK) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2518 |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2519 |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2520 class AttachmentSet(base.CommandBase): |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2521 def __init__(self, host): |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2522 super().__init__( |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2523 host, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2524 "set", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2525 use_pubsub=True, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2526 pubsub_flags={C.SERVICE, C.NODE, C.SINGLE_ITEM}, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2527 help=_("attach data to an item"), |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2528 ) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2529 |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2530 def add_parser_options(self): |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2531 self.parser.add_argument( |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2532 "--replace", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2533 action="store_true", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2534 help=_( |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2535 "replace previous versions of attachments (DEFAULT: update previous " |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2536 "version)" |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2537 ) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2538 ) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2539 self.parser.add_argument( |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2540 "-N", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2541 "--noticed", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2542 metavar="BOOLEAN", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2543 nargs="?", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2544 default="keep", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2545 help=_("mark item as (un)noticed (DEFAULT: keep current value))") |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2546 ) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2547 self.parser.add_argument( |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2548 "-r", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2549 "--reactions", |
3889
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2550 # FIXME: to be replaced by "extend" when we stop supporting python 3.7 |
3866
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2551 action="append", |
3889
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2552 help=_("emojis to add to react to an item") |
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2553 ) |
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2554 self.parser.add_argument( |
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2555 "-R", |
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2556 "--reactions-remove", |
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2557 # FIXME: to be replaced by "extend" when we stop supporting python 3.7 |
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2558 action="append", |
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2559 help=_("emojis to remove from reactions to an item") |
3866
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2560 ) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2561 |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2562 async def start(self): |
3964
0f858aa0b92c
cli (pubsub/signature): add `sign` command:
Goffi <goffi@goffi.org>
parents:
3959
diff
changeset
|
2563 attachments_data = { |
3866
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2564 "service": self.args.service, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2565 "node": self.args.node, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2566 "id": self.args.item, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2567 "extra": {} |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2568 } |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2569 operation = "replace" if self.args.replace else "update" |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2570 if self.args.noticed != "keep": |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2571 if self.args.noticed is None: |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2572 self.args.noticed = C.BOOL_TRUE |
3964
0f858aa0b92c
cli (pubsub/signature): add `sign` command:
Goffi <goffi@goffi.org>
parents:
3959
diff
changeset
|
2573 attachments_data["extra"]["noticed"] = C.bool(self.args.noticed) |
3866
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2574 |
3889
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2575 if self.args.reactions or self.args.reactions_remove: |
3964
0f858aa0b92c
cli (pubsub/signature): add `sign` command:
Goffi <goffi@goffi.org>
parents:
3959
diff
changeset
|
2576 reactions = attachments_data["extra"]["reactions"] = { |
3889
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2577 "operation": operation |
3866
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2578 } |
3889
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2579 if self.args.replace: |
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2580 reactions["reactions"] = self.args.reactions |
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2581 else: |
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2582 reactions["add"] = self.args.reactions |
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2583 reactions["remove"] = self.args.reactions_remove |
1ab5fb468a41
cli (pubsub/attachment/set): update reactions handling:
Goffi <goffi@goffi.org>
parents:
3866
diff
changeset
|
2584 |
3866
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2585 |
3964
0f858aa0b92c
cli (pubsub/signature): add `sign` command:
Goffi <goffi@goffi.org>
parents:
3959
diff
changeset
|
2586 if not attachments_data["extra"]: |
3866
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2587 self.parser.error(_("At leat one attachment must be specified.")) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2588 |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2589 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2590 await self.host.bridge.ps_attachments_set( |
3964
0f858aa0b92c
cli (pubsub/signature): add `sign` command:
Goffi <goffi@goffi.org>
parents:
3959
diff
changeset
|
2591 data_format.serialise(attachments_data), |
3866
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2592 self.profile, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2593 ) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2594 except Exception as e: |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2595 self.disp(f"can't attach data to item: {e}", error=True) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2596 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2597 else: |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2598 self.disp("data attached") |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2599 self.host.quit(C.EXIT_OK) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2600 |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2601 |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2602 class Attachments(base.CommandBase): |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2603 subcommands = (AttachmentGet, AttachmentSet) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2604 |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2605 def __init__(self, host): |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2606 super().__init__( |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2607 host, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2608 "attachments", |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2609 use_profile=False, |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2610 help=_("set or retrieve items attachments"), |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2611 ) |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2612 |
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
2613 |
3965
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2614 class SignatureSign(base.CommandBase): |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2615 def __init__(self, host): |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2616 super().__init__( |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2617 host, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2618 "sign", |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2619 use_pubsub=True, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2620 pubsub_flags={C.NODE, C.SINGLE_ITEM}, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2621 help=_("sign an item"), |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2622 ) |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2623 |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2624 def add_parser_options(self): |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2625 pass |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2626 |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2627 async def start(self): |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2628 attachments_data = { |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2629 "service": self.args.service, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2630 "node": self.args.node, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2631 "id": self.args.item, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2632 "extra": { |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2633 # we set None to use profile's bare JID |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2634 "signature": {"signer": None} |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2635 } |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2636 } |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2637 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2638 await self.host.bridge.ps_attachments_set( |
3965
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2639 data_format.serialise(attachments_data), |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2640 self.profile, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2641 ) |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2642 except Exception as e: |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2643 self.disp(f"can't sign the item: {e}", error=True) |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2644 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2645 else: |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2646 self.disp(f"item {self.args.item!r} has been signed") |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2647 self.host.quit(C.EXIT_OK) |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2648 |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2649 |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2650 class SignatureCheck(base.CommandBase): |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2651 def __init__(self, host): |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2652 super().__init__( |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2653 host, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2654 "check", |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2655 use_output=C.OUTPUT_DICT, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2656 use_pubsub=True, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2657 pubsub_flags={C.SERVICE, C.NODE, C.SINGLE_ITEM}, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2658 help=_("check the validity of pubsub signature"), |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2659 ) |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2660 |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2661 def add_parser_options(self): |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2662 self.parser.add_argument( |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2663 "signature", |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2664 metavar="JSON", |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2665 help=_("signature data") |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2666 ) |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2667 |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2668 async def start(self): |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2669 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2670 ret_s = await self.host.bridge.ps_signature_check( |
3965
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2671 self.args.service, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2672 self.args.node, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2673 self.args.item, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2674 self.args.signature, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2675 self.profile, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2676 ) |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2677 except Exception as e: |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2678 self.disp(f"can't check signature: {e}", error=True) |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2679 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2680 else: |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2681 await self.output(data_format.deserialise((ret_s))) |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2682 self.host.quit() |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2683 |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2684 |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2685 class Signature(base.CommandBase): |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2686 subcommands = ( |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2687 SignatureSign, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2688 SignatureCheck, |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2689 ) |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2690 |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2691 def __init__(self, host): |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2692 super().__init__( |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2693 host, "signature", use_profile=False, help=_("items signatures") |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2694 ) |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2695 |
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
2696 |
3939
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2697 class SecretShare(base.CommandBase): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2698 def __init__(self, host): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2699 super().__init__( |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2700 host, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2701 "share", |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2702 use_pubsub=True, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2703 pubsub_flags={C.NODE}, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2704 help=_("share a secret to let other entity encrypt or decrypt items"), |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2705 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2706 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2707 def add_parser_options(self): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2708 self.parser.add_argument( |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2709 "-k", "--key", metavar="ID", dest="secret_ids", action="append", default=[], |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2710 help=_( |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2711 "only share secrets with those IDs (default: share all secrets of the " |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2712 "node)" |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2713 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2714 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2715 self.parser.add_argument( |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2716 "recipient", metavar="JID", help=_("entity who must get the shared secret") |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2717 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2718 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2719 async def start(self): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2720 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2721 await self.host.bridge.ps_secret_share( |
3939
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2722 self.args.recipient, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2723 self.args.service, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2724 self.args.node, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2725 self.args.secret_ids, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2726 self.profile, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2727 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2728 except Exception as e: |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2729 self.disp(f"can't share secret: {e}", error=True) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2730 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2731 else: |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2732 self.disp("secrets have been shared") |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2733 self.host.quit(C.EXIT_OK) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2734 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2735 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2736 class SecretRevoke(base.CommandBase): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2737 def __init__(self, host): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2738 super().__init__( |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2739 host, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2740 "revoke", |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2741 use_pubsub=True, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2742 pubsub_flags={C.NODE}, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2743 help=_("revoke an encrypted node secret"), |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2744 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2745 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2746 def add_parser_options(self): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2747 self.parser.add_argument( |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2748 "secret_id", help=_("ID of the secrets to revoke") |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2749 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2750 self.parser.add_argument( |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2751 "-r", "--recipient", dest="recipients", metavar="JID", action="append", |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2752 default=[], help=_( |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2753 "entity who must get the revocation notification (default: send to all " |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2754 "entities known to have the shared secret)" |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2755 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2756 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2757 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2758 async def start(self): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2759 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2760 await self.host.bridge.ps_secret_revoke( |
3939
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2761 self.args.service, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2762 self.args.node, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2763 self.args.secret_id, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2764 self.args.recipients, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2765 self.profile, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2766 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2767 except Exception as e: |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2768 self.disp(f"can't revoke secret: {e}", error=True) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2769 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2770 else: |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2771 self.disp("secret {self.args.secret_id} has been revoked.") |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2772 self.host.quit(C.EXIT_OK) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2773 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2774 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2775 class SecretRotate(base.CommandBase): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2776 def __init__(self, host): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2777 super().__init__( |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2778 host, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2779 "rotate", |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2780 use_pubsub=True, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2781 pubsub_flags={C.NODE}, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2782 help=_("revoke existing secrets, create a new one and send notifications"), |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2783 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2784 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2785 def add_parser_options(self): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2786 self.parser.add_argument( |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2787 "-r", "--recipient", dest="recipients", metavar="JID", action="append", |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2788 default=[], help=_( |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2789 "entity who must get the revocation and shared secret notifications " |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2790 "(default: send to all entities known to have the shared secret)" |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2791 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2792 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2793 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2794 async def start(self): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2795 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2796 await self.host.bridge.ps_secret_rotate( |
3939
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2797 self.args.service, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2798 self.args.node, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2799 self.args.recipients, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2800 self.profile, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2801 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2802 except Exception as e: |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2803 self.disp(f"can't rotate secret: {e}", error=True) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2804 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2805 else: |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2806 self.disp("secret has been rotated") |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2807 self.host.quit(C.EXIT_OK) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2808 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2809 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2810 class SecretList(base.CommandBase): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2811 def __init__(self, host): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2812 super().__init__( |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2813 host, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2814 "list", |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2815 use_pubsub=True, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2816 use_verbose=True, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2817 pubsub_flags={C.NODE}, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2818 help=_("list known secrets for a pubsub node"), |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2819 use_output=C.OUTPUT_LIST_DICT |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2820 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2821 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2822 def add_parser_options(self): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2823 pass |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2824 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2825 async def start(self): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2826 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2827 secrets = data_format.deserialise(await self.host.bridge.ps_secrets_list( |
3939
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2828 self.args.service, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2829 self.args.node, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2830 self.profile, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2831 ), type_check=list) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2832 except Exception as e: |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2833 self.disp(f"can't list node secrets: {e}", error=True) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2834 self.host.quit(C.EXIT_BRIDGE_ERRBACK) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2835 else: |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2836 if not self.verbosity: |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2837 # we don't print key if verbosity is not a least one, to avoid showing it |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2838 # on the screen accidentally |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2839 for secret in secrets: |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2840 del secret["key"] |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2841 await self.output(secrets) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2842 self.host.quit(C.EXIT_OK) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2843 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2844 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2845 class Secret(base.CommandBase): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2846 subcommands = (SecretShare, SecretRevoke, SecretRotate, SecretList) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2847 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2848 def __init__(self, host): |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2849 super().__init__( |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2850 host, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2851 "secret", |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2852 use_profile=False, |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2853 help=_("handle encrypted nodes secrets"), |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2854 ) |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2855 |
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
2856 |
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
|
2857 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
|
2858 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2859 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2860 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2861 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2862 "create", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2863 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2864 pubsub_flags={C.NODE}, |
3028 | 2865 help=_("create a Pubsub hook"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2866 ) |
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
|
2867 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2868 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2869 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2870 "-t", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2871 "--type", |
3028 | 2872 default="python", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2873 choices=("python", "python_file", "python_code"), |
3028 | 2874 help=_("hook type"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2875 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2876 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2877 "-P", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2878 "--persistent", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2879 action="store_true", |
3028 | 2880 help=_("make hook persistent across restarts"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2881 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2882 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2883 "hook_arg", |
3028 | 2884 help=_("argument of the hook (depend of the type)"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2885 ) |
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
|
2886 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2887 @staticmethod |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2888 def check_args(self): |
3028 | 2889 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
|
2890 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
|
2891 if not os.path.isfile(self.args.hook_arg): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2892 self.parser.error( |
3028 | 2893 _("{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
|
2894 ) |
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
|
2895 |
3040 | 2896 async def start(self): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2897 self.check_args(self) |
3040 | 2898 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2899 await self.host.bridge.ps_hook_add( |
3040 | 2900 self.args.service, |
2901 self.args.node, | |
2902 self.args.type, | |
2903 self.args.hook_arg, | |
2904 self.args.persistent, | |
2905 self.profile, | |
2906 ) | |
2907 except Exception as e: | |
2908 self.disp(f"can't create hook: {e}", error=True) | |
2909 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2910 else: | |
2911 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
|
2912 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2913 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2914 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
|
2915 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2916 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2917 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2918 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2919 "delete", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2920 use_pubsub=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2921 pubsub_flags={C.NODE}, |
3028 | 2922 help=_("delete a Pubsub hook"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2923 ) |
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
|
2924 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2925 def add_parser_options(self): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2926 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2927 "-t", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2928 "--type", |
3028 | 2929 default="", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2930 choices=("", "python", "python_file", "python_code"), |
3028 | 2931 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
|
2932 ) |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2933 self.parser.add_argument( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2934 "-a", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2935 "--arg", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2936 dest="hook_arg", |
3028 | 2937 default="", |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2938 help=_( |
3028 | 2939 "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
|
2940 ), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2941 ) |
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
|
2942 |
3040 | 2943 async def start(self): |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2944 HookCreate.check_args(self) |
3040 | 2945 try: |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2946 nb_deleted = await self.host.bridge.ps_hook_remove( |
3040 | 2947 self.args.service, |
2948 self.args.node, | |
2949 self.args.type, | |
2950 self.args.hook_arg, | |
2951 self.profile, | |
2952 ) | |
2953 except Exception as e: | |
2954 self.disp(f"can't delete hook: {e}", error=True) | |
2955 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2956 else: | |
3568
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2957 self.disp( |
04283582966f
core, frontends: fix invalid translatable strings.
Goffi <goffi@goffi.org>
parents:
3521
diff
changeset
|
2958 _("{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
|
2959 ) |
3040 | 2960 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
|
2961 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2962 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2963 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
|
2964 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2965 base.CommandBase.__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2966 self, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2967 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2968 "list", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2969 use_output=C.OUTPUT_LIST_DICT, |
3028 | 2970 help=_("list hooks of a profile"), |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2971 ) |
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
|
2972 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2973 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
|
2974 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
|
2975 |
3040 | 2976 async def start(self): |
2977 try: | |
4037
524856bd7b19
massive refactoring to switch from camelCase to snake_case:
Goffi <goffi@goffi.org>
parents:
3973
diff
changeset
|
2978 data = await self.host.bridge.ps_hook_list( |
3040 | 2979 self.profile, |
2980 ) | |
2981 except Exception as e: | |
2982 self.disp(f"can't list hooks: {e}", error=True) | |
2983 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
2984 else: | |
2985 if not data: | |
2986 self.disp(_("No hook found.")) | |
2987 await self.output(data) | |
2988 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
|
2989 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2990 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2991 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
|
2992 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
|
2993 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
2994 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2995 super(Hook, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2996 host, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2997 "hook", |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2998 use_profile=False, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
2999 use_verbose=True, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3000 help=_("trigger action on Pubsub notifications"), |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3001 ) |
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
|
3002 |
0b21d87c91cf
jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents:
2292
diff
changeset
|
3003 |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3004 class Pubsub(base.CommandBase): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3005 subcommands = ( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3006 Set, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3007 Get, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3008 Delete, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3009 Edit, |
3521
62f490eff51c
jp (pubsub, blog): `rename` commands implementation
Goffi <goffi@goffi.org>
parents:
3479
diff
changeset
|
3010 Rename, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3011 Subscribe, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3012 Unsubscribe, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3013 Subscriptions, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3014 Affiliations, |
3835
f599e0e36444
cli (pubsub): new `reference` subcommand to send references/mentions to pubsub items:
Goffi <goffi@goffi.org>
parents:
3758
diff
changeset
|
3015 Reference, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3016 Search, |
2777
ff1b40823b07
jp (pubsub): new "transform" command:
Goffi <goffi@goffi.org>
parents:
2773
diff
changeset
|
3017 Transform, |
3866
915fb230cb28
cli (blog, pubsub): new `attachments` subcommands:
Goffi <goffi@goffi.org>
parents:
3835
diff
changeset
|
3018 Attachments, |
3965
2695dafc5c4d
cli (pubsub/set,edit) add `--sign` argument:
Goffi <goffi@goffi.org>
parents:
3964
diff
changeset
|
3019 Signature, |
3939
8ae3e870be94
cli (pubsub): new `secret` subcommands:
Goffi <goffi@goffi.org>
parents:
3938
diff
changeset
|
3020 Secret, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3021 Hook, |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3022 Uri, |
3602
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
3023 Node, |
7241ce3b79dd
jp (pubsub): new `cache` subcommand with commands to `get`, `sync`, `purge` and `reset` pubsub cache
Goffi <goffi@goffi.org>
parents:
3601
diff
changeset
|
3024 Cache, |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3025 ) |
2191
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3026 |
a1a8233f89e8
jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff
changeset
|
3027 def __init__(self, host): |
2624
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3028 super(Pubsub, self).__init__( |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3029 host, "pubsub", use_profile=False, help=_("PubSub nodes/items management") |
56f94936df1e
code style reformatting using black
Goffi <goffi@goffi.org>
parents:
2562
diff
changeset
|
3030 ) |