2 # Copyright (c) 2015-2016, 2019 Intel Corporation
4 # Permission is hereby granted, free of charge, to any person obtaining a copy
5 # of this software and associated documentation files (the "Software"), to deal
6 # in the Software without restriction, including without limitation the rights
7 # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8 # copies of the Software, and to permit persons to whom the Software is
9 # furnished to do so, subject to the following conditions:
11 # The above copyright notice and this permission notice shall be included in
12 # all copies or substantial portions of the Software.
14 # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15 # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16 # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17 # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18 # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19 # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22 """Shared parsers for use in multiple modules.
24 Much of this module is based on taking advantage of ArgumentParser's parent
25 argument and it's parse_known_args() method. The idea is that some parts of
26 parsers can be shared to reduce code duplication, either by parsing the
27 arguments early and acting on them, or by inheriting from a parent object.
31 from __future__
import (
32 absolute_import
, division
, print_function
, unicode_literals
36 from framework
import core
38 # parse the config file before any other options, this allows the config file
39 # to be used to set default values for the parser.
40 CONFIG
= argparse
.ArgumentParser(add_help
=False)
41 CONFIG
.add_argument("-f", "--config",
43 type=argparse
.FileType("r"),
44 help="override piglit.conf search path")
47 def parse_config(input_
):
48 """Convenience method for the CONFIG parser.
50 This returns a two element tuple, the first element is a namespace with the
51 known arguments in it (in this case the config_file), and the second is the
52 remaining unparsed arguments. These remaining arguments should be passed to
53 a new ArgumentParser instance.
55 This will also call core.get_config on the config file. The parsed options
56 are passed to ensure API compatibility
59 parsed
, unparsed
= CONFIG
.parse_known_args(input_
)
61 # Read the config file
62 # We want to read this before we finish parsing since some default options
63 # are set in the config file.
64 core
.get_config(parsed
.config_file
)
66 return parsed
, unparsed