Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #!/usr/bin/env python
- '''
- Usage: yamllint /path/to/lint
- Namely used for salt, but recursively checks a directory for files. For each file that ends with "sls" - check to ensure it can load using YAML. Print any files that have exceptions.
- Great as a pre-commit hook to any github project working on YAML-based files.
- '''
- import os
- import sys
- import yaml
- def main(target):
- if not os.path.isdir( target ):
- print('Could not walk %s. Target is not a directory or doesnt exist.' % target)
- return 1
- result = 0
- for rewt, dirs, files in os.walk( sys.argv[1] ):
- for file in files:
- if not file.endswith('sls'): continue
- try:
- with open(os.path.join(rewt, file)) as fd:
- yaml.load(fd)
- except Exception as e:
- print("Problem with %(rewt)s/%(file)s: %(e)s" % locals())
- result = 1
- return result
- sys.exit(main(sys.argv[1]))
Advertisement
Add Comment
Please, Sign In to add comment