jp (cmd_pubsub): xmpp: uri handling, first draft

This commit is contained in:
Goffi 2017-06-28 19:19:08 +02:00
commit c2ae6579c3
2 changed files with 30 additions and 0 deletions

View file

@ -59,6 +59,7 @@ class NodeInfo(base.CommandBase):
self.host.quit(C.EXIT_BRIDGE_ERRBACK) self.host.quit(C.EXIT_BRIDGE_ERRBACK)
def start(self): def start(self):
common.checkURI(self.args)
self.host.bridge.psNodeConfigurationGet( self.host.bridge.psNodeConfigurationGet(
self.args.service, self.args.service,
self.args.node, self.args.node,
@ -198,6 +199,7 @@ class NodeAffiliationsGet(base.CommandBase):
self.host.quit(C.EXIT_BRIDGE_ERRBACK) self.host.quit(C.EXIT_BRIDGE_ERRBACK)
def start(self): def start(self):
common.checkURI(self.args)
self.host.bridge.psNodeAffiliationsGet( self.host.bridge.psNodeAffiliationsGet(
self.args.service, self.args.service,
self.args.node, self.args.node,
@ -285,6 +287,7 @@ class Get(base.CommandBase):
self.host.quit(C.EXIT_BRIDGE_ERRBACK) self.host.quit(C.EXIT_BRIDGE_ERRBACK)
def start(self): def start(self):
common.checkURI(self.args)
self.host.bridge.psItemsGet( self.host.bridge.psItemsGet(
self.args.service, self.args.service,
self.args.node, self.args.node,

View file

@ -20,6 +20,7 @@
from sat_frontends.jp.constants import Const as C from sat_frontends.jp.constants import Const as C
from sat.core.i18n import _ from sat.core.i18n import _
from sat.tools.common import regex from sat.tools.common import regex
from sat.tools.common import uri
from sat.tools import config from sat.tools import config
from ConfigParser import NoSectionError, NoOptionError from ConfigParser import NoSectionError, NoOptionError
import json import json
@ -81,6 +82,32 @@ def parse_args(host, cmd_line, **format_kw):
return [] return []
def checkURI(args):
"""check if args.node is an URI
if a valid xmpp: URI is found, args.service, args.node and args.item will be set
"""
# FIXME: Q&D way to handle xmpp: uris, a generic way is needed
# and it should be merged with code in BaseEdit
if not args.service and args.node.startswith('xmpp:'):
try:
uri_data = uri.parseXMPPUri(args.node)
except ValueError:
pass
else:
if uri_data[u'type'] == 'pubsub':
args.service = uri_data[u'path']
args.node = uri_data[u'node']
if u'item' in uri_data:
try:
item = getattr(uri_data, 'item')
except AttributeError:
pass
else:
if item is None:
args.item = uri_data
class BaseEdit(object): class BaseEdit(object):
u"""base class for editing commands u"""base class for editing commands