annotate sat_frontends/jp/cmd_pubsub.py @ 3035:25af53e2990a

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