5 class TestIter(bt2
._UserMessageIterator
):
11 def _print_params(cls
, params
):
12 inputs
= sorted([str(x
) for x
in params
['inputs']])
13 print('{}: {}'.format(cls
.__name
__, ', '.join(inputs
)))
16 @bt2.plugin_component_class
17 class TestSourceExt(Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
19 Recognize files whose name start with 'aaa', 'bbb' or 'ccc'.
21 'aaa' files are grouped together, 'bbb' files are grouped together, 'ccc'
22 files are not grouped.
25 def __init__(self
, params
):
26 self
._print
_params
(params
)
29 def _user_query(query_exec
, obj
, params
, log_level
):
30 if obj
== 'support-info':
31 if params
['type'] == 'file':
32 name
= os
.path
.basename(str(params
['input']))
34 if name
.startswith('aaa'):
35 return {'weight': 1, 'group': 'aaa'}
36 elif name
.startswith('bbb'):
37 return {'weight': 0.5, 'group': 'bbb'}
38 elif name
.startswith('ccc'):
39 # Try two different ways of returning "no group", and two
40 # different ways of returning 1 (an int and a float).
42 return {'weight': 1, 'group': None}
44 return {'weight': 1.0, 'group': None}
52 raise bt2
.InvalidObject
55 @bt2.plugin_component_class
56 class TestSourceSomeDir(
57 Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
59 """Recognizes directories named "some-dir". The file "aaa10" in the
60 directory "some-dir" won't be found by TestSourceExt, because we won't
61 recurse in "some-dir"."""
63 def __init__(self
, params
):
64 self
._print
_params
(params
)
67 def _user_query(query_exec
, obj
, params
, log_level
):
68 if obj
== 'support-info':
69 if params
['type'] == 'directory':
70 name
= os
.path
.basename(str(params
['input']))
71 return 1 if name
== 'some-dir' else 0
75 raise bt2
.InvalidObject
78 @bt2.plugin_component_class
79 class TestSourceABCDE(Base
, bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
80 """A source that recognizes the arbitrary string input "ABCDE"."""
82 def __init__(self
, params
):
83 self
._print
_params
(params
)
86 def _user_query(query_exec
, obj
, params
, log_level
):
87 if obj
== 'support-info':
90 if params
['type'] == 'string' and params
['input'] == 'ABCDE'
94 raise bt2
.InvalidObject
97 class TestSourceNoQuery(bt2
._UserSourceComponent
, message_iterator_class
=TestIter
):
98 """A source that does not implement _query at all."""
101 bt2
.register_plugin(module_name
=__name__
, name
="test")
This page took 0.031911 seconds and 4 git commands to generate.