Created
April 9, 2015 09:29
-
-
Save jordiclariana/27282915850089067014 to your computer and use it in GitHub Desktop.
Simple yaml syntax checker
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/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