bfbf1b8c9b
This patch adds a script for validating YAML files, and replaces the existing JSON checks with one largely identical to the YAML check. This also provides a script that can be installed as a pre-commit hook that will perform this checks when you commit changes. You can install the hook by running tools/pre-commit-hook --install. Change-Id: Ib4742a9db062362cfa61d669c691151bc1ca376c
34 lines
637 B
Python
Executable File
34 lines
637 B
Python
Executable File
#!/usr/bin/python
|
|
|
|
import os
|
|
import sys
|
|
import argparse
|
|
import yaml
|
|
import logging
|
|
|
|
def parse_args():
|
|
p = argparse.ArgumentParser()
|
|
p.add_argument('input', nargs='*')
|
|
return p.parse_args()
|
|
|
|
def main():
|
|
args = parse_args()
|
|
logging.basicConfig()
|
|
res = 0
|
|
|
|
for filename in args.input:
|
|
with open(filename) as fd:
|
|
try:
|
|
data = yaml.load(fd)
|
|
except yaml.error.YAMLError as error:
|
|
res = 1
|
|
logging.error('%s failed validation: %s',
|
|
filename, error)
|
|
|
|
sys.exit(res)
|
|
|
|
if __name__ == '__main__':
|
|
main()
|
|
|
|
|