X-Git-Url: http://git.efficios.com/?a=blobdiff_plain;f=src%2Fbindings%2Fpython%2Fbt2%2Fbt2%2Fplugin.py;h=cb169f484a36ee317ab2cc22011051522f514407;hb=615238bec18761cbb35873ffb370e555d47cefec;hp=2d0d8b057303afa44d1e8cb0a832ac429c4b11c3;hpb=578e048b5debf169e286e5b5cc747b5d6c16886d;p=babeltrace.git diff --git a/src/bindings/python/bt2/bt2/plugin.py b/src/bindings/python/bt2/bt2/plugin.py index 2d0d8b05..cb169f48 100644 --- a/src/bindings/python/bt2/bt2/plugin.py +++ b/src/bindings/python/bt2/bt2/plugin.py @@ -22,34 +22,89 @@ from bt2 import native_bt, object, utils import collections.abc -import bt2.component +from bt2 import component as bt2_component import os.path -import bt2 -def find_plugins(path, recurse=True): +def find_plugins_in_path(path, recurse=True, fail_on_load_error=False): utils._check_str(path) utils._check_bool(recurse) + utils._check_bool(fail_on_load_error) plugin_set_ptr = None if os.path.isfile(path): - plugin_set_ptr = native_bt.plugin_find_all_from_file(path) + status, plugin_set_ptr = native_bt.bt2_plugin_find_all_from_file( + path, fail_on_load_error + ) elif os.path.isdir(path): - plugin_set_ptr = native_bt.plugin_find_all_from_dir(path, int(recurse)) + status, plugin_set_ptr = native_bt.bt2_plugin_find_all_from_dir( + path, int(recurse), int(fail_on_load_error) + ) + else: + raise ValueError("invalid path: '{}'".format(path)) - if plugin_set_ptr is None: + if status == native_bt.__BT_FUNC_STATUS_NOT_FOUND: return + utils._handle_func_status(status, 'failed to find plugins') + assert plugin_set_ptr is not None return _PluginSet._create_from_ptr(plugin_set_ptr) -def find_plugin(name): - utils._check_str(name) - ptr = native_bt.plugin_find(name) +def find_plugins( + find_in_std_env_var=True, + find_in_user_dir=True, + find_in_sys_dir=True, + find_in_static=True, + fail_on_load_error=False, +): + utils._check_bool(find_in_std_env_var) + utils._check_bool(find_in_user_dir) + utils._check_bool(find_in_sys_dir) + utils._check_bool(find_in_static) + utils._check_bool(fail_on_load_error) + plugin_set_ptr = None + + status, plugin_set_ptr = native_bt.bt2_plugin_find_all( + int(find_in_std_env_var), + int(find_in_user_dir), + int(find_in_sys_dir), + int(find_in_static), + int(fail_on_load_error), + ) + + if status == native_bt.__BT_FUNC_STATUS_NOT_FOUND: + return - if ptr is None: + utils._handle_func_status(status, 'failed to find plugins') + assert plugin_set_ptr is not None + return _PluginSet._create_from_ptr(plugin_set_ptr) + + +def find_plugin( + name, + find_in_std_env_var=True, + find_in_user_dir=True, + find_in_sys_dir=True, + find_in_static=True, + fail_on_load_error=False, +): + utils._check_str(name) + utils._check_bool(fail_on_load_error) + status, ptr = native_bt.bt2_plugin_find( + name, + int(find_in_std_env_var), + int(find_in_user_dir), + int(find_in_sys_dir), + int(find_in_static), + int(fail_on_load_error), + ) + + if status == native_bt.__BT_FUNC_STATUS_NOT_FOUND: return + utils._handle_func_status(status, 'failed to find plugin') + assert ptr is not None return _Plugin._create_from_ptr(ptr) @@ -59,7 +114,7 @@ class _PluginSet(object._SharedObject, collections.abc.Sequence): def __len__(self): count = native_bt.plugin_set_get_plugin_count(self._ptr) - assert(count >= 0) + assert count >= 0 return count def __getitem__(self, index): @@ -117,13 +172,17 @@ class _PluginComponentClassesIterator(collections.abc.Iterator): if self._at == total: raise StopIteration - comp_cls_ptr = self._plugin_comp_cls._borrow_component_class_by_index(plugin_ptr, self._at) + comp_cls_ptr = self._plugin_comp_cls._borrow_component_class_by_index( + plugin_ptr, self._at + ) assert comp_cls_ptr is not None self._at += 1 comp_cls_type = self._plugin_comp_cls._comp_cls_type - comp_cls_pycls = bt2.component._COMP_CLS_TYPE_TO_GENERIC_COMP_CLS_PYCLS[comp_cls_type] - comp_cls_ptr = comp_cls_pycls._as_component_class_ptr(comp_cls_ptr) + comp_cls_pycls = bt2_component._COMP_CLS_TYPE_TO_GENERIC_COMP_CLS_PYCLS[ + comp_cls_type + ] + comp_cls_ptr = comp_cls_pycls._bt_as_component_class_ptr(comp_cls_ptr) name = native_bt.component_class_get_name(comp_cls_ptr) assert name is not None return name @@ -140,7 +199,9 @@ class _PluginComponentClasses(collections.abc.Mapping): if cc_ptr is None: raise KeyError(key) - return bt2.component._create_component_class_from_ptr_and_get_ref(cc_ptr, self._comp_cls_type) + return bt2_component._create_component_class_from_const_ptr_and_get_ref( + cc_ptr, self._comp_cls_type + ) def __len__(self): return self._component_class_count(self._plugin._ptr) @@ -150,23 +211,41 @@ class _PluginComponentClasses(collections.abc.Mapping): class _PluginSourceComponentClasses(_PluginComponentClasses): - _component_class_count = staticmethod(native_bt.plugin_get_source_component_class_count) - _borrow_component_class_by_name = staticmethod(native_bt.plugin_borrow_source_component_class_by_name_const) - _borrow_component_class_by_index = staticmethod(native_bt.plugin_borrow_source_component_class_by_index_const) + _component_class_count = staticmethod( + native_bt.plugin_get_source_component_class_count + ) + _borrow_component_class_by_name = staticmethod( + native_bt.plugin_borrow_source_component_class_by_name_const + ) + _borrow_component_class_by_index = staticmethod( + native_bt.plugin_borrow_source_component_class_by_index_const + ) _comp_cls_type = native_bt.COMPONENT_CLASS_TYPE_SOURCE class _PluginFilterComponentClasses(_PluginComponentClasses): - _component_class_count = staticmethod(native_bt.plugin_get_filter_component_class_count) - _borrow_component_class_by_name = staticmethod(native_bt.plugin_borrow_filter_component_class_by_name_const) - _borrow_component_class_by_index = staticmethod(native_bt.plugin_borrow_filter_component_class_by_index_const) + _component_class_count = staticmethod( + native_bt.plugin_get_filter_component_class_count + ) + _borrow_component_class_by_name = staticmethod( + native_bt.plugin_borrow_filter_component_class_by_name_const + ) + _borrow_component_class_by_index = staticmethod( + native_bt.plugin_borrow_filter_component_class_by_index_const + ) _comp_cls_type = native_bt.COMPONENT_CLASS_TYPE_FILTER class _PluginSinkComponentClasses(_PluginComponentClasses): - _component_class_count = staticmethod(native_bt.plugin_get_sink_component_class_count) - _borrow_component_class_by_name = staticmethod(native_bt.plugin_borrow_sink_component_class_by_name_const) - _borrow_component_class_by_index = staticmethod(native_bt.plugin_borrow_sink_component_class_by_index_const) + _component_class_count = staticmethod( + native_bt.plugin_get_sink_component_class_count + ) + _borrow_component_class_by_name = staticmethod( + native_bt.plugin_borrow_sink_component_class_by_name_const + ) + _borrow_component_class_by_index = staticmethod( + native_bt.plugin_borrow_sink_component_class_by_index_const + ) _comp_cls_type = native_bt.COMPONENT_CLASS_TYPE_SINK @@ -177,7 +256,7 @@ class _Plugin(object._SharedObject): @property def name(self): name = native_bt.plugin_get_name(self._ptr) - assert(name is not None) + assert name is not None return name @property @@ -198,7 +277,7 @@ class _Plugin(object._SharedObject): @property def version(self): - status, major, minor, patch, extra = native_bt.plugin_get_version_wrapper(self._ptr) + status, major, minor, patch, extra = native_bt.bt2_plugin_get_version(self._ptr) if status == native_bt.PROPERTY_AVAILABILITY_NOT_AVAILABLE: return