annotate sat_frontends/jp/cmd_pubsub.py @ 2777:ff1b40823b07

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