File size: 1,218 Bytes
2c17839
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
#!/usr/bin/env python
"""
Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
SPDX-License-Identifier: MIT-0
"""

import fnmatch
import json
import os

import cfnlint
from cfnlint.helpers import format_json_string

modules = [
    "AdditionalSpecs",
    "CfnLintCli",
    "Serverless",
    "schemas",
]

for module in modules:
    append_dir = os.path.join(
        os.path.dirname(cfnlint.__file__),
        "data",
        module,
    )
    for dirpath, _, filenames in os.walk(append_dir):
        for filename in fnmatch.filter(filenames, "*.json"):
            try:
                string_content = ""
                with open(
                    os.path.join(dirpath, filename), encoding="utf8"
                ) as input_file:
                    string_content = "".join(input_file.readlines())

                pretty_content = format_json_string(json.loads(string_content))
                with open(
                    os.path.join(dirpath, filename), encoding="utf8", mode="w"
                ) as output_file:
                    output_file.write(pretty_content)
                    output_file.write("\n")
            except Exception as e:
                print(dirpath, filename, e)