File: validate-yaml.py

package info (click to toggle)
cloud-init 25.3-2
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 12,412 kB
  • sloc: python: 135,894; sh: 3,883; makefile: 141; javascript: 30; xml: 22
file content (24 lines) | stat: -rwxr-xr-x 543 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/env python3

"""Try to read a YAML file and report any errors."""

import sys
import yaml


if __name__ == "__main__":
    bads = 0
    for fn in sys.argv[1:]:
        sys.stdout.write("%s" % (fn))
        try:
            fh = open(fn, "rb")
            yaml.safe_load(fh.read().decode("utf-8"))
            fh.close()
            sys.stdout.write(" - ok\n")
        except Exception as e:
            sys.stdout.write(" - bad (%s)\n" % (e))
            bads += 1
    if bads > 0:
        sys.exit(1)
    else:
        sys.exit(0)