3 # Copyright (c) 2019 Collabora Ltd
5 # Permission is hereby granted, free of charge, to any person obtaining a
6 # copy of this software and associated documentation files (the "Software"),
7 # to deal in the Software without restriction, including without limitation
8 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
9 # and/or sell copies of the Software, and to permit persons to whom the
10 # Software is furnished to do so, subject to the following conditions:
12 # The above copyright notice and this permission notice shall be included
13 # in all copies or substantial portions of the Software.
15 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
16 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
18 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
19 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
20 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
21 # OTHER DEALINGS IN THE SOFTWARE.
23 # SPDX-License-Identifier: MIT
27 from traceutil
import all_trace_type_names
, trace_type_from_name
28 from traceutil
import trace_type_from_filename
30 def trace_devices(trace
):
31 return [e
['device'] for e
in trace
['expectations']]
33 def cmd_traces_db_repo(args
):
34 with
open(args
.file, 'r') as f
:
36 print(y
['traces-db']['repo'])
38 def cmd_traces_db_commit(args
):
39 with
open(args
.file, 'r') as f
:
41 print(y
['traces-db']['commit'])
44 with
open(args
.file, 'r') as f
:
48 traces
= filter(lambda t
: trace_type_from_filename(t
['path']) in args
.trace_types
,
51 traces
= filter(lambda t
: args
.device_name
in trace_devices(t
), traces
)
58 print('\n'.join((t
['path'] for t
in traces
)))
60 def cmd_checksum(args
):
61 with
open(args
.file, 'r') as f
:
65 trace
= next(t
for t
in traces
if t
['path'] == args
.trace_path
)
66 expectation
= next(e
for e
in trace
['expectations'] if e
['device'] == args
.device_name
)
68 print(expectation
['checksum'])
71 parser
= argparse
.ArgumentParser()
72 parser
.add_argument('--file', required
=True,
73 help='the name of the yaml file')
75 subparsers
= parser
.add_subparsers(help='sub-command help')
77 parser_traces_db_repo
= subparsers
.add_parser('traces_db_repo')
78 parser_traces_db_repo
.set_defaults(func
=cmd_traces_db_repo
)
80 parser_traces_db_commit
= subparsers
.add_parser('traces_db_commit')
81 parser_traces_db_commit
.set_defaults(func
=cmd_traces_db_commit
)
83 parser_traces
= subparsers
.add_parser('traces')
84 parser_traces
.add_argument('--device-name', required
=False,
85 help="the name of the graphics device used to "
87 parser_traces
.add_argument('--trace-types', required
=False,
88 default
=",".join(all_trace_type_names()),
89 help="the types of traces to look for in recursive "
90 "dir walks " "(by default all types)")
91 parser_traces
.set_defaults(func
=cmd_traces
)
93 parser_checksum
= subparsers
.add_parser('checksum')
94 parser_checksum
.add_argument('--device-name', required
=True,
95 help="the name of the graphics device used to "
97 parser_checksum
.add_argument('trace_path')
98 parser_checksum
.set_defaults(func
=cmd_checksum
)
100 args
= parser
.parse_args()
101 if hasattr(args
, 'trace_types'):
102 args
.trace_types
= [trace_type_from_name(t
) for t
in args
.trace_types
.split(",")]
106 if __name__
== "__main__":