Skip to content

Commit

Permalink
[one-cmds] Parse cfg file and overwrite args (Samsung#7869)
Browse files Browse the repository at this point in the history
This commit adds `_parse_cfg_and_overwrite` function to utils.

ONE-DCO-1.0-Signed-off-by: seongwoo <[email protected]>
  • Loading branch information
mhs4670go authored Oct 21, 2021
1 parent 0c3d5b8 commit 708a7e9
Showing 1 changed file with 26 additions and 1 deletion.
27 changes: 26 additions & 1 deletion compiler/one-cmds/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -126,9 +126,34 @@ def _is_valid_attr(args, attr):
return hasattr(args, attr) and getattr(args, attr)


def _parse_cfg_and_overwrite(config_path, section, args):
"""
parse given section of configuration file and set the values of args.
Even if the values parsed from the configuration file already exist in args,
the values are overwritten.
"""
if config_path == None:
# DO NOTHING
return
config = configparser.ConfigParser()
# make option names case sensitive
config.optionxform = str
parsed = config.read(config_path)
if not parsed:
raise FileNotFoundError('Not found given configuration file')
if not config.has_section(section):
raise AssertionError('configuration file doesn\'t have \'' + section +
'\' section')
for key in config[section]:
setattr(args, key, config[section][key])
# TODO support accumulated arguments


def _parse_cfg(args, driver_name):
"""parse configuration file. If the option is directly given to the command line,
the option is processed prior to the configuration file."""
the option is processed prior to the configuration file.
That is, if the values parsed from the configuration file already exist in args,
the values are ignored."""
if _is_valid_attr(args, 'config'):
config = configparser.ConfigParser()
config.optionxform = str
Expand Down

0 comments on commit 708a7e9

Please sign in to comment.