Skip to content

Commit

Permalink
Checking more configuration values
Browse files Browse the repository at this point in the history
  • Loading branch information
Greg Wilson committed Jul 6, 2016
1 parent 503cddd commit 9610f40
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
10 changes: 10 additions & 0 deletions bin/lesson_check.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down
9 changes: 8 additions & 1 deletion bin/util.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
]


REPORTER_NOT_SET = []

class Reporter(object):
"""Collect and report errors."""

Expand All @@ -26,11 +28,16 @@ def __init__(self):
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)

Expand Down

0 comments on commit 9610f40

Please sign in to comment.