summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristophe Fontaine <christophe.fontaine@qosmos.com>2016-12-09 15:53:47 +0100
committerOle Trøan <otroan@employees.org>2016-12-13 16:24:21 +0000
commit04f4b78ce25a38ca3feef7d454ad20705b379941 (patch)
treefffea859cf6b0b1ea46ccea192b0616f1fbb9ec1
parentcdab4bde04eab3250b8b4f8b42fcf1dc9a4d2af3 (diff)
vpp_papi: Add help() support for python interactive mode
The python api 1.3 removed the ability to call 'help' in interactive mode. example: > help(vpp.sw_interface_span_enable_disable) Help on function sw_interface_span_enable_disable in module vpp_papi.vpp_papi: sw_interface_span_enable_disable(**kwargs) u16 _vl_msg_id, u32 client_index, u32 context, u32 sw_if_index_from, u32 sw_if_index_to, u8 state Change-Id: Iea1944fdc862482490174ff966592cf3c8208a98 Signed-off-by: Christophe Fontaine <christophe.fontaine@qosmos.com>
-rw-r--r--vpp-api/python/vpp_papi/vpp_papi.py17
1 files changed, 13 insertions, 4 deletions
diff --git a/vpp-api/python/vpp_papi/vpp_papi.py b/vpp-api/python/vpp_papi/vpp_papi.py
index 312aa335572..8e7b7f66ff5 100644
--- a/vpp-api/python/vpp_papi/vpp_papi.py
+++ b/vpp-api/python/vpp_papi/vpp_papi.py
@@ -223,29 +223,38 @@ class VPP():
raise ValueError('Duplicate message name: ' + name)
args = collections.OrderedDict()
+ argtypes = collections.OrderedDict()
fields = []
msg = {}
for f in msgdef:
if type(f) is dict and 'crc' in f:
msg['crc'] = f['crc']
continue
+ field_type = f[0]
field_name = f[1]
args[field_name] = self.__struct(*f)
+ argtypes[field_name] = field_type
fields.append(field_name)
msg['return_tuple'] = collections.namedtuple(name, fields,
rename = True)
self.messages[name] = msg
self.messages[name]['args'] = args
+ self.messages[name]['argtypes'] = argtypes
return self.messages[name]
def add_type(self, name, typedef):
self.add_message('vl_api_' + name + '_t', typedef)
- def make_function(self, i, msgdef, multipart, async):
+ def make_function(self, name, i, msgdef, multipart, async):
if (async):
- return lambda **kwargs: (self._call_vpp_async(i, msgdef, multipart, **kwargs))
+ f = lambda **kwargs: (self._call_vpp_async(i, msgdef, multipart, **kwargs))
else:
- return lambda **kwargs: (self._call_vpp(i, msgdef, multipart, **kwargs))
+ f = lambda **kwargs: (self._call_vpp(i, msgdef, multipart, **kwargs))
+ args = self.messages[name]['args']
+ argtypes = self.messages[name]['argtypes']
+ f.__name__ = str(name)
+ f.__doc__ = ", ".join(["%s %s" % (argtypes[k], k) for k in args.keys()])
+ return f
def _register_functions(self, async=False):
self.id_names = [None] * (self.vpp_dictionary_maxid + 1)
@@ -260,7 +269,7 @@ class VPP():
self.id_msgdef[i] = msgdef
self.id_names[i] = name
multipart = True if name.find('_dump') > 0 else False
- setattr(self, name, self.make_function(i, msgdef, multipart, async))
+ setattr(self, name, self.make_function(name, i, msgdef, multipart, async))
def _write (self, buf):
if not self.connected: