annotate frontends/src/jp/cmd_pubsub.py @ 2275:64e99bf0dfa2

jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
author Goffi <goffi@goffi.org>
date Tue, 27 Jun 2017 19:38:22 +0200
parents 27f469d40a83
children 5cd45a79775b
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
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
5 # Copyright (C) 2009-2016 Jérôme Poisson (goffi@goffi.org)
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 _
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
23 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
24 from sat_frontends.jp import common
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
25 from functools import partial
2224
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
26 from sat.tools.common import uri
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
27 from sat_frontends.tools import jid
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
28
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
29 __commands__ = ["Pubsub"]
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
30
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
31 PUBSUB_TMP_DIR = u"pubsub"
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
32
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
33
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
34 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
35
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
36 def __init__(self, host):
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
37 base.CommandBase.__init__(self, host, 'info', use_output=C.OUTPUT_DICT, use_pubsub_node_req=True, help=_(u'retrieve node configuration'))
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
38 self.need_loop=True
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
39
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
40 def add_parser_options(self):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
41 self.parser.add_argument("-k", "--key", type=base.unicode_decoder, action='append', dest='keys',
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
42 help=_(u"data key to filter"))
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
43
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
44 def removePrefix(self, key):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
45 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
46
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
47 def filterKey(self, key):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
48 return any((key == k or key == u'pubsub#' + k) for k in self.args.keys)
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
49
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
50 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
51 key_filter = (lambda k: True) if not self.args.keys else self.filterKey
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
52 config_dict = {self.removePrefix(k):v for k,v in config_dict.iteritems() if key_filter(k)}
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
53 self.output(config_dict)
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
54 self.host.quit()
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
55
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
56 def psNodeConfigurationGetEb(self, failure_):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
57 self.disp(u"can't get node configuration: {reason}".format(
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
58 reason=failure_), error=True)
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
59 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
60
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
61 def start(self):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
62 self.host.bridge.psNodeConfigurationGet(
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
63 self.args.service,
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
64 self.args.node,
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
65 self.profile,
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
66 callback=self.psNodeConfigurationGetCb,
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
67 errback=self.psNodeConfigurationGetEb)
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
68
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
69
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
70 class NodeCreate(base.CommandBase):
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
71
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
72 def __init__(self, host):
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
73 base.CommandBase.__init__(self, host, 'create', use_output=C.OUTPUT_DICT, use_pubsub_node_req=True, use_verbose=True, help=_(u'create a node'))
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
74 self.need_loop=True
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
75
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
76 def add_parser_options(self):
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
77 self.parser.add_argument("-f", "--field", type=base.unicode_decoder, action='append', nargs=2, dest='fields',
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
78 default={}, metavar=(u"KEY", u"VALUE"), help=_(u"configuration field to set"))
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
79 self.parser.add_argument("-F", "--full-prefix", action="store_true", help=_(u"don't prepend \"pubsub#\" prefix to field names"))
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
80
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
81 def psNodeCreateCb(self, node_id):
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
82 if self.host.verbosity:
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
83 announce = _(u'node created successfully: ')
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
84 else:
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
85 announce = u''
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
86 self.disp(announce + node_id)
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
87 self.host.quit()
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
88
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
89 def psNodeCreateEb(self, failure_):
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
90 self.disp(u"can't create: {reason}".format(
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
91 reason=failure_), error=True)
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
92 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
93
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
94 def start(self):
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
95 if not self.args.full_prefix:
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
96 options = {u'pubsub#' + k: v for k,v in self.args.fields}
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
97 else:
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
98 options = dict(self.args.fields)
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
99 self.host.bridge.psNodeCreate(
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
100 self.args.service,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
101 self.args.node,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
102 options,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
103 self.profile,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
104 callback=self.psNodeCreateCb,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
105 errback=partial(self.errback,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
106 msg=_(u"can't create node: {}"),
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
107 exit_code=C.EXIT_BRIDGE_ERRBACK))
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
108
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
109
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
110 class NodeDelete(base.CommandBase):
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
111
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
112 def __init__(self, host):
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
113 base.CommandBase.__init__(self, host, 'delete', use_pubsub_node_req=True, help=_(u'delete a node'))
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
114 self.need_loop=True
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
115
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
116 def add_parser_options(self):
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
117 self.parser.add_argument('-f', '--force', action='store_true', help=_(u'delete node without confirmation'))
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
118
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
119 def psNodeDeleteCb(self):
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
120 self.disp(_(u'node deleted successfully'))
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
121 self.host.quit()
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
122
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
123 def start(self):
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
124 if not self.args.force:
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
125 if not self.args.service:
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
126 message = _(u"Are you sure to delete pep node [{node_id}] ?").format(
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
127 node_id=self.args.node)
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
128 else:
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
129 message = _(u"Are you sure to delete node [{node_id}] on service [{service}] ?").format(
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
130 node_id=self.args.node, service=self.args.service)
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
131
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
132 res = raw_input("{} (y/N)? ".format(message))
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
133 if res not in ("y", "Y"):
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
134 self.disp(_(u"node deletion cancelled"))
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
135 self.host.quit(2)
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
136
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
137 self.host.bridge.psNodeDelete(
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
138 self.args.service,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
139 self.args.node,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
140 self.profile,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
141 callback=self.psNodeDeleteCb,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
142 errback=partial(self.errback,
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
143 msg=_(u"can't delete node: {}"),
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
144 exit_code=C.EXIT_BRIDGE_ERRBACK))
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
145
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
146
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
147 class NodeSet(base.CommandBase):
2199
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
148
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
149 def __init__(self, host):
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
150 base.CommandBase.__init__(self, host, 'set', use_output=C.OUTPUT_DICT, use_pubsub_node_req=True, use_verbose=True, help=_(u'set node configuration'))
2199
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
151 self.need_loop=True
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
152
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
153 def add_parser_options(self):
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
154 self.parser.add_argument("-f", "--field", type=base.unicode_decoder, action='append', nargs=2, dest='fields',
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
155 required=True, metavar=(u"KEY", u"VALUE"), help=_(u"configuration field to set (required)"))
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
156
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
157 def psNodeConfigurationSetCb(self):
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
158 self.disp(_(u'node configuration successful'), 1)
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
159 self.host.quit()
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
160
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
161 def psNodeConfigurationSetEb(self, failure_):
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
162 self.disp(u"can't set node configuration: {reason}".format(
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
163 reason=failure_), error=True)
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
164 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
165
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
166 def getKeyName(self, k):
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
167 if not k.startswith(u'pubsub#'):
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
168 return u'pubsub#' + k
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
169 else:
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
170 return k
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
171
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
172 def start(self):
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
173 self.host.bridge.psNodeConfigurationSet(
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
174 self.args.service,
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
175 self.args.node,
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
176 {self.getKeyName(k): v for k,v in self.args.fields},
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
177 self.profile,
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
178 callback=self.psNodeConfigurationSetCb,
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
179 errback=self.psNodeConfigurationSetEb)
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
180
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
181
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
182 class NodeAffiliationsGet(base.CommandBase):
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
183
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
184 def __init__(self, host):
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
185 base.CommandBase.__init__(self, host, 'get', use_output=C.OUTPUT_DICT, use_pubsub_node_req=True, help=_(u'retrieve node affiliations (for node owner)'))
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
186 self.need_loop=True
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
187
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
188 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
189 pass
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
190
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
191 def psNodeAffiliationsGetCb(self, affiliations):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
192 self.output(affiliations)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
193 self.host.quit()
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
194
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
195 def psNodeAffiliationsGetEb(self, failure_):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
196 self.disp(u"can't get node affiliations: {reason}".format(
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
197 reason=failure_), error=True)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
198 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
199
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
200 def start(self):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
201 self.host.bridge.psNodeAffiliationsGet(
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
202 self.args.service,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
203 self.args.node,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
204 self.profile,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
205 callback=self.psNodeAffiliationsGetCb,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
206 errback=self.psNodeAffiliationsGetEb)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
207
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
208
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
209 class NodeAffiliationsSet(base.CommandBase):
2207
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
210
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
211 def __init__(self, host):
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
212 base.CommandBase.__init__(self, host, 'set', use_pubsub_node_req=True, use_verbose=True, help=_(u'set affiliations (for node owner)'))
2207
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
213 self.need_loop=True
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
214
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
215 def add_parser_options(self):
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
216 # 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
217 # (uses to construct dicts) don't work with positional arguments
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
218 self.parser.add_argument("-a",
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
219 "--affiliation",
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
220 dest="affiliations",
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
221 metavar=('JID', 'AFFILIATION'),
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
222 required=True,
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
223 type=base.unicode_decoder,
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
224 action="append",
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
225 nargs=2,
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
226 help=_(u"entity/affiliation couple(s)"))
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
227
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
228 def psNodeAffiliationsSetCb(self):
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
229 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
230 self.host.quit()
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
231
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
232 def psNodeAffiliationsSetEb(self, failure_):
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
233 self.disp(u"can't set node affiliations: {reason}".format(
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
234 reason=failure_), error=True)
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
235 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
236
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
237 def start(self):
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
238 affiliations = dict(self.args.affiliations)
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
239 self.host.bridge.psNodeAffiliationsSet(
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
240 self.args.service,
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
241 self.args.node,
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
242 affiliations,
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
243 self.profile,
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
244 callback=self.psNodeAffiliationsSetCb,
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
245 errback=self.psNodeAffiliationsSetEb)
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
246
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
247
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
248 class NodeAffiliations(base.CommandBase):
2207
d662bdd682b2 jp (pubsub/node) added pubsub/node/affiliations/set command
Goffi <goffi@goffi.org>
parents: 2204
diff changeset
249 subcommands = (NodeAffiliationsGet, NodeAffiliationsSet)
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
250
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
251 def __init__(self, host):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
252 super(NodeAffiliations, self).__init__(host, 'affiliations', use_profile=False, help=_(u'set or retrieve node affiliations'))
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
253
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
254
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
255 class Node(base.CommandBase):
2221
a6c9bc4d1de0 jp (pubsub/node): added create and delete commands
Goffi <goffi@goffi.org>
parents: 2214
diff changeset
256 subcommands = (NodeInfo, NodeCreate, NodeDelete, NodeSet, NodeAffiliations)
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
257
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
258 def __init__(self, host):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
259 super(Node, self).__init__(host, 'node', use_profile=False, help=_('node handling'))
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
260
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
261
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
262 class Get(base.CommandBase):
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
263
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
264 def __init__(self, host):
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
265 base.CommandBase.__init__(self, host, 'get', use_output=C.OUTPUT_LIST_XML, use_pubsub_node_req=True, help=_(u'get pubsub item(s)'))
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
266 self.need_loop=True
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
267
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
268 def add_parser_options(self):
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
269 self.parser.add_argument("-i", "--item", type=base.unicode_decoder, action='append', default=[], dest='items',
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
270 help=_(u"item(s) id(s) to get (default: request all items)"))
2214
4e06cd44e667 jp (pubsub/get): --service is now optional argument, and sub_id now use "-S" short option
Goffi <goffi@goffi.org>
parents: 2207
diff changeset
271 self.parser.add_argument("-S", "--sub-id", type=base.unicode_decoder, default=u'',
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
272 help=_(u"subscription id"))
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
273 self.parser.add_argument("-m", "--max", type=int, default=10, help=_(u"maximum number of items to get ({} to get all items)".format(C.NO_LIMIT)))
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
274 # TODO: a key(s) argument to select keys to display
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
275 # TODO: add MAM filters
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
276
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
277
2274
27f469d40a83 jp (pubsub): psItemGet has been renamed to psItemsGet as several items are gotten
Goffi <goffi@goffi.org>
parents: 2239
diff changeset
278 def psItemsGetCb(self, ps_result):
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
279 self.output(ps_result[0])
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
280 self.host.quit(C.EXIT_OK)
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
281
2274
27f469d40a83 jp (pubsub): psItemGet has been renamed to psItemsGet as several items are gotten
Goffi <goffi@goffi.org>
parents: 2239
diff changeset
282 def psItemsGetEb(self, failure_):
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
283 self.disp(u"can't get pubsub items: {reason}".format(
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
284 reason=failure_), error=True)
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
285 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
286
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
287 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
288 self.host.bridge.psItemsGet(
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
289 self.args.service,
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
290 self.args.node,
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
291 self.args.max,
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
292 self.args.items,
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
293 self.args.sub_id,
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
294 {},
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
295 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
296 callback=self.psItemsGetCb,
27f469d40a83 jp (pubsub): psItemGet has been renamed to psItemsGet as several items are gotten
Goffi <goffi@goffi.org>
parents: 2239
diff changeset
297 errback=self.psItemsGetEb)
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
298
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
299
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
300 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
301
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
302 def __init__(self, host):
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
303 base.CommandBase.__init__(self, host, 'edit', use_verbose=True, use_pubsub_node_req=True, help=_(u'edit an existing or new pubsub 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
304 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
305
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
306 def add_parser_options(self):
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
307 self.parser.add_argument("item", type=base.unicode_decoder, nargs='?', default=u'new', help=_(u"URL of the item to edit, or keyword"))
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
308 common.BaseEdit.add_parser_options(self)
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
309
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
310 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
311 # 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
312 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
313
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
314 def publish(self, content):
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
315 published_id = self.host.bridge.psItemSend(self.pubsub_service, self.pubsub_node, content, self.pubsub_item or '', {}, self.profile)
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
316 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
317 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
318 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
319 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
320
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
321 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
322 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
323 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
324 except ImportError:
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
325 self.disp(u"lxml module must be installed to use edit, please install it with \"pip install lxml\"", error=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
326 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
327 items = [item] if item is not None 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
328 item_raw = self.host.bridge.psItemsGet(service, node, 1, items, "", {}, self.profile)[0][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
329 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
330 item_elt = etree.fromstring(item_raw, parser)
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
331 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
332 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
333 except IndexError:
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
334 self.disp(_(u'Item has not payload'), 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
335 return u''
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
336 return etree.tostring(payload, encoding="unicode", pretty_print=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
337
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
338 def start(self):
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
339 self.pubsub_service, self.pubsub_node, self.pubsub_item, content_file_path, content_file_obj = self.getItemPath(self.args.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
340
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
341 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
342
64e99bf0dfa2 jp (pubsub/edit): new edit subcommand, which work in a same way as for blog
Goffi <goffi@goffi.org>
parents: 2274
diff changeset
343
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
344 class Affiliations(base.CommandBase):
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
345
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
346 def __init__(self, host):
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
347 base.CommandBase.__init__(self, host, 'affiliations', use_output=C.OUTPUT_DICT, use_pubsub=True, help=_(u'retrieve all affiliations on a service'))
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
348 self.need_loop=True
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
349
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
350 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
351 pass
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 def psAffiliationsGetCb(self, affiliations):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
354 self.output(affiliations)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
355 self.host.quit()
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
356
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
357 def psAffiliationsGetEb(self, failure_):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
358 self.disp(u"can't get node affiliations: {reason}".format(
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
359 reason=failure_), error=True)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
360 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
361
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
362 def start(self):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
363 self.host.bridge.psAffiliationsGet(
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
364 self.args.service,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
365 self.args.node,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
366 self.profile,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
367 callback=self.psAffiliationsGetCb,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
368 errback=self.psAffiliationsGetEb)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
369
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
370
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
371 class Uri(base.CommandBase):
2224
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
372
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
373 def __init__(self, host):
2235
4db836386641 jp: added use_pubsub and use_pubsub_node_req arguments to CommandBase
Goffi <goffi@goffi.org>
parents: 2224
diff changeset
374 base.CommandBase.__init__(self, host, 'uri', use_profile=False, use_pubsub_node_req=True, help=_(u'build URI'))
2224
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
375 self.need_loop=True
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
376
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
377 def add_parser_options(self):
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
378 self.parser.add_argument("-i", "--item", type=base.unicode_decoder, help=_(u"item to link"))
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
379 self.parser.add_argument("-p", "--profile", type=base.unicode_decoder, default=C.PROF_KEY_DEFAULT, help=_(u"profile (used when no server is specified)"))
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
380
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
381 def display_uri(self, jid_):
2239
17502e74c046 jp (pubsub/uri): fixed URI generation
Goffi <goffi@goffi.org>
parents: 2235
diff changeset
382 uri_args = {}
2224
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
383 if not self.args.service:
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
384 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
385
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
386 for key in ('node', 'service', 'item'):
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
387 value = getattr(self.args, key)
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
388 if key == 'service':
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
389 key = 'path'
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
390 if value:
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
391 uri_args[key] = value
2239
17502e74c046 jp (pubsub/uri): fixed URI generation
Goffi <goffi@goffi.org>
parents: 2235
diff changeset
392 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
393 self.host.quit()
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
394
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
395 def start(self):
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
396 if not self.args.service:
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
397 self.host.bridge.asyncGetParamA(
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
398 u'JabberID',
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
399 u'Connection',
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
400 profile_key=self.args.profile,
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
401 callback=self.display_uri,
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
402 errback=partial(self.errback,
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
403 msg=_(u"can't retrieve jid: {}"),
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
404 exit_code=C.EXIT_BRIDGE_ERRBACK))
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
405 else:
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
406 self.display_uri(None)
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
407
87fcd4a7c7e4 jp (pubsub): added uri command to build pubsub URI
Goffi <goffi@goffi.org>
parents: 2221
diff changeset
408
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
409 class Pubsub(base.CommandBase):
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
410 subcommands = (Get, Edit, Node, Affiliations, Uri)
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
411
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
412 def __init__(self, host):
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
413 super(Pubsub, self).__init__(host, 'pubsub', use_profile=False, help=_('PubSub nodes/items management'))