Skip to content
Snippets Groups Projects
Commit 7a3143a3 authored by Andy Boughton's avatar Andy Boughton
Browse files

Merge pull request #131 from r-gaia-cs/core-check-required-files

Validator should check that required files exist
parents 3178d121 c89124ef
Branches
Tags
No related merge requests found
......@@ -668,6 +668,48 @@ def command_line():
return parser.parse_args()
def check_required_files(dir_to_validate):
"""Check if required files exists."""
REQUIRED_FILES = ["01-*.md",
"discussion.md",
"index.md",
"instructors.md",
"LICENSE.md",
"motivation.md",
"README.md",
"reference.md"]
valid = True
for required in REQUIRED_FILES:
req_fn = os.path.join(dir_to_validate, required)
if not glob.glob(req_fn):
logging.error(
"Missing file {0}.".format(required))
valid = False
return valid
def get_files_to_validate(file_or_path):
"""Generate list of files to validate."""
files_to_validate = []
dirs_to_validate = []
for fn in file_or_path:
if os.path.isdir(fn):
search_str = os.path.join(fn, "*.md")
files_to_validate.extend(glob.glob(search_str))
dirs_to_validate.append(fn)
elif os.path.isfile(fn):
files_to_validate.append(fn)
else:
logging.error(
"The specified file or folder {0} does not exist; "
"could not perform validation".format(fn))
return files_to_validate, dirs_to_validate
def main(parsed_args_obj):
if parsed_args_obj.debug:
log_level = "DEBUG"
......@@ -678,16 +720,16 @@ def main(parsed_args_obj):
template = parsed_args_obj.template
all_valid = True
for fn in parsed_args_obj.file_or_path:
if os.path.isdir(fn):
res = validate_folder(fn, template=template)
elif os.path.isfile(fn):
res = validate_single(fn, template=template)
else:
res = False
logging.error(
"The specified file or folder {0} does not exist; "
"could not perform validation".format(fn))
files_to_validate, dirs_to_validate = get_files_to_validate(
parsed_args_obj.file_or_path)
# If user ask to validate only one file don't check for required files.
for d in dirs_to_validate:
all_valid = all_valid and check_required_files(d)
for fn in files_to_validate:
res = validate_single(fn, template=template)
all_valid = all_valid and res
......
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