~smoser/cloud-init/lp-1077700

« back to all changes in this revision

Viewing changes to tools/validate-yaml.py

  • Committer: Joshua Harlow
  • Date: 2012-11-09 22:44:05 UTC
  • mfrom: (701.2.2 yaml-checking)
  • Revision ID: harlowja@yahoo-inc.com-20121109224405-7kdrz2axlw58zmrw
Merge the yaml/cloud config examples checking tool.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
#!/usr/bin/env python
 
2
 
 
3
"""Try to read a YAML file and report any errors.
 
4
"""
 
5
 
 
6
import sys
 
7
 
 
8
import yaml
 
9
 
 
10
 
 
11
if __name__ == "__main__":
 
12
    bads = 0
 
13
    for fn in sys.argv[1:]:
 
14
        sys.stdout.write("%s" % (fn))
 
15
        try:
 
16
            fh = open(fn, 'r')
 
17
            yaml.safe_load(fh.read())
 
18
            fh.close()
 
19
            sys.stdout.write(" - ok\n")
 
20
        except Exception, e:
 
21
            sys.stdout.write(" - bad (%s)\n" % (e))
 
22
            bads += 1
 
23
    if bads > 0:
 
24
        sys.exit(1)
 
25
    else:
 
26
        sys.exit(0)