def check_file(reporter, path, data): """ Get header from file, call all other functions, and check file for validity. """ # Get metadata as text and as YAML. raw, header, body = split_metadata(path, data) # Do we have any blank lines in the header? check_blank_lines(reporter, raw) # Look through all header entries. If the category is in the input # file and is either required or we have actual data (as opposed to # a commented-out entry), we check it. If it *isn't* in the header # but is required, report an error. for category in HANDLERS: required, handler, message = HANDLERS[category] if category in header: if required or header[category]: reporter.check(handler(header[category]), None, '{0}\n actual value "{1}"', message, header[category]) elif required: reporter.add(None, 'Missing mandatory key "{0}"', category) # Check whether we have missing or too many categories seen_categories = set(header.keys()) check_categories(reporter, REQUIRED, seen_categories, 'Missing categories') check_categories(reporter, seen_categories, REQUIRED.union(OPTIONAL), 'Superfluous categories')
def check_file(reporter, path, data): """ Get header from file, call all other functions, and check file for validity. """ # Get metadata as text and as YAML. raw, header, body = split_metadata(path, data) # Do we have any blank lines in the header? check_blank_lines(reporter, raw) # Look through all header entries. If the category is in the input # file and is either required or we have actual data (as opposed to # a commented-out entry), we check it. If it *isn't* in the header # but is required, report an error. for category in HANDLERS: required, handler, message = HANDLERS[category] if category in header: if required or header[category]: reporter.check(handler(header[category]), None, '{0}\n actual value "{1}"', message, header[category]) elif required: reporter.add(None, 'Missing mandatory key "{0}"', category) # Check whether we have missing or too many categories seen_categories = set(header.keys()) check_categories(reporter, REQUIRED, seen_categories, 'Missing categories') check_categories(reporter, seen_categories, REQUIRED.union(OPTIONAL), 'Superfluous categories')