From 7e40a6ed4ebbd77ca0cacbf3bb9b3eff9b8c781d Mon Sep 17 00:00:00 2001 From: Raniere Silva Date: Mon, 19 Jan 2015 00:46:36 -0200 Subject: [PATCH] Validator should check for required files --- tools/check.py | 58 +++++++++++++++++++++++++++++++++++++++++--------- 1 file changed, 48 insertions(+), 10 deletions(-) diff --git a/tools/check.py b/tools/check.py index dda03f8..f490302 100755 --- a/tools/check.py +++ b/tools/check.py @@ -667,6 +667,45 @@ 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 = [] + dir_to_validate = None + + 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)) + dir_to_validate = 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, dir_to_validate def main(parsed_args_obj): if parsed_args_obj.debug: @@ -678,16 +717,15 @@ 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, dir_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. + if dir_to_validate: + all_valid = all_valid and check_required_files(dir_to_validate) + + for fn in files_to_validate: + res = validate_single(fn, template=template) all_valid = all_valid and res -- GitLab