annotate sat_frontends/jp/cmd_pubsub.py @ 2803:d4a9a60bc650

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