Skip to content

Commit

Permalink
'include' statement has been added [RHBZ#1272381]
Browse files Browse the repository at this point in the history
  • Loading branch information
plageat authored and xsuchy committed Jul 14, 2016
1 parent 925996f commit 2f147d0
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
3 changes: 3 additions & 0 deletions etc/mock/site-defaults.cfg
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,9 @@
# The site-defaults.cfg delivered by default has NO options set. Only set
# options here if you want to override the defaults.
#
# It's possiable to use include statement in order to make one config included to another:
# include('/path/to/included/config.cfg')
#
# Entries in this file follow the same format as other mock config files.
# config_opts['foo'] = bar

Expand Down
20 changes: 17 additions & 3 deletions py/mockbuild/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -1031,6 +1031,22 @@ def check_config(config_opts):
if 'root' not in config_opts:
raise exception.ConfigError("Error in configuration - option config_opts['root'] must be present in your config.")

@traceLog()
def include(config_file, config_opts, is_statement=False):
if os.path.exists(config_file):
if is_statement and config_file in config_opts['config_paths']:
getLog().warning("Multiple inclusion of %s, skipping" % config_file)
return

config_opts['config_paths'].append(config_file)

with open(config_file) as f:
content = f.read()
content = re.sub(r'include\((.*)\)', r'include(\g<1>, config_opts, True)', content)
code = compile(content, config_file, 'exec')
exec(code)
else:
raise exception.ConfigError("Could not find included config file: %s" % config_file)

@traceLog()
def update_config_from_file(config_opts, config_file, uid_manager):
Expand All @@ -1041,9 +1057,7 @@ def update_config_from_file(config_opts, config_file, uid_manager):
os.close(r_pipe)
if uid_manager and not all(getresuid()):
uid_manager.dropPrivsForever()
with open(config_file) as f:
code = compile(f.read(), config_file, 'exec')
exec(code)
include(config_file, config_opts)
writer = os.fdopen(w_pipe, 'wb')
pickle.dump(config_opts, writer)
except:
Expand Down

0 comments on commit 2f147d0

Please sign in to comment.