Commit 3beaa15f authored by Reinout van Rees's avatar Reinout van Rees

Merge pull request #258 from buildout/reinout-missingsectionheader

A MissingSectionHeader error now also reports the cached file
parents 3cbb51d7 3e1fa46f
...@@ -4,7 +4,9 @@ Change History ...@@ -4,7 +4,9 @@ Change History
2.4.2 (unreleased) 2.4.2 (unreleased)
================== ==================
- Nothing changed yet. - If a downloaded config file in the "extends-cache" gets corrupted, buildout
now tells you the filename in the cache. Handy for troubleshooting.
[reinout]
2.4.1 (2015-08-08) 2.4.1 (2015-08-08)
......
...@@ -1570,9 +1570,10 @@ def _open(base, filename, seen, dl_options, override, downloaded): ...@@ -1570,9 +1570,10 @@ def _open(base, filename, seen, dl_options, override, downloaded):
_dl_options, cache=_dl_options.get('extends-cache'), _dl_options, cache=_dl_options.get('extends-cache'),
fallback=fallback, hash_name=True) fallback=fallback, hash_name=True)
is_temp = False is_temp = False
downloaded_filename = None
if _isurl(filename): if _isurl(filename):
path, is_temp = download(filename) downloaded_filename, is_temp = download(filename)
fp = open(path) fp = open(downloaded_filename)
base = filename[:filename.rfind('/')] base = filename[:filename.rfind('/')]
elif _isurl(base): elif _isurl(base):
if os.path.isabs(filename): if os.path.isabs(filename):
...@@ -1580,8 +1581,8 @@ def _open(base, filename, seen, dl_options, override, downloaded): ...@@ -1580,8 +1581,8 @@ def _open(base, filename, seen, dl_options, override, downloaded):
base = os.path.dirname(filename) base = os.path.dirname(filename)
else: else:
filename = base + '/' + filename filename = base + '/' + filename
path, is_temp = download(filename) downloaded_filename, is_temp = download(filename)
fp = open(path) fp = open(downloaded_filename)
base = filename[:filename.rfind('/')] base = filename[:filename.rfind('/')]
else: else:
filename = os.path.join(base, filename) filename = os.path.join(base, filename)
...@@ -1592,16 +1593,22 @@ def _open(base, filename, seen, dl_options, override, downloaded): ...@@ -1592,16 +1593,22 @@ def _open(base, filename, seen, dl_options, override, downloaded):
if filename in seen: if filename in seen:
if is_temp: if is_temp:
fp.close() fp.close()
os.remove(path) os.remove(downloaded_filename)
raise zc.buildout.UserError("Recursive file include", seen, filename) raise zc.buildout.UserError("Recursive file include", seen, filename)
root_config_file = not seen root_config_file = not seen
seen.append(filename) seen.append(filename)
result = zc.buildout.configparser.parse(fp, filename, _default_globals) filename_for_logging = filename
if downloaded_filename:
filename_for_logging = '%s (downloaded as %s)' % (
filename, downloaded_filename)
result = zc.buildout.configparser.parse(
fp, filename_for_logging, _default_globals)
fp.close() fp.close()
if is_temp: if is_temp:
os.remove(path) os.remove(downloaded_filename)
options = result.get('buildout', {}) options = result.get('buildout', {})
extends = options.pop('extends', None) extends = options.pop('extends', None)
......
...@@ -267,7 +267,7 @@ Clean up: ...@@ -267,7 +267,7 @@ Clean up:
>>> rmdir('cache') >>> rmdir('cache')
Offline mode and installation from cache Offline mode and installation from cache
----------------------------~~~~~~~~~~~~ ----------------------------------------
If we run buildout in offline mode now, it will fail because it cannot get at If we run buildout in offline mode now, it will fail because it cannot get at
the remote configuration file needed by the user's defaults: the remote configuration file needed by the user's defaults:
...@@ -505,6 +505,29 @@ While: ...@@ -505,6 +505,29 @@ While:
Error: No-longer supported "extended-by" option found in http://localhost/base.cfg. Error: No-longer supported "extended-by" option found in http://localhost/base.cfg.
Reporting cached locations for downloads of faulty config files
---------------------------------------------------------------
A downloaded config file might be invalid. A cancelled buildout run, an
accidentally gzip-encoded download and so on.
>>> write(server_data, 'faulty.cfg', """\
... This is definitively not
... a proper() config file.
... """)
>>> write('buildout.cfg', """\
... [buildout]
... extends = %sfaulty.cfg
... """ % server_url)
>>> print_(system(buildout))
While:
Initializing.
... File contains no section headers.
file: http://localhost/faulty.cfg (downloaded as ...), line: 1
'This is definitively not\n'
Clean up Clean up
-------- --------
......
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