Skip to content

Instantly share code, notes, and snippets.

@t1anchen
Created May 30, 2014 13:06
Show Gist options
  • Save t1anchen/00670a71f3c2392a33b0 to your computer and use it in GitHub Desktop.
Save t1anchen/00670a71f3c2392a33b0 to your computer and use it in GitHub Desktop.
check manual yaml file and re-format it to formulized one
#!/usr/bin/python
import sys
import yaml
def main():
"""check.py: a simple tool to check yaml format
Usage: check.py <yaml_filename>
"""
mode = 'piped'
if len(sys.argv) == 3:
mode = 'file'
of_name = sys.argv[2]
if_name = sys.argv[1]
with open(if_name, 'r') as if_stream:
res = yaml.dump(yaml.load(if_stream), default_flow_style=False, allow_unicode=True)
if mode == 'file':
with open(of_name, 'wb') as of_stream:
of_stream.write(res)
else:
print res
main()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment