Skip to content

Instantly share code, notes, and snippets.

@markizano
Created October 5, 2022 11:33
Show Gist options
  • Save markizano/89b7bc9b81d1667a210a7ea34a458eb0 to your computer and use it in GitHub Desktop.
Save markizano/89b7bc9b81d1667a210a7ea34a458eb0 to your computer and use it in GitHub Desktop.
Walk a directory for files and do a lint check on loading up YAML configuration files.
#!/usr/bin/env python3
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.safe_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]))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment