Skip to content

Instantly share code, notes, and snippets.

@jordiclariana
Created April 9, 2015 09:29
Show Gist options
  • Save jordiclariana/27282915850089067014 to your computer and use it in GitHub Desktop.
Save jordiclariana/27282915850089067014 to your computer and use it in GitHub Desktop.
Simple yaml syntax checker
#!/usr/bin/env python
import sys
from yaml import load, dump, error
try:
from yaml import CLoader as Loader, CDumper as Dumper
except ImportError:
from yaml import Loader, Dumper
if len(sys.argv) < 2:
print("No filename specified")
sys.exit(0)
try:
data = load(file(sys.argv[1], 'r') , Loader=Loader)
except error.YAMLError as exc:
message = '{} : {} {}'.format(type(exc).__name__, exc.problem, exc.context)
print(':{}:{}: {}\n'.format(exc.problem_mark.line, exc.problem_mark.column, message))
except IOError as exc:
print("{}".format(exc))
except Exception as exc:
print('uncaught exception - {} : {}'.format(type(exc), exc))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment