1 # SPDX-License-Identifier: GPL-2.0-only
3 # Copyright (C) 2019 EfficiOS Inc.
9 # Source component classes in this file recognize and group inputs in
10 # various ways. One stream is created by each component, with a name
11 # derived from the component class and the inputs. This is then checked
12 # using the `sink.text.details` sink.
15 class TestIter(bt2
._UserMessageIterator
):
16 def __init__(self
, config
, output_port
):
17 inputs
= output_port
.user_data
['inputs']
18 sc
= output_port
.user_data
['sc']
21 s
= t
.create_stream(sc
, name
=self
._make
_stream
_name
(inputs
))
24 self
._create
_stream
_beginning
_message
(s
),
25 self
._create
_stream
_end
_message
(s
),
28 def _make_stream_name(self
, inputs
):
29 comp_cls_name
= self
._component
.__class
__.__name
__
33 + ', '.join(sorted([os
.path
.basename(str(x
)) for x
in inputs
]))
37 if len(self
._msgs
) == 0:
40 return self
._msgs
.pop(0)
44 def __init__(self
, params
):
45 tc
= self
._create
_trace
_class
()
46 sc
= tc
.create_stream_class()
48 self
._add
_output
_port
('out', {'inputs': params
['inputs'], 'sc': sc
})
51 @bt2.plugin_component_class
52 class TestSourceExt(Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
54 Recognize files whose name start with 'aaa', 'bbb' or 'ccc'.
56 'aaa' files are grouped together, 'bbb' files are grouped together, 'ccc'
57 files are not grouped.
60 def __init__(self
, config
, params
, obj
):
61 super().__init
__(params
)
64 def _user_query(priv_query_exec
, obj
, params
, method_obj
):
65 if obj
== 'babeltrace.support-info':
66 if params
['type'] == 'file':
67 name
= os
.path
.basename(str(params
['input']))
69 if name
.startswith('aaa'):
70 return {'weight': 1, 'group': 'aaa'}
71 elif name
.startswith('bbb'):
72 return {'weight': 0.5, 'group': 'bbb'}
73 elif name
.startswith('ccc'):
74 # Try two different ways of returning 1 (an int and a float).
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
, config
, 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
, config
, 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.031173 seconds and 4 git commands to generate.