3 # Copyright (c) 2019 Collabora Ltd
4 # Copyright © 2020 Valve Corporation.
6 # Permission is hereby granted, free of charge, to any person obtaining a
7 # copy of this software and associated documentation files (the "Software"),
8 # to deal in the Software without restriction, including without limitation
9 # the rights to use, copy, modify, merge, publish, distribute, sublicense,
10 # and/or sell copies of the Software, and to permit persons to whom the
11 # Software is furnished to do so, subject to the following conditions:
13 # The above copyright notice and this permission notice shall be included
14 # in all copies or substantial portions of the Software.
16 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS
17 # OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL
19 # THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR
20 # OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE,
21 # ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR
22 # OTHER DEALINGS IN THE SOFTWARE.
24 # SPDX-License-Identifier: MIT
28 from traceutil
import all_trace_type_names
, trace_type_from_name
29 from traceutil
import trace_type_from_filename
31 def trace_devices(trace
):
32 return [e
['device'] for e
in trace
['expectations']]
34 def cmd_traces_db_gitlab_project_url(args
):
35 with
open(args
.file, 'r') as f
:
37 print(y
['traces-db']['gitlab-project-url'])
39 def cmd_traces_db_commit(args
):
40 with
open(args
.file, 'r') as f
:
42 print(y
['traces-db']['commit'])
45 with
open(args
.file, 'r') as f
:
49 traces
= filter(lambda t
: trace_type_from_filename(t
['path']) in args
.trace_types
,
52 traces
= filter(lambda t
: args
.device_name
in trace_devices(t
), traces
)
59 print('\n'.join((t
['path'] for t
in traces
)))
61 def cmd_checksum(args
):
62 with
open(args
.file, 'r') as f
:
66 trace
= next(t
for t
in traces
if t
['path'] == args
.trace_path
)
67 expectation
= next(e
for e
in trace
['expectations'] if e
['device'] == args
.device_name
)
69 print(expectation
['checksum'])
72 parser
= argparse
.ArgumentParser()
73 parser
.add_argument('--file', required
=True,
74 help='the name of the yaml file')
76 subparsers
= parser
.add_subparsers(help='sub-command help')
78 parser_traces_db_gitlab_project_url
= subparsers
.add_parser('traces_db_gitlab_project_url')
79 parser_traces_db_gitlab_project_url
.set_defaults(func
=cmd_traces_db_gitlab_project_url
)
81 parser_traces_db_commit
= subparsers
.add_parser('traces_db_commit')
82 parser_traces_db_commit
.set_defaults(func
=cmd_traces_db_commit
)
84 parser_traces
= subparsers
.add_parser('traces')
85 parser_traces
.add_argument('--device-name', required
=False,
86 help="the name of the graphics device used to "
88 parser_traces
.add_argument('--trace-types', required
=False,
89 default
=",".join(all_trace_type_names()),
90 help="the types of traces to look for in recursive "
91 "dir walks " "(by default all types)")
92 parser_traces
.set_defaults(func
=cmd_traces
)
94 parser_checksum
= subparsers
.add_parser('checksum')
95 parser_checksum
.add_argument('--device-name', required
=True,
96 help="the name of the graphics device used to "
98 parser_checksum
.add_argument('trace_path')
99 parser_checksum
.set_defaults(func
=cmd_checksum
)
101 args
= parser
.parse_args()
102 if hasattr(args
, 'trace_types'):
103 args
.trace_types
= [trace_type_from_name(t
) for t
in args
.trace_types
.split(",")]
107 if __name__
== "__main__":