Commit 7f93ff04 authored by Godefroid Chapelle's avatar Godefroid Chapelle

Problem: some increments of default_cfg do not work

Solution: merge default_cfg in the first config without extends
parent 8376678b
...@@ -110,6 +110,8 @@ class SectionKey(object): ...@@ -110,6 +110,8 @@ class SectionKey(object):
self.value = sectionkey.value self.value = sectionkey.value
if sectionkey.history[-1].operation not in ['ADD', 'REMOVE']: if sectionkey.history[-1].operation not in ['ADD', 'REMOVE']:
self.addToHistory("OVERRIDE", sectionkey.value, sectionkey.source) self.addToHistory("OVERRIDE", sectionkey.value, sectionkey.source)
else:
self.history = copy.deepcopy(sectionkey.history)
def setDirectory(self, value): def setDirectory(self, value):
self.value = value self.value = value
...@@ -304,13 +306,19 @@ _buildout_default_options = _annotate_section({ ...@@ -304,13 +306,19 @@ _buildout_default_options = _annotate_section({
}, 'DEFAULT_VALUE') }, 'DEFAULT_VALUE')
def _get_user_config():
buildout_home = os.path.join(os.path.expanduser('~'), '.buildout')
buildout_home = os.environ.get('BUILDOUT_HOME', buildout_home)
return os.path.join(buildout_home, 'default.cfg')
@commands @commands
class Buildout(DictMixin): class Buildout(DictMixin):
COMMANDS = set() COMMANDS = set()
def __init__(self, config_file, cloptions, def __init__(self, config_file, cloptions,
user_defaults=True, use_user_defaults=True,
command=None, args=()): command=None, args=()):
__doing__ = 'Initializing.' __doing__ = 'Initializing.'
...@@ -352,26 +360,26 @@ class Buildout(DictMixin): ...@@ -352,26 +360,26 @@ class Buildout(DictMixin):
override = copy.deepcopy(cloptions.get('buildout', {})) override = copy.deepcopy(cloptions.get('buildout', {}))
# load user defaults, which override defaults # load user defaults, which override defaults
if user_defaults: user_config = _get_user_config()
if os.environ.get('BUILDOUT_HOME'): if use_user_defaults and os.path.exists(user_config):
buildout_home = os.environ['BUILDOUT_HOME'] data_buildout_copy = copy.deepcopy(data['buildout'])
else: user_defaults, _ = _open(
buildout_home = os.path.join( os.path.dirname(user_config),
os.path.expanduser('~'), '.buildout') user_config, [], data_buildout_copy,
user_config = os.path.join(buildout_home, 'default.cfg') override, set(), {}
if os.path.exists(user_config): )
data_buildout_copy = copy.deepcopy(data['buildout']) for_dl_option = _update(data, user_defaults)
_update(data, _open(os.path.dirname(user_config), user_config, else:
[], data_buildout_copy, override, user_defaults = {}
set())) for_dl_option = copy.deepcopy(data)
# load configuration files # load configuration files
if config_file: if config_file:
data_buildout_copy = copy.deepcopy(data['buildout']) data_buildout_copy = copy.deepcopy(for_dl_option['buildout'])
cfg_data = _open( cfg_data, _ = _open(
os.path.dirname(config_file), os.path.dirname(config_file),
config_file, [], data_buildout_copy, config_file, [], data_buildout_copy,
override, set() override, set(), user_defaults
) )
data = _update(data, cfg_data) data = _update(data, cfg_data)
...@@ -1774,7 +1782,10 @@ def _default_globals(): ...@@ -1774,7 +1782,10 @@ def _default_globals():
return globals_defs return globals_defs
def _open(base, filename, seen, dl_options, override, downloaded):
def _open(
base, filename, seen, dl_options, override, downloaded, user_defaults
):
"""Open a configuration file and return the result as a dictionary, """Open a configuration file and return the result as a dictionary,
Recursively open other files based on buildout options found. Recursively open other files based on buildout options found.
...@@ -1842,16 +1853,19 @@ def _open(base, filename, seen, dl_options, override, downloaded): ...@@ -1842,16 +1853,19 @@ def _open(base, filename, seen, dl_options, override, downloaded):
if extends: if extends:
extends = extends.split() extends = extends.split()
eresult = _open(base, extends.pop(0), seen, dl_options, override, eresult, user_defaults = _open(base, extends.pop(0), seen, dl_options, override,
downloaded) downloaded, user_defaults)
for fname in extends: for fname in extends:
next_extend = _open(base, fname, seen, dl_options, override, next_extend, user_defaults = _open(base, fname, seen, dl_options, override,
downloaded) downloaded, user_defaults)
eresult = _update(eresult, next_extend) eresult = _update(eresult, next_extend)
result = _update(eresult, result) result = _update(eresult, result)
else:
if user_defaults:
result = _update(user_defaults, result)
user_defaults = {}
seen.pop() seen.pop()
return result return result, user_defaults
ignore_directories = '.svn', 'CVS', '__pycache__', '.git' ignore_directories = '.svn', 'CVS', '__pycache__', '.git'
...@@ -2116,7 +2130,7 @@ def main(args=None): ...@@ -2116,7 +2130,7 @@ def main(args=None):
config_file = 'buildout.cfg' config_file = 'buildout.cfg'
verbosity = 0 verbosity = 0
options = [] options = []
user_defaults = True use_user_defaults = True
debug = False debug = False
while args: while args:
if args[0][0] == '-': if args[0][0] == '-':
...@@ -2128,7 +2142,7 @@ def main(args=None): ...@@ -2128,7 +2142,7 @@ def main(args=None):
elif op[0] == 'q': elif op[0] == 'q':
verbosity -= 10 verbosity -= 10
elif op[0] == 'U': elif op[0] == 'U':
user_defaults = False use_user_defaults = False
elif op[0] == 'o': elif op[0] == 'o':
options.append(('buildout', 'offline', 'true')) options.append(('buildout', 'offline', 'true'))
elif op[0] == 'O': elif op[0] == 'O':
...@@ -2199,7 +2213,7 @@ def main(args=None): ...@@ -2199,7 +2213,7 @@ def main(args=None):
try: try:
try: try:
buildout = Buildout(config_file, options, buildout = Buildout(config_file, options,
user_defaults, command, args) use_user_defaults, command, args)
getattr(buildout, command)(args) getattr(buildout, command)(args)
except SystemExit: except SystemExit:
logging.shutdown() logging.shutdown()
......
This diff is collapsed.
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment