Created
May 30, 2014 13:06
-
-
Save t1anchen/00670a71f3c2392a33b0 to your computer and use it in GitHub Desktop.
check manual yaml file and re-format it to formulized one
This file contains hidden or 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/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