merge bookmark @
This commit is contained in:
commit
50d7cb2a51
4 changed files with 277 additions and 150 deletions
|
|
@ -140,7 +140,21 @@ class Bridge:
|
|||
kwargs['reply_handler'] = _callback
|
||||
kwargs['error_handler'] = lambda err: _errback(dbus_to_bridge_exception(err))
|
||||
|
||||
return method(*args, **kwargs)
|
||||
try:
|
||||
return method(*args, **kwargs)
|
||||
except ValueError as e:
|
||||
if e.args[0].startswith("Unable to guess signature"):
|
||||
# XXX: if frontend is started too soon after backend, the
|
||||
# inspection misses methods (notably plugin dynamically added
|
||||
# methods). The following hack works around that by redoing the
|
||||
# cache of introspected methods signatures.
|
||||
log.debug("using hack to work around inspection issue")
|
||||
proxy = self.db_plugin_iface.proxy_object
|
||||
IN_PROGRESS = proxy.INTROSPECT_STATE_INTROSPECT_IN_PROGRESS
|
||||
proxy._introspect_state = IN_PROGRESS
|
||||
proxy._Introspect()
|
||||
return self.db_plugin_iface.get_dbus_method(name)(*args, **kwargs)
|
||||
raise e
|
||||
|
||||
return getPluginMethod
|
||||
|
||||
|
|
@ -930,13 +944,32 @@ class AIOBridge(Bridge):
|
|||
fut.set_result, ret)
|
||||
error_handler = lambda err: loop.call_soon_threadsafe(
|
||||
fut.set_exception, dbus_to_bridge_exception(err))
|
||||
method(
|
||||
*args,
|
||||
**kwargs,
|
||||
timeout=const_TIMEOUT,
|
||||
reply_handler=reply_handler,
|
||||
error_handler=error_handler
|
||||
)
|
||||
try:
|
||||
method(
|
||||
*args,
|
||||
**kwargs,
|
||||
timeout=const_TIMEOUT,
|
||||
reply_handler=reply_handler,
|
||||
error_handler=error_handler
|
||||
)
|
||||
except ValueError as e:
|
||||
if e.args[0].startswith("Unable to guess signature"):
|
||||
# same hack as for Bridge.__getattribute__
|
||||
log.warning("using hack to work around inspection issue")
|
||||
proxy = self.db_plugin_iface.proxy_object
|
||||
IN_PROGRESS = proxy.INTROSPECT_STATE_INTROSPECT_IN_PROGRESS
|
||||
proxy._introspect_state = IN_PROGRESS
|
||||
proxy._Introspect()
|
||||
self.db_plugin_iface.get_dbus_method(name)(
|
||||
*args,
|
||||
**kwargs,
|
||||
timeout=const_TIMEOUT,
|
||||
reply_handler=reply_handler,
|
||||
error_handler=error_handler
|
||||
)
|
||||
|
||||
else:
|
||||
raise e
|
||||
return fut
|
||||
|
||||
return getPluginMethod
|
||||
|
|
|
|||
|
|
@ -54,6 +54,11 @@ class Const(constants.Const):
|
|||
OUTPUT_XMLUI,
|
||||
OUTPUT_LIST_XMLUI,
|
||||
)
|
||||
OUTPUT_NAME_SIMPLE = "simple"
|
||||
OUTPUT_NAME_XML = "xml"
|
||||
OUTPUT_NAME_XML_RAW = "xml-raw"
|
||||
OUTPUT_NAME_JSON = "json"
|
||||
OUTPUT_NAME_JSON_RAW = "json-raw"
|
||||
|
||||
# Pubsub options flags
|
||||
SERVICE = "service" # service required
|
||||
|
|
|
|||
|
|
@ -26,9 +26,6 @@ from sat.tools.common import date_utils
|
|||
import json
|
||||
|
||||
__outputs__ = ["Simple", "Json"]
|
||||
SIMPLE = "simple"
|
||||
JSON = "json"
|
||||
JSON_RAW = "json_raw"
|
||||
|
||||
|
||||
class Simple(object):
|
||||
|
|
@ -36,13 +33,13 @@ class Simple(object):
|
|||
|
||||
def __init__(self, host):
|
||||
self.host = host
|
||||
host.register_output(C.OUTPUT_TEXT, SIMPLE, self.simple_print)
|
||||
host.register_output(C.OUTPUT_LIST, SIMPLE, self.list)
|
||||
host.register_output(C.OUTPUT_DICT, SIMPLE, self.dict)
|
||||
host.register_output(C.OUTPUT_LIST_DICT, SIMPLE, self.list_dict)
|
||||
host.register_output(C.OUTPUT_DICT_DICT, SIMPLE, self.dict_dict)
|
||||
host.register_output(C.OUTPUT_MESS, SIMPLE, self.messages)
|
||||
host.register_output(C.OUTPUT_COMPLEX, SIMPLE, self.simple_print)
|
||||
host.register_output(C.OUTPUT_TEXT, C.OUTPUT_NAME_SIMPLE, self.simple_print)
|
||||
host.register_output(C.OUTPUT_LIST, C.OUTPUT_NAME_SIMPLE, self.list)
|
||||
host.register_output(C.OUTPUT_DICT, C.OUTPUT_NAME_SIMPLE, self.dict)
|
||||
host.register_output(C.OUTPUT_LIST_DICT, C.OUTPUT_NAME_SIMPLE, self.list_dict)
|
||||
host.register_output(C.OUTPUT_DICT_DICT, C.OUTPUT_NAME_SIMPLE, self.dict_dict)
|
||||
host.register_output(C.OUTPUT_MESS, C.OUTPUT_NAME_SIMPLE, self.messages)
|
||||
host.register_output(C.OUTPUT_COMPLEX, C.OUTPUT_NAME_SIMPLE, self.simple_print)
|
||||
|
||||
def simple_print(self, data):
|
||||
self.host.disp(str(data))
|
||||
|
|
@ -109,19 +106,19 @@ class Json(object):
|
|||
|
||||
def __init__(self, host):
|
||||
self.host = host
|
||||
host.register_output(C.OUTPUT_TEXT, JSON, self.dump)
|
||||
host.register_output(C.OUTPUT_LIST, JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_LIST, JSON_RAW, self.dump)
|
||||
host.register_output(C.OUTPUT_DICT, JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_DICT, JSON_RAW, self.dump)
|
||||
host.register_output(C.OUTPUT_LIST_DICT, JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_LIST_DICT, JSON_RAW, self.dump)
|
||||
host.register_output(C.OUTPUT_DICT_DICT, JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_DICT_DICT, JSON_RAW, self.dump)
|
||||
host.register_output(C.OUTPUT_MESS, JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_MESS, JSON_RAW, self.dump)
|
||||
host.register_output(C.OUTPUT_COMPLEX, JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_COMPLEX, JSON_RAW, self.dump)
|
||||
host.register_output(C.OUTPUT_TEXT, C.OUTPUT_NAME_JSON, self.dump)
|
||||
host.register_output(C.OUTPUT_LIST, C.OUTPUT_NAME_JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_LIST, C.OUTPUT_NAME_JSON_RAW, self.dump)
|
||||
host.register_output(C.OUTPUT_DICT, C.OUTPUT_NAME_JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_DICT, C.OUTPUT_NAME_JSON_RAW, self.dump)
|
||||
host.register_output(C.OUTPUT_LIST_DICT, C.OUTPUT_NAME_JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_LIST_DICT, C.OUTPUT_NAME_JSON_RAW, self.dump)
|
||||
host.register_output(C.OUTPUT_DICT_DICT, C.OUTPUT_NAME_JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_DICT_DICT, C.OUTPUT_NAME_JSON_RAW, self.dump)
|
||||
host.register_output(C.OUTPUT_MESS, C.OUTPUT_NAME_JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_MESS, C.OUTPUT_NAME_JSON_RAW, self.dump)
|
||||
host.register_output(C.OUTPUT_COMPLEX, C.OUTPUT_NAME_JSON, self.dump_pretty)
|
||||
host.register_output(C.OUTPUT_COMPLEX, C.OUTPUT_NAME_JSON_RAW, self.dump)
|
||||
|
||||
def dump(self, data):
|
||||
self.host.disp(json.dumps(data, default=str))
|
||||
|
|
|
|||
|
|
@ -1,7 +1,6 @@
|
|||
#! /usr/bin/env python3
|
||||
|
||||
|
||||
# jp: a SàT command line tool
|
||||
# Libervia CLI frontend
|
||||
# Copyright (C) 2009-2021 Jérôme Poisson (goffi@goffi.org)
|
||||
|
||||
# This program is free software: you can redistribute it and/or modify
|
||||
|
|
@ -36,8 +35,6 @@ except ImportError:
|
|||
|
||||
|
||||
__outputs__ = ["XML"]
|
||||
RAW = "xml_raw"
|
||||
PRETTY = "xml_pretty"
|
||||
|
||||
|
||||
class XML(object):
|
||||
|
|
@ -45,16 +42,20 @@ class XML(object):
|
|||
|
||||
def __init__(self, host):
|
||||
self.host = host
|
||||
host.register_output(C.OUTPUT_XML, PRETTY, self.pretty, default=True)
|
||||
host.register_output(C.OUTPUT_LIST_XML, PRETTY, self.pretty_list, default=True)
|
||||
host.register_output(C.OUTPUT_XML, RAW, self.raw)
|
||||
host.register_output(C.OUTPUT_LIST_XML, RAW, self.list_raw)
|
||||
host.register_output(C.OUTPUT_XML, C.OUTPUT_NAME_XML, self.pretty, default=True)
|
||||
host.register_output(
|
||||
C.OUTPUT_LIST_XML, C.OUTPUT_NAME_XML, self.pretty_list, default=True
|
||||
)
|
||||
host.register_output(C.OUTPUT_XML, C.OUTPUT_NAME_XML_RAW, self.raw)
|
||||
host.register_output(C.OUTPUT_LIST_XML, C.OUTPUT_NAME_XML_RAW, self.list_raw)
|
||||
|
||||
def colorize(self, xml):
|
||||
if pygments is None:
|
||||
self.host.disp(
|
||||
_(
|
||||
"Pygments is not available, syntax highlighting is not possible. Please install if from http://pygments.org or with pip install pygments"
|
||||
"Pygments is not available, syntax highlighting is not possible. "
|
||||
"Please install if from http://pygments.org or with pip install "
|
||||
"pygments"
|
||||
),
|
||||
error=True,
|
||||
)
|
||||
|
|
|
|||
Loading…
Reference in a new issue