Mercurial > libervia-backend
comparison frontends/src/jp/cmd_pubsub.py @ 2207:d662bdd682b2
jp (pubsub/node) added pubsub/node/affiliations/set command
author | Goffi <goffi@goffi.org> |
---|---|
date | Sun, 26 Mar 2017 18:08:05 +0200 |
parents | afc703419186 |
children | 4e06cd44e667 |
comparison
equal
deleted
inserted
replaced
2206:59d3de85a0cb | 2207:d662bdd682b2 |
---|---|
106 def __init__(self, host): | 106 def __init__(self, host): |
107 base.CommandBase.__init__(self, host, 'get', use_output=C.OUTPUT_DICT, help=_(u'retrieve node affiliations (for node owner)')) | 107 base.CommandBase.__init__(self, host, 'get', use_output=C.OUTPUT_DICT, help=_(u'retrieve node affiliations (for node owner)')) |
108 self.need_loop=True | 108 self.need_loop=True |
109 | 109 |
110 def add_parser_options(self): | 110 def add_parser_options(self): |
111 self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to request")) | |
112 self.parser.add_argument("-s", "--service", type=base.unicode_decoder, default=u'', | 111 self.parser.add_argument("-s", "--service", type=base.unicode_decoder, default=u'', |
113 help=_(u"JID of the PubSub service (default: request profile own pubsub)")) | 112 help=_(u"JID of the PubSub service (default: request profile own pubsub)")) |
113 self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to request")) | |
114 | 114 |
115 def psNodeAffiliationsGetCb(self, affiliations): | 115 def psNodeAffiliationsGetCb(self, affiliations): |
116 self.output(affiliations) | 116 self.output(affiliations) |
117 self.host.quit() | 117 self.host.quit() |
118 | 118 |
128 self.profile, | 128 self.profile, |
129 callback=self.psNodeAffiliationsGetCb, | 129 callback=self.psNodeAffiliationsGetCb, |
130 errback=self.psNodeAffiliationsGetEb) | 130 errback=self.psNodeAffiliationsGetEb) |
131 | 131 |
132 | 132 |
133 class NodeAffiliationsSet(base.CommandBase): | |
134 | |
135 def __init__(self, host): | |
136 base.CommandBase.__init__(self, host, 'set', use_verbose=True, help=_(u'set affiliations (for node owner)')) | |
137 self.need_loop=True | |
138 | |
139 def add_parser_options(self): | |
140 self.parser.add_argument("-s", "--service", type=base.unicode_decoder, default=u'', | |
141 help=_(u"JID of the PubSub service (default: request profile own pubsub)")) | |
142 self.parser.add_argument("node", type=base.unicode_decoder, help=_(u"node to set")) | |
143 # XXX: we use optional argument syntax for a required one because list of list of 2 elements | |
144 # (uses to construct dicts) don't work with positional arguments | |
145 self.parser.add_argument("-a", | |
146 "--affiliation", | |
147 dest="affiliations", | |
148 metavar=('JID', 'AFFILIATION'), | |
149 required=True, | |
150 type=base.unicode_decoder, | |
151 action="append", | |
152 nargs=2, | |
153 help=_(u"entity/affiliation couple(s)")) | |
154 | |
155 def psNodeAffiliationsSetCb(self): | |
156 self.disp(_(u"affiliations have been set"), 1) | |
157 self.host.quit() | |
158 | |
159 def psNodeAffiliationsSetEb(self, failure_): | |
160 self.disp(u"can't set node affiliations: {reason}".format( | |
161 reason=failure_), error=True) | |
162 self.host.quit(C.EXIT_BRIDGE_ERRBACK) | |
163 | |
164 def start(self): | |
165 affiliations = dict(self.args.affiliations) | |
166 self.host.bridge.psNodeAffiliationsSet( | |
167 self.args.service, | |
168 self.args.node, | |
169 affiliations, | |
170 self.profile, | |
171 callback=self.psNodeAffiliationsSetCb, | |
172 errback=self.psNodeAffiliationsSetEb) | |
173 | |
174 | |
133 class NodeAffiliations(base.CommandBase): | 175 class NodeAffiliations(base.CommandBase): |
134 subcommands = (NodeAffiliationsGet,) | 176 subcommands = (NodeAffiliationsGet, NodeAffiliationsSet) |
135 | 177 |
136 def __init__(self, host): | 178 def __init__(self, host): |
137 super(NodeAffiliations, self).__init__(host, 'affiliations', use_profile=False, help=_(u'set or retrieve node affiliations')) | 179 super(NodeAffiliations, self).__init__(host, 'affiliations', use_profile=False, help=_(u'set or retrieve node affiliations')) |
138 | 180 |
139 | 181 |