From 68bf4bb0671f86ac93a100f0bdff168f9ef664f1 Mon Sep 17 00:00:00 2001 From: Greg Wilson Date: Sun, 3 Jul 2016 17:43:08 -0400 Subject: [PATCH] Checking for .nojekyll file --- bin/lesson_check.py | 3 ++- bin/util.py | 20 ++++++++++++++++++++ bin/workshop_check.py | 3 ++- 3 files changed, 24 insertions(+), 2 deletions(-) diff --git a/bin/lesson_check.py b/bin/lesson_check.py index 6de7714..9e051bd 100755 --- a/bin/lesson_check.py +++ b/bin/lesson_check.py @@ -11,7 +11,7 @@ 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 __version__ = '0.2' @@ -100,6 +100,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() diff --git a/bin/util.py b/bin/util.py index f7aaf2e..8ce17fe 100644 --- a/bin/util.py +++ b/bin/util.py @@ -1,13 +1,21 @@ import sys +import os import json from subprocess import Popen, PIPE +# Import this way to produce a more useful error message. try: import yaml except ImportError: print('Unable to import YAML module: please install PyYAML', file=sys.stderr) sys.exit(1) + +UNWANTED_FILES = [ + '.nojekyll' +] + + class Reporter(object): """Collect and report errors.""" @@ -124,3 +132,15 @@ def load_yaml(filename): except (yaml.YAMLError, FileNotFoundError) as e: print('Unable to load YAML file {0}:\n{1}'.format(filename, e), file=sys.stderr) sys.exit(1) + + +def check_unwanted_files(dir_path, reporter): + """ + Check that unwanted files are not present. + """ + + for filename in UNWANTED_FILES: + path = os.path.join(dir_path, filename) + reporter.check(not os.path.exists(path), + path, + "Unwanted file found") diff --git a/bin/workshop_check.py b/bin/workshop_check.py index d018b78..1dcd33c 100755 --- a/bin/workshop_check.py +++ b/bin/workshop_check.py @@ -8,7 +8,7 @@ import os import re from datetime import date -from util import Reporter, split_metadata +from util import Reporter, split_metadata, load_yaml, check_unwanted_files # Metadata field patterns. @@ -400,6 +400,7 @@ def main(): reporter = Reporter() check_config(reporter, config_file) + check_unwanted_files(root_dir, reporter) with open(index_file) as reader: data = reader.read() check_file(reporter, index_file, data)