Checking more configuration values
authorGreg Wilson <gvwilson@third-bit.com>
Wed, 6 Jul 2016 00:48:45 +0000 (20:48 -0400)
committerGreg Wilson <gvwilson@third-bit.com>
Wed, 6 Jul 2016 00:48:45 +0000 (20:48 -0400)
bin/lesson_check.py
bin/util.py

index 9e051bdb2b331a28ec504495544285040f658034..016b395451659e299cdeb2f60af299cd0f9e96bc 100755 (executable)
@@ -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):
index 8ce17fea6bd4840adad137b8193f25337fee5a15..2341bdb006b9bfae5d85243cc5d13dfe60e3b652 100644 (file)
@@ -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)