Commit 9610f407 authored by Greg Wilson's avatar Greg Wilson
Browse files

Checking more configuration values

parent 503cdddb
......@@ -146,6 +146,16 @@ def check_config(reporter, source_dir):
config_file = os.path.join(source_dir, '_config.yml')
config = load_yaml(config_file)
reporter.check_field(config_file, 'configuration', config, 'kind', 'lesson')
reporter.check_field(config_file, 'configuration', config, 'carpentry', ('swc', 'dc'))
reporter.check_field(config_file, 'configuration', config, 'title')
reporter.check_field(config_file, 'configuration', config, 'email')
reporter.check_field(config_file, 'configuration', config, 'repo')
reporter.check_field(config_file, 'configuration', config, 'root')
if ('repo' in config) and ('root' in config):
reporter.check(config['repo'].endswith(config['root']),
config_file,
'Repository name "{0}" not consistent with root "{1}"',
config['repo'], config['root'])
def read_all_markdown(source_dir, parser):
......
......@@ -16,6 +16,8 @@ UNWANTED_FILES = [
]
REPORTER_NOT_SET = []
class Reporter(object):
"""Collect and report errors."""
......@@ -26,11 +28,16 @@ class Reporter(object):
self.messages = []
def check_field(self, filename, name, values, key, expected):
def check_field(self, filename, name, values, key, expected=REPORTER_NOT_SET):
"""Check that a dictionary has an expected value."""
if key not in values:
self.add(filename, '{0} does not contain {1}', name, key)
elif expected is REPORTER_NOT_SET:
pass
elif type(expected) in (tuple, set, list):
if values[key] not in expected:
self.add(filename, '{0} {1} value {2} is not in {3}', name, key, values[key], expected)
elif values[key] != expected:
self.add(filename, '{0} {1} is {2} not {3}', name, key, values[key], expected)
......
Supports Markdown
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