a4d53dbd88d75b267badb2ed8b645e2698b69aaa
4 # Source component classes in this file recognize and group inputs in
5 # various ways. One stream is created by each component, with a name
6 # derived from the component class and the inputs. This is then checked
7 # using the `sink.text.details` sink.
10 class TestIter(bt2
._UserMessageIterator
):
11 def __init__(self
, output_port
):
12 inputs
= output_port
.user_data
['inputs']
13 sc
= output_port
.user_data
['sc']
16 s
= t
.create_stream(sc
, name
=self
._make
_stream
_name
(inputs
))
19 self
._create
_stream
_beginning
_message
(s
),
20 self
._create
_stream
_end
_message
(s
),
23 def _make_stream_name(self
, inputs
):
24 comp_cls_name
= self
._component
.__class
__.__name
__
28 + ', '.join(sorted([os
.path
.basename(str(x
)) for x
in inputs
]))
32 if len(self
._msgs
) == 0:
35 return self
._msgs
.pop(0)
39 def __init__(self
, params
):
40 tc
= self
._create
_trace
_class
()
41 sc
= tc
.create_stream_class()
43 self
._add
_output
_port
('out', {'inputs': params
['inputs'], 'sc': sc
})
46 @bt2.plugin_component_class
47 class TestSourceExt(Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
49 Recognize files whose name start with 'aaa', 'bbb' or 'ccc'.
51 'aaa' files are grouped together, 'bbb' files are grouped together, 'ccc'
52 files are not grouped.
55 def __init__(self
, params
, obj
):
56 super().__init
__(params
)
59 def _user_query(priv_query_exec
, obj
, params
, method_obj
):
60 if obj
== 'babeltrace.support-info':
61 if params
['type'] == 'file':
62 name
= os
.path
.basename(str(params
['input']))
64 if name
.startswith('aaa'):
65 return {'weight': 1, 'group': 'aaa'}
66 elif name
.startswith('bbb'):
67 return {'weight': 0.5, 'group': 'bbb'}
68 elif name
.startswith('ccc'):
69 # Try two different ways of returning "no group", and two
70 # different ways of returning 1 (an int and a float).
72 return {'weight': 1, 'group': None}
74 return {'weight': 1.0, 'group': None}
82 raise bt2
.UnknownObject
85 @bt2.plugin_component_class
86 class TestSourceSomeDir(
87 Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
89 """Recognizes directories named "some-dir". The file "aaa10" in the
90 directory "some-dir" won't be found by TestSourceExt, because we won't
91 recurse in "some-dir"."""
93 def __init__(self
, params
, obj
):
94 super().__init
__(params
)
97 def _user_query(priv_query_exec
, obj
, params
, method_obj
):
98 if obj
== 'babeltrace.support-info':
99 if params
['type'] == 'directory':
100 name
= os
.path
.basename(str(params
['input']))
101 return 1 if name
== 'some-dir' else 0
105 raise bt2
.UnknownObject
108 @bt2.plugin_component_class
109 class TestSourceABCDE(Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
110 """A source that recognizes the arbitrary string input "ABCDE"."""
112 def __init__(self
, params
, obj
):
113 super().__init
__(params
)
116 def _user_query(priv_query_exec
, obj
, params
, method_obj
):
117 if obj
== 'babeltrace.support-info':
120 if params
['type'] == 'string' and params
['input'] == 'ABCDE'
124 raise bt2
.UnknownObject
127 class TestSourceNoQuery(bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
128 """A source that does not implement _query at all."""
131 bt2
.register_plugin(module_name
=__name__
, name
="test")
This page took 0.03318 seconds and 3 git commands to generate.