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 framework
import exceptions
29 from framework
.replay
import query_traces_yaml
as qty
36 def _traces_db_download_url(args
):
37 y
= qty
.load_yaml(args
.yaml_file
)
39 url
= qty
.download_url(y
) or ""
45 y
= qty
.load_yaml(args
.yaml_file
)
47 t_list
= qty
.traces(y
,
48 trace_extensions
=args
.trace_extensions
,
49 device_name
=args
.device_name
,
50 checksum
=args
.checksum
)
53 print('\n'.join(((t
['path'] + '\n' + t
['checksum'])
56 print('\n'.join((t
['path'] for t
in t_list
)))
60 y
= qty
.load_yaml(args
.yaml_file
)
64 trace
= next(t
for t
in traces
if t
['path'] == args
.file_path
)
69 print(qty
.trace_checksum(trace
, args
.device_name
))
74 """ Parser for replayer query command """
76 parser
= argparse
.ArgumentParser(parents
=[parsers
.YAML
])
77 # The "required" keyword is only available since python >= 3.7
78 subparsers
= parser
.add_subparsers(dest
='command', required
=True)
80 parser
= argparse
.ArgumentParser(parents
=[parsers
.YAML
])
81 # Add a destination due to
82 # https://github.com/python/cpython/pull/3027#issuecomment-330910633
83 subparsers
= parser
.add_subparsers(dest
='command')
85 parser_checksum
= subparsers
.add_parser(
87 parents
=[parsers
.DEVICE
],
88 help=('Outputs, if available, the checksum that a specific device '
89 'should produce for a specified trace file.'))
90 parser_checksum
.add_argument(
92 help=('the path to a trace file.'))
93 parser_checksum
.set_defaults(func
=_checksum
)
95 parser_traces
= subparsers
.add_parser(
97 parents
=[parsers
.DEVICE
],
98 help=('Outputs the trace files filtered by the optional arguments.'))
99 parser_traces
.add_argument(
100 '-t', '--trace-extensions',
103 help=('a comma separated list of trace extensions to look for '
104 'in recursive dir walks (e.g. ".trace,.rdc"). '
105 'If none are provide, all supported extensions '
106 'are used by default'))
107 parser_traces
.add_argument(
110 help='whether to print the checksum below every trace')
111 parser_traces
.set_defaults(func
=_traces
)
113 parser_traces_db_download_url
= subparsers
.add_parser(
114 'traces_db_download_url',
115 help=('Outputs, if available, the download URL.'))
116 parser_traces_db_download_url
.set_defaults(func
=_traces_db_download_url
)
118 args
= parser
.parse_args(input_
)