annotate frontends/src/jp/cmd_pubsub.py @ 2204:afc703419186

jp (pubsub): added affiliations and node/affiliations/get: affiliations allow to retrieve all node were a profile is affiliated on a service, or the affiliation on a specific node. node/affiliations/get is for node owner and allow to retrieve who is affiliated with a node and which kind of affiliation.
author Goffi <goffi@goffi.org>
date Thu, 23 Mar 2017 21:04:01 +0100
parents ea0d0a4e2ad8
children d662bdd682b2
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
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
24
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
25 __commands__ = ["Pubsub"]
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
26
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
27
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
28 class NodeInfo(base.CommandBase):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
29
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
30 def __init__(self, host):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
31 base.CommandBase.__init__(self, host, 'info', use_output=C.OUTPUT_DICT, help=_(u'retrieve node configuration'))
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
32 self.need_loop=True
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
33
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
34 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
35 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
36 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
37 self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to request"))
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
38 self.parser.add_argument("service", type=base.unicode_decoder, nargs='?', default=u'',
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
39 help=_(u"JID of the PubSub service (default: request profile own pubsub)"))
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
40
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
41 def removePrefix(self, key):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
42 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
43
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
44 def filterKey(self, key):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
45 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
46
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
47 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
48 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
49 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
50 self.output(config_dict)
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
51 self.host.quit()
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
52
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
53 def psNodeConfigurationGetEb(self, failure_):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
54 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
55 reason=failure_), error=True)
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
56 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
57
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
58 def start(self):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
59 self.host.bridge.psNodeConfigurationGet(
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
60 self.args.service,
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
61 self.args.node,
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
62 self.profile,
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
63 callback=self.psNodeConfigurationGetCb,
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
64 errback=self.psNodeConfigurationGetEb)
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
65
2199
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
66 class NodeSet(base.CommandBase):
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
67
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
68 def __init__(self, host):
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
69 base.CommandBase.__init__(self, host, 'set', use_output=C.OUTPUT_DICT, use_verbose=True, help=_(u'set node configuration'))
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
70 self.need_loop=True
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
71
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
72 def add_parser_options(self):
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
73 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
74 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
75 self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to request"))
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
76 self.parser.add_argument("service", type=base.unicode_decoder, nargs='?', default=u'',
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
77 help=_(u"JID of the PubSub service (default: request profile own pubsub)"))
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
78
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
79 def psNodeConfigurationSetCb(self):
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
80 self.disp(_(u'node configuration successful'), 1)
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
81 self.host.quit()
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
82
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
83 def psNodeConfigurationSetEb(self, failure_):
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
84 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
85 reason=failure_), error=True)
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
86 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
87
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
88 def getKeyName(self, k):
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
89 if not k.startswith(u'pubsub#'):
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
90 return u'pubsub#' + k
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
91 else:
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
92 return k
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
93
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
94 def start(self):
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
95 self.host.bridge.psNodeConfigurationSet(
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
96 self.args.service,
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
97 self.args.node,
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
98 {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
99 self.profile,
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
100 callback=self.psNodeConfigurationSetCb,
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
101 errback=self.psNodeConfigurationSetEb)
ea0d0a4e2ad8 jp (pubsub/node): added set command
Goffi <goffi@goffi.org>
parents: 2197
diff changeset
102
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
103
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
104 class NodeAffiliationsGet(base.CommandBase):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
105
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
106 def __init__(self, host):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
107 base.CommandBase.__init__(self, host, 'get', use_output=C.OUTPUT_DICT, help=_(u'retrieve node affiliations (for node owner)'))
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
108 self.need_loop=True
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
109
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
110 def add_parser_options(self):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
111 self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to request"))
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
112 self.parser.add_argument("-s", "--service", type=base.unicode_decoder, default=u'',
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
113 help=_(u"JID of the PubSub service (default: request profile own pubsub)"))
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
114
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
115 def psNodeAffiliationsGetCb(self, affiliations):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
116 self.output(affiliations)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
117 self.host.quit()
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
118
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
119 def psNodeAffiliationsGetEb(self, failure_):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
120 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
121 reason=failure_), error=True)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
122 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
123
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
124 def start(self):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
125 self.host.bridge.psNodeAffiliationsGet(
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
126 self.args.service,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
127 self.args.node,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
128 self.profile,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
129 callback=self.psNodeAffiliationsGetCb,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
130 errback=self.psNodeAffiliationsGetEb)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
131
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
132
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
133 class NodeAffiliations(base.CommandBase):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
134 subcommands = (NodeAffiliationsGet,)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
135
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
136 def __init__(self, host):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
137 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
138
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
139
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
140 class Node(base.CommandBase):
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
141 subcommands = (NodeInfo, NodeSet, NodeAffiliations)
2197
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
142
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
143 def __init__(self, host):
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
144 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
145
e0e06391ce91 jp (pubsub): added pubsub/node/info command to retrieve node configuration
Goffi <goffi@goffi.org>
parents: 2195
diff changeset
146
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
147 class Get(base.CommandBase):
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
148
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
149 def __init__(self, host):
2195
d65275ac39b3 plugin XEP-0060: renamed psGet bridge method to psItemGet
Goffi <goffi@goffi.org>
parents: 2191
diff changeset
150 base.CommandBase.__init__(self, host, 'get', use_output=C.OUTPUT_LIST_XML, help=_(u'get pubsub item(s)'))
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
151 self.need_loop=True
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
152
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
153 def add_parser_options(self):
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
154 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
155 help=_(u"item(s) id(s) to get (default: request all items)"))
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
156 self.parser.add_argument("-s", "--sub-id", type=base.unicode_decoder, default=u'',
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
157 help=_(u"subscription id"))
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
158 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
159 # 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
160 self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to request"))
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
161 self.parser.add_argument("service", type=base.unicode_decoder, nargs='?', default=u'',
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
162 help=_(u"JID of the PubSub service (default: request profile own pubsub)"))
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
163 # TODO: add MAM filters
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
164
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
165
2195
d65275ac39b3 plugin XEP-0060: renamed psGet bridge method to psItemGet
Goffi <goffi@goffi.org>
parents: 2191
diff changeset
166 def psItemGetCb(self, ps_result):
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
167 self.output(ps_result[0])
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
168 self.host.quit(C.EXIT_OK)
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
169
2195
d65275ac39b3 plugin XEP-0060: renamed psGet bridge method to psItemGet
Goffi <goffi@goffi.org>
parents: 2191
diff changeset
170 def psItemGetEb(self, failure_):
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
171 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
172 reason=failure_), error=True)
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
173 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
174
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
175 def start(self):
2195
d65275ac39b3 plugin XEP-0060: renamed psGet bridge method to psItemGet
Goffi <goffi@goffi.org>
parents: 2191
diff changeset
176 self.host.bridge.psItemGet(
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
177 self.args.service,
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
178 self.args.node,
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
179 self.args.max,
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
180 self.args.items,
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
181 self.args.sub_id,
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
182 {},
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
183 self.profile,
2195
d65275ac39b3 plugin XEP-0060: renamed psGet bridge method to psItemGet
Goffi <goffi@goffi.org>
parents: 2191
diff changeset
184 callback=self.psItemGetCb,
d65275ac39b3 plugin XEP-0060: renamed psGet bridge method to psItemGet
Goffi <goffi@goffi.org>
parents: 2191
diff changeset
185 errback=self.psItemGetEb)
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
186
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
187
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
188 class Affiliations(base.CommandBase):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
189
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
190 def __init__(self, host):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
191 base.CommandBase.__init__(self, host, 'affiliations', use_output=C.OUTPUT_DICT, help=_(u'retrieve all affiliations on a service'))
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
192 self.need_loop=True
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
193
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
194 def add_parser_options(self):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
195 self.parser.add_argument("-n", "--node", type=base.unicode_decoder, default=u'', help=_(u"node to request"))
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
196 self.parser.add_argument("-s", "--service", type=base.unicode_decoder, default=u'',
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
197 help=_(u"JID of the PubSub service (default: request profile own pubsub)"))
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
198
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
199 def psAffiliationsGetCb(self, affiliations):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
200 self.output(affiliations)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
201 self.host.quit()
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
202
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
203 def psAffiliationsGetEb(self, failure_):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
204 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
205 reason=failure_), error=True)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
206 self.host.quit(C.EXIT_BRIDGE_ERRBACK)
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 def start(self):
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
209 self.host.bridge.psAffiliationsGet(
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
210 self.args.service,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
211 self.args.node,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
212 self.profile,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
213 callback=self.psAffiliationsGetCb,
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
214 errback=self.psAffiliationsGetEb)
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
215
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
216
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
217 class Pubsub(base.CommandBase):
2204
afc703419186 jp (pubsub): added affiliations and node/affiliations/get:
Goffi <goffi@goffi.org>
parents: 2199
diff changeset
218 subcommands = (Get, Node, Affiliations)
2191
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
219
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
220 def __init__(self, host):
a1a8233f89e8 jp(pubsub/get): pubsub/get command, first draft
Goffi <goffi@goffi.org>
parents:
diff changeset
221 super(Pubsub, self).__init__(host, 'pubsub', use_profile=False, help=_('PubSub nodes/items management'))