Checking future print
[rnaseq-cwl-training.git] / bin / lesson_check.py
index 6de771470a11a4ccdcdb6b25af8649b7885eb6b4..ace8de6943c9a5552827f68952ed2d2eda0a72fc 100755 (executable)
@@ -4,6 +4,7 @@
 Check lesson files and their contents.
 """
 
+from __future__ import print_function
 import sys
 import os
 import glob
@@ -11,7 +12,7 @@ import json
 import re
 from optparse import OptionParser
 
-from util import Reporter, read_markdown, load_yaml
+from util import Reporter, read_markdown, load_yaml, check_unwanted_files, require, IMAGE_FILE_SUFFIX
 
 __version__ = '0.2'
 
@@ -67,6 +68,7 @@ KNOWN_CODEBLOCKS = {
     'source',
     'bash',
     'make',
+    'matlab',
     'python',
     'r',
     'sql'
@@ -100,6 +102,7 @@ def main():
     check_config(args.reporter, args.source_dir)
     docs = read_all_markdown(args.source_dir, args.parser)
     check_fileset(args.source_dir, args.reporter, docs.keys())
+    check_unwanted_files(args.source_dir, args.reporter)
     for filename in docs.keys():
         checker = create_checker(args, filename, docs[filename])
         checker.check()
@@ -145,6 +148,9 @@ 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')
 
 
 def read_all_markdown(source_dir, parser):
@@ -216,9 +222,9 @@ def check_figures(source_dir, reporter):
                      'File not found')
         return
 
-    # Get actual files.
+    # Get actual image files (ignore non-image files).
     fig_dir_path = os.path.join(source_dir, 'fig')
-    actual = [f for f in os.listdir(fig_dir_path) if not f.startswith('.')]
+    actual = [f for f in os.listdir(fig_dir_path) if os.path.splitext(f)[1] in IMAGE_FILE_SUFFIX]
 
     # Report differences.
     unexpected = set(actual) - set(referenced)
@@ -241,14 +247,6 @@ def create_checker(args, filename, info):
             return cls(args, filename, **info)
 
 
-def require(condition, message):
-    """Fail if condition not met."""
-
-    if not condition:
-        print(message, file=sys.stderr)
-        sys.exit(1)
-
-
 class CheckBase(object):
     """Base class for checking Markdown files."""