MCPcopy Create free account
hub / github.com/apache/impala / get_config_from_file

Function get_config_from_file

shell/impala_shell/option_parser.py:104–155  ·  view source on GitHub ↗

Reads contents of configuration file Two config sections are supported: "[impala]": Overrides the defaults of the shell arguments. Unknown options are filtered and some values are converted from string to their corresponding python types (booleans and None). Multiple flags are appended

(config_filename, option_list)

Source from the content-addressed store, hash-verified

102
103
104def get_config_from_file(config_filename, option_list):
105 """Reads contents of configuration file
106
107 Two config sections are supported:
108 "[impala]":
109 Overrides the defaults of the shell arguments. Unknown options are filtered
110 and some values are converted from string to their corresponding python types
111 (booleans and None).
112
113 Multiple flags are appended with ",option_name=" as its delimiter, e.g.
114 The delimiter is for multiple options is ,<option>=. For example:
115 var=msg1=hello,var=msg2=world.
116
117 Setting 'config_filename' in the config file would have no effect,
118 so its original value is kept.
119
120 "[impala.query_options]"
121 Overrides the defaults of the query options. Not validated here,
122 because validation will take place after connecting to impalad.
123
124 Returns a pair of dictionaries (shell_options, query_options), with option names
125 as keys and option values as values.
126 """
127 try:
128 config = ConfigParser(strict=False) # python3
129 except TypeError:
130 config = ConfigParser() # python2
131
132 # Preserve case-sensitivity since flag names are case sensitive.
133 config.optionxform = str
134 try:
135 config.read(config_filename)
136 except Exception as e:
137 raise ConfigFileFormatError(
138 "Unable to read configuration file correctly. Check formatting: %s" % e)
139
140 shell_options = {}
141 if config.has_section("impala"):
142 shell_options = parse_shell_options(config.items("impala"), impala_shell_defaults,
143 option_list)
144 if "config_file" in shell_options:
145 warn_msg = "WARNING: Option 'config_file' can be only set from shell."
146 print('\n{0}'.format(warn_msg), file=sys.stderr)
147 shell_options["config_file"] = config_filename
148
149 query_options = {}
150 if config.has_section("impala.query_options"):
151 # Query option keys must be "normalized" to upper case before updating with
152 # options coming from command line.
153 query_options = dict(
154 [(k.upper(), v) for k, v in config.items("impala.query_options")])
155 return shell_options, query_options
156
157
158def get_option_parser(defaults):

Callers 1

impala_shell_mainFunction · 0.90

Calls 4

parse_shell_optionsFunction · 0.85
readMethod · 0.45
formatMethod · 0.45

Tested by

no test coverage detected