#
# Copyright (c) 2017 Philippe Proulx <pproulx@efficios.com>
-from bt2 import native_bt, object, utils
+import os.path
import collections.abc
+
+from bt2 import utils as bt2_utils
+from bt2 import object as bt2_object
from bt2 import component as bt2_component
-import os.path
+from bt2 import native_bt
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)
+ bt2_utils._check_str(path)
+ bt2_utils._check_bool(recurse)
+ bt2_utils._check_bool(fail_on_load_error)
plugin_set_ptr = None
if os.path.isfile(path):
if status == native_bt.__BT_FUNC_STATUS_NOT_FOUND:
return
- utils._handle_func_status(status, 'failed to find plugins')
+ bt2_utils._handle_func_status(status, "failed to find plugins")
assert plugin_set_ptr is not None
return _PluginSet._create_from_ptr(plugin_set_ptr)
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)
+ bt2_utils._check_bool(find_in_std_env_var)
+ bt2_utils._check_bool(find_in_user_dir)
+ bt2_utils._check_bool(find_in_sys_dir)
+ bt2_utils._check_bool(find_in_static)
+ bt2_utils._check_bool(fail_on_load_error)
plugin_set_ptr = None
status, plugin_set_ptr = native_bt.bt2_plugin_find_all(
if status == native_bt.__BT_FUNC_STATUS_NOT_FOUND:
return
- utils._handle_func_status(status, 'failed to find plugins')
+ bt2_utils._handle_func_status(status, "failed to find plugins")
assert plugin_set_ptr is not None
return _PluginSet._create_from_ptr(plugin_set_ptr)
find_in_static=True,
fail_on_load_error=False,
):
- utils._check_str(name)
- utils._check_bool(fail_on_load_error)
+ bt2_utils._check_str(name)
+ bt2_utils._check_bool(fail_on_load_error)
status, ptr = native_bt.bt2_plugin_find(
name,
int(find_in_std_env_var),
if status == native_bt.__BT_FUNC_STATUS_NOT_FOUND:
return
- utils._handle_func_status(status, 'failed to find plugin')
+ bt2_utils._handle_func_status(status, "failed to find plugin")
assert ptr is not None
return _Plugin._create_from_ptr(ptr)
-class _PluginSet(object._SharedObject, collections.abc.Sequence):
- _put_ref = staticmethod(native_bt.plugin_set_put_ref)
- _get_ref = staticmethod(native_bt.plugin_set_get_ref)
+class _PluginSet(bt2_object._SharedObject, collections.abc.Sequence):
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.plugin_set_put_ref(ptr)
+
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.plugin_set_get_ref(ptr)
def __len__(self):
count = native_bt.plugin_set_get_plugin_count(self._ptr)
return count
def __getitem__(self, index):
- utils._check_uint64(index)
+ bt2_utils._check_uint64(index)
if index >= len(self):
raise IndexError
return self._extra
def __str__(self):
- extra = ''
+ extra = ""
if self._extra is not None:
extra = self._extra
- return '{}.{}.{}{}'.format(self._major, self._minor, self._patch, extra)
+ return "{}.{}.{}{}".format(self._major, self._minor, self._patch, extra)
class _PluginComponentClassesIterator(collections.abc.Iterator):
self._plugin = plugin
def __getitem__(self, key):
- utils._check_str(key)
+ bt2_utils._check_str(key)
cc_ptr = self._borrow_component_class_by_name(self._plugin._ptr, key)
if cc_ptr is None:
_comp_cls_type = native_bt.COMPONENT_CLASS_TYPE_SINK
-class _Plugin(object._SharedObject):
- _put_ref = staticmethod(native_bt.plugin_put_ref)
- _get_ref = staticmethod(native_bt.plugin_get_ref)
+class _Plugin(bt2_object._SharedObject):
+ @staticmethod
+ def _put_ref(ptr):
+ native_bt.plugin_put_ref(ptr)
+
+ @staticmethod
+ def _get_ref(ptr):
+ native_bt.plugin_get_ref(ptr)
@property
def name(self):