annotate sat_frontends/jp/cmd_pubsub.py @ 2624:56f94936df1e

code style reformatting using black
author Goffi <goffi@goffi.org>
date Wed, 27 Jun 2018 20:14:46 +0200
parents 26edcf3a30eb
children 4b693ea24d5f
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
2483
0046283a285d dates update
Goffi <goffi@goffi.org>
parents: 2456
diff changeset
5 # Copyright (C) 2009-2018 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
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
27 from functools import partial
2224
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
28 from sat.tools.common import uri
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
29 from sat.tools.common.ansi import ANSI as A
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
30 from sat_frontends.tools import jid, strings
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
31 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
32 import os.path
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
33 import re
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
34 import subprocess
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
35 import sys
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
36
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
37 __commands__ = ["Pubsub"]
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
38
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
39 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
40 PUBSUB_SCHEMA_TMP_DIR = PUBSUB_TMP_DIR + "_schema"
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
41 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
42
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
43 # 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
44
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
45
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
46 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
47 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
48 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
49 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
50 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
51 "info",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
52 use_output=C.OUTPUT_DICT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
53 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
54 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
55 help=_(u"retrieve node configuration"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
56 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
57 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
58
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
59 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
60 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
61 "-k",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
62 "--key",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
63 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
64 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
65 dest="keys",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
66 help=_(u"data key to filter"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
67 )
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
68
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
69 def removePrefix(self, key):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
70 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
71
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
72 def filterKey(self, key):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
73 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
74
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
75 def psNodeConfigurationGetCb(self, config_dict):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
76 key_filter = (lambda k: True) if not self.args.keys else self.filterKey
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
77 config_dict = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
78 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
79 }
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
80 self.output(config_dict)
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
81 self.host.quit()
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
82
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
83 def psNodeConfigurationGetEb(self, failure_):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
84 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
85 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
86 )
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
87 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
88
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
89 def start(self):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
90 self.host.bridge.psNodeConfigurationGet(
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
91 self.args.service,
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
92 self.args.node,
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
93 self.profile,
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
94 callback=self.psNodeConfigurationGetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
95 errback=self.psNodeConfigurationGetEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
96 )
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
97
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
98
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
99 class NodeCreate(base.CommandBase):
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
100 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
101 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
102 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
103 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
104 "create",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
105 use_output=C.OUTPUT_DICT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
106 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
107 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
108 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
109 help=_(u"create a node"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
110 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
111 self.need_loop = True
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
112
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
113 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
114 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
115 "-f",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
116 "--field",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
117 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
118 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
119 nargs=2,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
120 dest="fields",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
121 default=[],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
122 metavar=(u"KEY", u"VALUE"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
123 help=_(u"configuration field to set"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
124 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
125 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
126 "-F",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
127 "--full-prefix",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
128 action="store_true",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
129 help=_(u'don\'t prepend "pubsub#" prefix to field names'),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
130 )
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
131
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
132 def psNodeCreateCb(self, node_id):
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
133 if self.host.verbosity:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
134 announce = _(u"node created successfully: ")
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
135 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
136 announce = u""
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
137 self.disp(announce + node_id)
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
138 self.host.quit()
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
139
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
140 def psNodeCreateEb(self, failure_):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
141 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
142 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
143
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
144 def start(self):
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
145 if not self.args.full_prefix:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
146 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
147 else:
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
148 options = dict(self.args.fields)
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
149 self.host.bridge.psNodeCreate(
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
150 self.args.service,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
151 self.args.node,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
152 options,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
153 self.profile,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
154 callback=self.psNodeCreateCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
155 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
156 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
157 msg=_(u"can't create node: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
158 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
159 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
160 )
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
161
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
162
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
163 class NodeDelete(base.CommandBase):
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
164 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
165 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
166 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
167 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
168 "delete",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
169 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
170 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
171 help=_(u"delete a node"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
172 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
173 self.need_loop = True
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
174
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
175 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
176 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
177 "-f",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
178 "--force",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
179 action="store_true",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
180 help=_(u"delete node without confirmation"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
181 )
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
182
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
183 def psNodeDeleteCb(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
184 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
185 self.host.quit()
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
186
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
187 def start(self):
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
188 if not self.args.force:
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
189 if not self.args.service:
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
190 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
191 node_id=self.args.node
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
192 )
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
193 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
194 message = _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
195 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
196 ).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
197 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
198
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
199 self.host.bridge.psNodeDelete(
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
200 self.args.service,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
201 self.args.node,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
202 self.profile,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
203 callback=self.psNodeDeleteCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
204 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
205 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
206 msg=_(u"can't delete node: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
207 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
208 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
209 )
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
210
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
211
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
212 class NodeSet(base.CommandBase):
2199
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
213 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
214 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
215 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
216 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
217 "set",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
218 use_output=C.OUTPUT_DICT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
219 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
220 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
221 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
222 help=_(u"set node configuration"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
223 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
224 self.need_loop = True
2199
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
225
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
226 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
227 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
228 "-f",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
229 "--field",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
230 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
231 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
232 nargs=2,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
233 dest="fields",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
234 required=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
235 metavar=(u"KEY", u"VALUE"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
236 help=_(u"configuration field to set (required)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
237 )
2199
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
238
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
239 def psNodeConfigurationSetCb(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
240 self.disp(_(u"node configuration successful"), 1)
2199
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
241 self.host.quit()
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
242
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
243 def psNodeConfigurationSetEb(self, failure_):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
244 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
245 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
246 )
2199
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
247 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
248
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
249 def getKeyName(self, k):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
250 if not k.startswith(u"pubsub#"):
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
251 return u"pubsub#" + k
2199
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
252 else:
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
253 return k
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
254
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
255 def start(self):
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
256 self.host.bridge.psNodeConfigurationSet(
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
257 self.args.service,
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
258 self.args.node,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
259 {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
260 self.profile,
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
261 callback=self.psNodeConfigurationSetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
262 errback=self.psNodeConfigurationSetEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
263 )
2199
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
264
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
265
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
266 class NodeAffiliationsGet(base.CommandBase):
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
267 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
268 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
269 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
270 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
271 "get",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
272 use_output=C.OUTPUT_DICT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
273 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
274 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
275 help=_(u"retrieve node affiliations (for node owner)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
276 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
277 self.need_loop = True
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
278
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
279 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
280 pass
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
281
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
282 def psNodeAffiliationsGetCb(self, affiliations):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
283 self.output(affiliations)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
284 self.host.quit()
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
285
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
286 def psNodeAffiliationsGetEb(self, failure_):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
287 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
288 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
289 )
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
290 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
291
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
292 def start(self):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
293 self.host.bridge.psNodeAffiliationsGet(
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
294 self.args.service,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
295 self.args.node,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
296 self.profile,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
297 callback=self.psNodeAffiliationsGetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
298 errback=self.psNodeAffiliationsGetEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
299 )
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
300
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
301
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
302 class NodeAffiliationsSet(base.CommandBase):
2207
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
303 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
304 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
305 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
306 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
307 "set",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
308 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
309 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
310 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
311 help=_(u"set affiliations (for node owner)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
312 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
313 self.need_loop = True
2207
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
314
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
315 def add_parser_options(self):
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
316 # 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
317 # (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
318 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
319 "-a",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
320 "--affiliation",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
321 dest="affiliations",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
322 metavar=("JID", "AFFILIATION"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
323 required=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
324 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
325 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
326 nargs=2,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
327 help=_(u"entity/affiliation couple(s)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
328 )
2207
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
329
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
330 def psNodeAffiliationsSetCb(self):
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
331 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
332 self.host.quit()
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
333
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
334 def psNodeAffiliationsSetEb(self, failure_):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
335 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
336 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
337 )
2207
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
338 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
339
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
340 def start(self):
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
341 affiliations = dict(self.args.affiliations)
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
342 self.host.bridge.psNodeAffiliationsSet(
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
343 self.args.service,
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
344 self.args.node,
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
345 affiliations,
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
346 self.profile,
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
347 callback=self.psNodeAffiliationsSetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
348 errback=self.psNodeAffiliationsSetEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
349 )
2207
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
350
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
351
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
352 class NodeAffiliations(base.CommandBase):
2207
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
353 subcommands = (NodeAffiliationsGet, NodeAffiliationsSet)
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
354
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
355 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
356 super(NodeAffiliations, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
357 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
358 "affiliations",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
359 use_profile=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
360 help=_(u"set or retrieve node affiliations"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
361 )
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
362
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
363
2339
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
364 class NodeSubscriptionsGet(base.CommandBase):
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
365 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
366 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
367 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
368 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
369 "get",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
370 use_output=C.OUTPUT_DICT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
371 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
372 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
373 help=_(u"retrieve node subscriptions (for node owner)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
374 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
375 self.need_loop = True
2339
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
376
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
377 def add_parser_options(self):
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
378 pass
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
379
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
380 def psNodeSubscriptionsGetCb(self, subscriptions):
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
381 self.output(subscriptions)
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
382 self.host.quit()
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
383
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
384 def psNodeSubscriptionsGetEb(self, failure_):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
385 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
386 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
387 )
2339
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
388 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
389
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
390 def start(self):
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
391 self.host.bridge.psNodeSubscriptionsGet(
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
392 self.args.service,
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
393 self.args.node,
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
394 self.profile,
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
395 callback=self.psNodeSubscriptionsGetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
396 errback=self.psNodeSubscriptionsGetEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
397 )
2339
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
398
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 class StoreSubscriptionAction(argparse.Action):
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
401 """Action which handle subscription parameter for owner
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
402
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
403 list is given by pairs: jid and subscription state
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
404 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
405 """
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 def __call__(self, parser, namespace, values, option_string):
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
408 dest_dict = getattr(namespace, self.dest)
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
409 while values:
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
410 jid_s = values.pop(0)
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
411 try:
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
412 subscription = values.pop(0)
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
413 except IndexError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
414 subscription = "subscribed"
2339
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
415 if subscription not in ALLOWED_SUBSCRIPTIONS_OWNER:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
416 parser.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
417 _(u"subscription must be one of {}").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
418 u", ".join(ALLOWED_SUBSCRIPTIONS_OWNER)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
419 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
420 )
2339
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
421 dest_dict[jid_s] = subscription
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
422
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 class NodeSubscriptionsSet(base.CommandBase):
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
425 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
426 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
427 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
428 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
429 "set",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
430 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
431 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
432 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
433 help=_(u"set/modify subscriptions (for node owner)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
434 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
435 self.need_loop = True
2339
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
436
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
437 def add_parser_options(self):
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
438 # 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
439 # (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
440 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
441 "-S",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
442 "--subscription",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
443 dest="subscriptions",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
444 default={},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
445 nargs="+",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
446 metavar=("JID [SUSBSCRIPTION]"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
447 required=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
448 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
449 action=StoreSubscriptionAction,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
450 help=_(u"entity/subscription couple(s)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
451 )
2339
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
452
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
453 def psNodeSubscriptionsSetCb(self):
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
454 self.disp(_(u"subscriptions have been set"), 1)
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
455 self.host.quit()
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
456
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
457 def psNodeSubscriptionsSetEb(self, failure_):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
458 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
459 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
460 )
2339
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
461 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
462
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
463 def start(self):
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
464 self.host.bridge.psNodeSubscriptionsSet(
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
465 self.args.service,
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
466 self.args.node,
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
467 self.args.subscriptions,
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
468 self.profile,
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
469 callback=self.psNodeSubscriptionsSetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
470 errback=self.psNodeSubscriptionsSetEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
471 )
2339
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
472
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 class NodeSubscriptions(base.CommandBase):
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
475 subcommands = (NodeSubscriptionsGet, NodeSubscriptionsSet)
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
476
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
477 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
478 super(NodeSubscriptions, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
479 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
480 "subscriptions",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
481 use_profile=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
482 help=_(u"get or modify node subscriptions"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
483 )
2339
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
484
d94e932be8b3 jp (pubsub/node): added subscriptions subcommand:
Goffi <goffi@goffi.org>
parents: 2320
diff changeset
485
2351
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
486 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
487 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
488 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
489 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
490 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
491 "set",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
492 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
493 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
494 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
495 help=_(u"set/replace a schema"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
496 )
2351
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
497 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
498
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
499 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
500 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
501
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
502 def psSchemaSetCb(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
503 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
504 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
505
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
506 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
507 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
508 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
509 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
510 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
511 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
512 callback=self.psSchemaSetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
513 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
514 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
515 msg=_(u"can't set schema: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
516 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
517 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
518 )
2351
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
519
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 class NodeSchemaEdit(base.CommandBase, common.BaseEdit):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
522 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
523
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
524 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
525 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
526 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
527 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
528 "edit",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
529 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
530 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
531 use_draft=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
532 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
533 help=_(u"edit a schema"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
534 )
2351
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
535 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
536 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
537
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
538 def add_parser_options(self):
2532
772447ec070f jp: pubsub options refactoring:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
539 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
540
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
541 def psSchemaSetCb(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
542 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
543 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
544
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
545 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
546 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
547 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
548 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
549 schema,
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
550 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
551 callback=self.psSchemaSetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
552 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
553 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
554 msg=_(u"can't set schema: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
555 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
556 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
557 )
2351
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
558
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
559 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
560 try:
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
561 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
562 except ImportError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
563 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
564 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
565 error=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
566 )
2351
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
567 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
568 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
569 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
570 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
571 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
572 schema_elt = etree.fromstring(schema, parser)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
573 content_file_obj.write(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
574 etree.tostring(schema_elt, encoding="utf-8", pretty_print=True)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
575 )
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
576 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
577 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
578
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
579 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
580 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
581 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
582 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
583 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
584 callback=self.psSchemaGetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
585 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
586 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
587 msg=_(u"can't edit schema: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
588 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
589 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
590 )
2351
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
591
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 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
594 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
595 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
596 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
597 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
598 "get",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
599 use_output=C.OUTPUT_XML,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
600 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
601 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
602 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
603 help=_(u"get schema"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
604 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
605 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
606
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
607 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
608 pass
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
609
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
610 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
611 if not schema:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
612 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
613 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
614 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
615 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
616
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
617 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
618 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
619 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
620 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
621 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
622 callback=self.psSchemaGetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
623 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
624 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
625 msg=_(u"can't get schema: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
626 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
627 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
628 )
2351
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
629
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 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
632 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
633
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
634 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
635 super(NodeSchema, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
636 host, "schema", use_profile=False, help=_(u"data schema manipulation")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
637 )
2351
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
638
3c0a3fae1862 jp (pubsub/node): added schema (set/edit/get) commands to manipulate PubSub node schema
Goffi <goffi@goffi.org>
parents: 2339
diff changeset
639
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
640 class Node(base.CommandBase):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
641 subcommands = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
642 NodeInfo,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
643 NodeCreate,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
644 NodeDelete,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
645 NodeSet,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
646 NodeAffiliations,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
647 NodeSubscriptions,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
648 NodeSchema,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
649 )
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
650
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
651 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
652 super(Node, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
653 host, "node", use_profile=False, help=_("node handling")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
654 )
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
655
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
656
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
657 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
658 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
659 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
660 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
661 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
662 "set",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
663 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
664 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
665 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
666 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
667 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
668
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 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
670 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
671 "item",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
672 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
673 nargs="?",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
674 default=u"",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
675 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
676 )
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
677
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 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
679 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
680 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
681 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
682 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
683 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
684
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 def start(self):
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 try:
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
687 from lxml import etree
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
688 except ImportError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
689 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
690 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
691 error=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
692 )
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
693 self.host.quit(1)
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
694 try:
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
695 element = etree.parse(sys.stdin).getroot()
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
696 except Exception as e:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
697 self.parser.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
698 _(u"Can't parse the payload XML in input: {msg}").format(msg=e)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
699 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
700 if element.tag in ("item", "{http://jabber.org/protocol/pubsub}item"):
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
701 if len(element) > 1:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
702 self.parser.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
703 _(u"<item> can only have one child element (the payload)")
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 element = element[0]
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
706 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
707
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
708 self.host.bridge.psItemSend(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
709 self.args.service,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
710 self.args.node,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
711 payload,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
712 self.args.item,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
713 {},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
714 self.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
715 callback=self.psItemsSendCb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
716 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
717 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
718 msg=_(u"can't send item: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
719 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
720 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
721 )
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
722
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
723
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
724 class Get(base.CommandBase):
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
725 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
726 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
727 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
728 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
729 "get",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
730 use_output=C.OUTPUT_LIST_XML,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
731 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
732 pubsub_flags={C.NODE, C.MULTI_ITEMS},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
733 help=_(u"get pubsub item(s)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
734 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
735 self.need_loop = True
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
736
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
737 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
738 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
739 "-S",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
740 "--sub-id",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
741 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
742 default=u"",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
743 help=_(u"subscription id"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
744 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
745 #  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
746 # TODO: add MAM filters
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
747
2274
27f469d40a83 jp (pubsub): psItemGet has been renamed to psItemsGet as several items are gotten
Goffi <goffi@goffi.org>
parents: 2239
diff changeset
748 def psItemsGetCb(self, ps_result):
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
749 self.output(ps_result[0])
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
750 self.host.quit(C.EXIT_OK)
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
751
2274
27f469d40a83 jp (pubsub): psItemGet has been renamed to psItemsGet as several items are gotten
Goffi <goffi@goffi.org>
parents: 2239
diff changeset
752 def psItemsGetEb(self, failure_):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
753 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
754 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
755
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
756 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
757 self.host.bridge.psItemsGet(
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
758 self.args.service,
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
759 self.args.node,
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
760 self.args.max,
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
761 self.args.items,
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
762 self.args.sub_id,
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
763 {},
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
764 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
765 callback=self.psItemsGetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
766 errback=self.psItemsGetEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
767 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
768
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
769
2281
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
770 class Delete(base.CommandBase):
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
771 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
772 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
773 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
774 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
775 "delete",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
776 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
777 pubsub_flags={C.NODE, C.SINGLE_ITEM},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
778 help=_(u"delete an item"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
779 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
780 self.need_loop = True
2281
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
781
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
782 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
783 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
784 "-f", "--force", action="store_true", help=_(u"delete without confirmation")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
785 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
786 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
787 "-N", "--notify", action="store_true", help=_(u"notify deletion")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
788 )
2281
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
789
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
790 def psItemsDeleteCb(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
791 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
792 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
793
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
794 def start(self):
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
795 if not self.args.item:
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
796 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
797 if not self.args.force:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
798 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
799 item_id=self.args.item
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
800 )
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
801 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
802 self.host.bridge.psRetractItem(
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
803 self.args.service,
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
804 self.args.node,
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
805 self.args.item,
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
806 self.args.notify,
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
807 self.profile,
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
808 callback=self.psItemsDeleteCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
809 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
810 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
811 msg=_(u"can't delete item: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
812 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
813 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
814 )
2281
4af1805cc6df jp (pubsub/delete): delete command implementation (to delete an item)
Goffi <goffi@goffi.org>
parents: 2280
diff changeset
815
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
816
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
817 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
818 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
819 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
820 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
821 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
822 "edit",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
823 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
824 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
825 pubsub_flags={C.NODE, C.SINGLE_ITEM},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
826 use_draft=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
827 help=_(u"edit an existing or new pubsub item"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
828 )
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
829 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
830
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 def add_parser_options(self):
2532
772447ec070f jp: pubsub options refactoring:
Goffi <goffi@goffi.org>
parents: 2483
diff changeset
832 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
833
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 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
835 # 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
836 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
837
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 def publish(self, content):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
839 published_id = self.host.bridge.psItemSend(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
840 self.pubsub_service,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
841 self.pubsub_node,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
842 content,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
843 self.pubsub_item or "",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
844 {},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
845 self.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
846 )
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
847 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
848 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
849 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
850 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
851
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 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
853 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
854 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
855 except ImportError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
856 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
857 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
858 error=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
859 )
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
860 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
861 items = [item] if item is not None else []
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
862 item_raw = self.host.bridge.psItemsGet(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
863 service, node, 1, items, "", {}, self.profile
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
864 )[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
865 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
866 item_elt = etree.fromstring(item_raw, parser)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
867 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
868 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
869 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
870 except IndexError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
871 self.disp(_(u"Item has not payload"), 1)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
872 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
873 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
874
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
875 def start(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
876 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
877 self.getItemPath()
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
878 )
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
879 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
880
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
881
2353
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
882 class Subscribe(base.CommandBase):
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
883 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
884 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
885 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
886 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
887 "subscribe",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
888 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
889 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
890 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
891 help=_(u"subscribe to a node"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
892 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
893 self.need_loop = True
2353
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
894
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
895 def add_parser_options(self):
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
896 pass
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
897
2442
b8ffb7f8056b plugin XEP-0060: added "options" argument to psSubscribe, and return subscription id if present
Goffi <goffi@goffi.org>
parents: 2439
diff changeset
898 def psSubscribeCb(self, sub_id):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
899 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
900 if sub_id:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
901 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
902 self.host.quit()
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
903
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
904 def start(self):
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
905 self.host.bridge.psSubscribe(
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
906 self.args.service,
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
907 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
908 {},
2353
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
909 self.profile,
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
910 callback=self.psSubscribeCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
911 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
912 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
913 msg=_(u"can't subscribe to node: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
914 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
915 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
916 )
2353
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
917
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
918
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
919 class Unsubscribe(base.CommandBase):
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
920 # 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
921
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
922 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
923 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
924 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
925 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
926 "unsubscribe",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
927 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
928 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
929 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
930 help=_(u"unsubscribe from a node"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
931 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
932 self.need_loop = True
2353
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
933
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
934 def add_parser_options(self):
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
935 pass
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 def psUnsubscribeCb(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
938 self.disp(_(u"subscription removed"), 1)
2353
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
939 self.host.quit()
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
940
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
941 def start(self):
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
942 self.host.bridge.psUnsubscribe(
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
943 self.args.service,
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
944 self.args.node,
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
945 self.profile,
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
946 callback=self.psUnsubscribeCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
947 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
948 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
949 msg=_(u"can't unsubscribe from node: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
950 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
951 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
952 )
2353
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
953
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
954
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
955 class Subscriptions(base.CommandBase):
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
956 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
957 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
958 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
959 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
960 "subscriptions",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
961 use_output=C.OUTPUT_LIST_DICT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
962 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
963 help=_(u"retrieve all subscriptions on a service"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
964 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
965 self.need_loop = True
2353
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
966
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
967 def add_parser_options(self):
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
968 pass
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 def psSubscriptionsGetCb(self, subscriptions):
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
971 self.output(subscriptions)
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
972 self.host.quit()
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
973
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
974 def start(self):
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
975 self.host.bridge.psSubscriptionsGet(
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
976 self.args.service,
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
977 self.args.node,
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
978 self.profile,
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
979 callback=self.psSubscriptionsGetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
980 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
981 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
982 msg=_(u"can't retrieve subscriptions: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
983 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
984 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
985 )
2353
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
986
ebc0dfe9c0ca jp (pubsub): added subscribe, unsubscribe and subscriptions methods:
Goffi <goffi@goffi.org>
parents: 2351
diff changeset
987
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
988 class Affiliations(base.CommandBase):
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
989 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
990 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
991 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
992 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
993 "affiliations",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
994 use_output=C.OUTPUT_DICT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
995 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
996 help=_(u"retrieve all affiliations on a service"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
997 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
998 self.need_loop = True
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
999
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1000 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
1001 pass
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1002
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1003 def psAffiliationsGetCb(self, affiliations):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1004 self.output(affiliations)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1005 self.host.quit()
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1006
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1007 def psAffiliationsGetEb(self, failure_):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1008 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1009 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
1010 )
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1011 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1012
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1013 def start(self):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1014 self.host.bridge.psAffiliationsGet(
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1015 self.args.service,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1016 self.args.node,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1017 self.profile,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1018 callback=self.psAffiliationsGetCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1019 errback=self.psAffiliationsGetEb,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1020 )
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1021
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
1022
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1023 class Search(base.CommandBase):
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1024 """this command to a search without using MAM, i.e. by checking every items if dound by itself, so it may be heavy in resources both for server and client"""
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1025
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1026 RE_FLAGS = re.MULTILINE | re.UNICODE
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1027 EXEC_ACTIONS = (u"exec", u"external")
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1028
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1029 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1030 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1031 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1032 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1033 "search",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1034 use_output=C.OUTPUT_XML,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1035 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1036 pubsub_flags={C.MULTI_ITEMS, C.NO_MAX},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1037 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1038 help=_(u"search items corresponding to filters"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1039 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1040 self.need_loop = True
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1041
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1042 @property
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1043 def etree(self):
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1044 """load lxml.etree only if needed"""
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1045 if self._etree is None:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1046 from lxml import etree
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1047
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1048 self._etree = etree
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1049 return self._etree
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1050
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1051 def filter_opt(self, value, type_):
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1052 value = base.unicode_decoder(value)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1053 return (type_, value)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1054
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1055 def filter_flag(self, value, type_):
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1056 value = C.bool(value)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1057 return (type_, value)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1058
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1059 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1060 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1061 "-D",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1062 "--max-depth",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1063 type=int,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1064 default=0,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1065 help=_(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1066 u"maximum depth of recursion (will search linked nodes if > 0, default: 0)"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1067 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1068 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1069 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1070 "-m",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1071 "--max",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1072 type=int,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1073 default=30,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1074 help=_(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1075 u"maximum number of items to get per node ({} to get all items, default: 30)".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1076 C.NO_LIMIT
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1077 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1078 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1079 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1080 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1081 "-N",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1082 "--namespace",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1083 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1084 nargs=2,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1085 default=[],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1086 metavar="NAME NAMESPACE",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1087 help=_(u"namespace to use for xpath"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1088 )
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1089
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1090 # filters
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1091 filter_text = partial(self.filter_opt, type_=u"text")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1092 filter_re = partial(self.filter_opt, type_=u"regex")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1093 filter_xpath = partial(self.filter_opt, type_=u"xpath")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1094 filter_python = partial(self.filter_opt, type_=u"python")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1095 filters = self.parser.add_argument_group(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1096 _(u"filters"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1097 _(u"only items corresponding to following filters will be kept"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1098 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1099 filters.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1100 "-t",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1101 "--text",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1102 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1103 dest="filters",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1104 type=filter_text,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1105 metavar="TEXT",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1106 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
1107 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1108 filters.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1109 "-r",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1110 "--regex",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1111 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1112 dest="filters",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1113 type=filter_re,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1114 metavar="EXPRESSION",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1115 help=_(u"like --text but using a regular expression"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1116 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1117 filters.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1118 "-x",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1119 "--xpath",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1120 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1121 dest="filters",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1122 type=filter_xpath,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1123 metavar="XPATH",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1124 help=_(u"filter items which has elements matching this xpath"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1125 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1126 filters.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1127 "-P",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1128 "--python",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1129 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1130 dest="filters",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1131 type=filter_python,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1132 metavar="PYTHON_CODE",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1133 help=_(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1134 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
1135 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1136 )
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1137
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1138 # filters flags
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1139 flag_case = partial(self.filter_flag, type_=u"ignore-case")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1140 flag_invert = partial(self.filter_flag, type_=u"invert")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1141 flag_dotall = partial(self.filter_flag, type_=u"dotall")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1142 flag_matching = partial(self.filter_flag, type_=u"only-matching")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1143 flags = self.parser.add_argument_group(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1144 _(u"filters flags"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1145 _(u"filters modifiers (change behaviour of following filters)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1146 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1147 flags.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1148 "-C",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1149 "--ignore-case",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1150 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1151 dest="filters",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1152 type=flag_case,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1153 const=("ignore-case", True),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1154 nargs="?",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1155 metavar="BOOLEAN",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1156 help=_(u"(don't) ignore case in following filters (default: case sensitive)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1157 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1158 flags.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1159 "-I",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1160 "--invert",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1161 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1162 dest="filters",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1163 type=flag_invert,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1164 const=("invert", True),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1165 nargs="?",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1166 metavar="BOOLEAN",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1167 help=_(u"(don't) invert effect of following filters (default: don't invert)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1168 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1169 flags.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1170 "-A",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1171 "--dot-all",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1172 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1173 dest="filters",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1174 type=flag_dotall,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1175 const=("dotall", True),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1176 nargs="?",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1177 metavar="BOOLEAN",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1178 help=_(u"(don't) use DOTALL option for regex (default: don't use)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1179 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1180 flags.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1181 "-o",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1182 "--only-matching",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1183 action="append",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1184 dest="filters",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1185 type=flag_matching,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1186 const=("only-matching", True),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1187 nargs="?",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1188 metavar="BOOLEAN",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1189 help=_(u"keep only the matching part of the item"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1190 )
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1191
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1192 # action
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1193 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1194 "action",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1195 default="print",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1196 nargs="?",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1197 choices=("print", "exec", "external"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1198 help=_(u"action to do on found items (default: print)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1199 )
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1200 self.parser.add_argument("command", nargs=argparse.REMAINDER)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1201
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1202 def psItemsGetEb(self, failure_, service, node):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1203 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1204 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
1205 service=service, node=node, reason=failure_
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1206 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1207 error=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1208 )
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1209 self.to_get -= 1
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1210
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1211 def getItems(self, depth, service, node, items):
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1212 search = partial(self.search, depth=depth)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1213 errback = partial(self.psItemsGetEb, service=service, node=node)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1214 self.host.bridge.psItemsGet(
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1215 service,
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1216 node,
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1217 self.args.max,
2456
83f9b9ff1a54 jp (pubsub/search): fixed --item argument
Goffi <goffi@goffi.org>
parents: 2442
diff changeset
1218 items,
2316
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 {},
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1221 self.profile,
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1222 callback=search,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1223 errback=errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1224 )
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1225 self.to_get += 1
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1226
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1227 def _checkPubsubURL(self, match, found_nodes):
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1228 """check that the matched URL is an xmpp: one
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1229
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1230 @param found_nodes(list[unicode]): found_nodes
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1231 this list will be filled while xmpp: URIs are discovered
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1232 """
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1233 url = match.group(0)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1234 if url.startswith(u"xmpp"):
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1235 try:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1236 url_data = uri.parseXMPPUri(url)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1237 except ValueError:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1238 return
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1239 if url_data[u"type"] == u"pubsub":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1240 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
1241 if u"item" in url_data:
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1242 found_node[u"item"] = url_data[u"item"]
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1243 found_nodes.append(found_node)
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 getSubNodes(self, item, depth):
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1246 """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
1247 found_nodes = []
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1248 checkURI = partial(self._checkPubsubURL, found_nodes=found_nodes)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1249 strings.RE_URL.sub(checkURI, item)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1250 for data in found_nodes:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1251 self.getItems(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1252 depth + 1,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1253 data[u"service"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1254 data[u"node"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1255 [data[u"item"]] if u"item" in data else [],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1256 )
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1257
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1258 def parseXml(self, item):
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1259 try:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1260 return self.etree.fromstring(item)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1261 except self.etree.XMLSyntaxError:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1262 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1263 _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1264 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
1265 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1266 error=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1267 )
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1268 self.host.quit(C.EXIT_BAD_ARG)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1269
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1270 def filter(self, item):
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1271 """apply filters given on command line
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 if only-matching is used, item may be modified
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1274 @return (tuple[bool, unicode]): a tuple with:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1275 - keep: True if item passed the filters
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1276 - item: it is returned in case of modifications
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1277 """
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1278 ignore_case = False
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1279 invert = False
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1280 dotall = False
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1281 only_matching = False
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1282 item_xml = None
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1283 for type_, value in self.args.filters:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1284 keep = True
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1285
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1286 ## filters
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1287
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1288 if type_ == u"text":
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1289 if ignore_case:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1290 if value.lower() not in item.lower():
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1291 keep = False
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1292 else:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1293 if value not in item:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1294 keep = False
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1295 if keep and only_matching:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1296 # doesn't really make sens to keep a fixed string
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1297 # so we raise an error
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1298 self.host.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1299 _(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1300 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
1301 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1302 error=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1303 )
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1304 self.host.quit(C.EXIT_BAD_ARG)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1305 elif type_ == u"regex":
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1306 flags = self.RE_FLAGS
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1307 if ignore_case:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1308 flags |= re.IGNORECASE
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1309 if dotall:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1310 flags |= re.DOTALL
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1311 match = re.search(value, item, flags)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1312 keep = match != None
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1313 if keep and only_matching:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1314 item = match.group()
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1315 item_xml = None
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1316 elif type_ == u"xpath":
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1317 if item_xml is None:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1318 item_xml = self.parseXml(item)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1319 try:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1320 elts = item_xml.xpath(value, namespaces=self.args.namespace)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1321 except self.etree.XPathEvalError as e:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1322 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1323 _(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
1324 )
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1325 self.host.quit(C.EXIT_BAD_ARG)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1326 keep = bool(elts)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1327 if keep and only_matching:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1328 item_xml = elts[0]
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1329 try:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1330 item = self.etree.tostring(item_xml, encoding="unicode")
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1331 except TypeError:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1332 # we have a string only, not an element
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1333 item = unicode(item_xml)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1334 item_xml = None
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1335 elif type_ == u"python":
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1336 if item_xml is None:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1337 item_xml = self.parseXml(item)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1338 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
1339 try:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1340 keep = eval(value, cmd_ns)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1341 except SyntaxError as e:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1342 self.disp(unicode(e), error=True)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1343 self.host.quit(C.EXIT_BAD_ARG)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1344
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1345 ## flags
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1346
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1347 elif type_ == u"ignore-case":
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1348 ignore_case = value
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1349 elif type_ == u"invert":
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1350 invert = value
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1351 #  we need to continue, else loop would end here
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1352 continue
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1353 elif type_ == u"dotall":
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1354 dotall = value
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1355 elif type_ == u"only-matching":
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1356 only_matching = value
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1357 else:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1358 raise exceptions.InternalError(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1359 _(u"unknown filter type {type}").format(type=type_)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1360 )
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1361
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1362 if invert:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1363 keep = not keep
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1364 if not keep:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1365 return False, item
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1366
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1367 return True, item
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1368
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1369 def doItemAction(self, item, metadata):
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1370 """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
1371
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1372 @param item(unicode): accepted item
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1373 """
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1374 action = self.args.action
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1375 if action == u"print" or self.host.verbosity > 0:
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1376 try:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1377 self.output(item)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1378 except self.etree.XMLSyntaxError:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1379 # item is not valid XML, but a string
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1380 # can happen when --only-matching is used
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1381 self.disp(item)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1382 if action in self.EXEC_ACTIONS:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1383 item_elt = self.parseXml(item)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1384 if action == u"exec":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1385 use = {
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1386 "service": metadata[u"service"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1387 "node": metadata[u"node"],
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1388 "item": item_elt.get("id"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1389 "profile": self.profile,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1390 }
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
1391 # 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
1392 # else it would be modified
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1393 parser_args, use_args = arg_tools.get_use_args(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1394 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
1395 )
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
1396 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
1397 else:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1398 cmd_args = self.args.command
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1399
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 u"COMMAND: {command}".format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1402 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
1403 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1404 2,
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 if action == u"exec":
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1407 ret = subprocess.call(cmd_args)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1408 else:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1409 p = subprocess.Popen(cmd_args, stdin=subprocess.PIPE)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1410 p.communicate(item.encode("utf-8"))
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1411 ret = p.wait()
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1412 if ret != 0:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1413 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1414 A.color(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1415 C.A_FAILURE,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1416 _(u"executed command failed with exit code {code}").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1417 code=ret
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1418 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1419 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1420 )
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1421
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1422 def search(self, items_data, depth):
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1423 """callback of getItems
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1424
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1425 this method filters items, get sub nodes if needed,
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1426 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
1427 @param items_data(tuple): result of getItems
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1428 @param depth(int): current depth level
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1429 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
1430 """
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1431 items, metadata = items_data
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1432 for item in items:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1433 if depth < self.args.max_depth:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1434 self.getSubNodes(item, depth)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1435 keep, item = self.filter(item)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1436 if not keep:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1437 continue
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1438 self.doItemAction(item, metadata)
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1439
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1440 #  we check if we got all getItems results
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1441 self.to_get -= 1
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1442 if self.to_get == 0:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1443 # yes, we can quit
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1444 self.host.quit()
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1445 assert self.to_get > 0
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1446
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1447 def start(self):
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1448 if self.args.command:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1449 if self.args.action not in self.EXEC_ACTIONS:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1450 self.parser.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1451 _(u"Command can only be used with {actions} actions").format(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1452 actions=u", ".join(self.EXEC_ACTIONS)
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1453 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1454 )
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1455 else:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1456 if self.args.action in self.EXEC_ACTIONS:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1457 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
1458 if not self.args.node:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1459 # TODO: handle get service affiliations when node is not set
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1460 self.parser.error(_(u"empty node is not handled yet"))
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1461 # 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
1462 # when it reach 0 again, the command is finished
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1463 self.to_get = 0
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1464 self._etree = None
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1465 if self.args.filters is None:
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1466 self.args.filters = []
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1467 self.args.namespace = dict(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1468 self.args.namespace + [("pubsub", "http://jabber.org/protocol/pubsub")]
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1469 )
2316
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1470 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
1471
7b448ac50a69 jp (pubsub): new search command:
Goffi <goffi@goffi.org>
parents: 2308
diff changeset
1472
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
1473 class Uri(base.CommandBase):
2224
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1474 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1475 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1476 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1477 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1478 "uri",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1479 use_profile=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1480 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1481 pubsub_flags={C.NODE, C.SINGLE_ITEM},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1482 help=_(u"build URI"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1483 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1484 self.need_loop = True
2224
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1485
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1486 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1487 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1488 "-p",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1489 "--profile",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1490 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1491 default=C.PROF_KEY_DEFAULT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1492 help=_(u"profile (used when no server is specified)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1493 )
2224
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1494
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1495 def display_uri(self, jid_):
2239
17502e74c046 jp (pubsub/uri): fixed URI generation
Goffi <goffi@goffi.org>
parents: 2235
diff changeset
1496 uri_args = {}
2224
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1497 if not self.args.service:
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1498 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
1499
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1500 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
1501 value = getattr(self.args, key)
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1502 if key == "service":
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1503 key = "path"
2224
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1504 if value:
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1505 uri_args[key] = value
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1506 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
1507 self.host.quit()
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1508
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1509 def start(self):
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1510 if not self.args.service:
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1511 self.host.bridge.asyncGetParamA(
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1512 u"JabberID",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1513 u"Connection",
2224
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1514 profile_key=self.args.profile,
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1515 callback=self.display_uri,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1516 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1517 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1518 msg=_(u"can't retrieve jid: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1519 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1520 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1521 )
2224
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1522 else:
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1523 self.display_uri(None)
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1524
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
1525
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
1526 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
1527 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1528 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1529 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1530 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1531 "create",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1532 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1533 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1534 help=_(u"create a Pubsub hook"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1535 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1536 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
1537
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1538 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1539 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1540 "-t",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1541 "--type",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1542 default=u"python",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1543 choices=("python", "python_file", "python_code"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1544 help=_(u"hook type"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1545 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1546 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1547 "-P",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1548 "--persistent",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1549 action="store_true",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1550 help=_(u"make hook persistent across restarts"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1551 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1552 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1553 "hook_arg",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1554 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1555 help=_(u"argument of the hook (depend of the type)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1556 )
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
1557
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1558 @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
1559 def checkArgs(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1560 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
1561 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
1562 if not os.path.isfile(self.args.hook_arg):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1563 self.parser.error(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1564 _(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
1565 )
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
1566
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1567 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
1568 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
1569 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
1570 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
1571 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
1572 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
1573 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
1574 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
1575 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
1576 callback=self.host.quit,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1577 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1578 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1579 msg=_(u"can't create hook: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1580 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1581 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1582 )
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
1583
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1584
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1585 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
1586 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1587 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1588 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1589 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1590 "delete",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1591 use_pubsub=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1592 pubsub_flags={C.NODE},
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1593 help=_(u"delete a Pubsub hook"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1594 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1595 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
1596
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1597 def add_parser_options(self):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1598 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1599 "-t",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1600 "--type",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1601 default=u"",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1602 choices=("", "python", "python_file", "python_code"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1603 help=_(u"hook type to remove, empty to remove all (default: remove all)"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1604 )
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1605 self.parser.add_argument(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1606 "-a",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1607 "--arg",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1608 dest="hook_arg",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1609 type=base.unicode_decoder,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1610 default=u"",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1611 help=_(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1612 u"argument of the hook to remove, empty to remove all (default: remove all)"
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1613 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1614 )
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
1615
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1616 def psHookRemoveCb(self, nb_deleted):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1617 self.disp(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1618 _(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
1619 )
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
1620 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
1621
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1622 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
1623 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
1624 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
1625 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
1626 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
1627 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
1628 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
1629 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
1630 callback=self.psHookRemoveCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1631 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1632 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1633 msg=_(u"can't delete hook: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1634 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1635 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1636 )
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
1637
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1638
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1639 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
1640 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1641 base.CommandBase.__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1642 self,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1643 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1644 "list",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1645 use_output=C.OUTPUT_LIST_DICT,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1646 help=_(u"list hooks of a profile"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1647 )
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
1648 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
1649
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1650 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
1651 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
1652
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1653 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
1654 if not data:
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1655 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
1656 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
1657 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
1658
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1659 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
1660 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
1661 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
1662 callback=self.psHookListCb,
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1663 errback=partial(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1664 self.errback,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1665 msg=_(u"can't list hooks: {}"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1666 exit_code=C.EXIT_BRIDGE_ERRBACK,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1667 ),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1668 )
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
1669
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1670
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1671 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
1672 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
1673
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1674 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1675 super(Hook, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1676 host,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1677 "hook",
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1678 use_profile=False,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1679 use_verbose=True,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1680 help=_("trigger action on Pubsub notifications"),
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1681 )
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
1682
0b21d87c91cf jp (pubsub/hook): added create/delete/list hook command to handle new Pubsub hook feature
Goffi <goffi@goffi.org>
parents: 2292
diff changeset
1683
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1684 class Pubsub(base.CommandBase):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1685 subcommands = (
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1686 Set,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1687 Get,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1688 Delete,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1689 Edit,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1690 Subscribe,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1691 Unsubscribe,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1692 Subscriptions,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1693 Node,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1694 Affiliations,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1695 Search,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1696 Hook,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1697 Uri,
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1698 )
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1699
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
1700 def __init__(self, host):
2624
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1701 super(Pubsub, self).__init__(
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1702 host, "pubsub", use_profile=False, help=_("PubSub nodes/items management")
56f94936df1e code style reformatting using black
Goffi <goffi@goffi.org>
parents: 2562
diff changeset
1703 )