cli: apply parameters (`--params` option) to leftovers
[babeltrace.git] / tests / data / cli / convert / auto-source-discovery-params / bt_plugin_test.py
CommitLineData
1ead9076
SM
1import bt2
2import os
3
4# This file defines source component classes that print the parameters they
5# receive in their __init__ which start with 'test-'.
6
7
8class TestIter(bt2._UserMessageIterator):
9 pass
10
11
12class Base:
13 @classmethod
14 def _print_test_params(cls, params):
15 items = sorted([str(x) for x in params.items() if x[0].startswith('test-')])
16 print('{}: {}'.format(cls.__name__, ', '.join(items)))
17
18
19@bt2.plugin_component_class
20class TestSourceA(Base, bt2._UserSourceComponent, message_iterator_class=TestIter):
21 def __init__(self, params):
22 self._print_test_params(params)
23
24 @staticmethod
25 def _user_query(priv_query_exec, obj, params):
26 # Match files starting with 'aaa'.
27
28 if obj == 'babeltrace.support-info':
29 if params['type'] != 'file':
30 return 0
31
32 name = os.path.basename(str(params['input']))
33
34 if name.startswith('aaa'):
35 return {'weight': 1, 'group': 'aaa'}
36 else:
37 return 0
38 else:
39 raise bt2.UnknownObject
40
41
42@bt2.plugin_component_class
43class TestSourceB(Base, bt2._UserSourceComponent, message_iterator_class=TestIter):
44 def __init__(self, params):
45 self._print_test_params(params)
46
47 @staticmethod
48 def _user_query(priv_query_exec, obj, params):
49 # Match files starting with 'bbb'.
50
51 if obj == 'babeltrace.support-info':
52 if params['type'] != 'file':
53 return 0
54
55 name = os.path.basename(str(params['input']))
56
57 if name.startswith('bbb'):
58 return {'weight': 1, 'group': 'bbb'}
59 else:
60 return 0
61 else:
62 raise bt2.UnknownObject
63
64
65bt2.register_plugin(module_name=__name__, name="test")
This page took 0.025856 seconds and 4 git commands to generate.