-
Notifications
You must be signed in to change notification settings - Fork 4
Expand file tree
/
Copy pathyaml_split.py
More file actions
39 lines (28 loc) · 873 Bytes
/
Copy pathyaml_split.py
File metadata and controls
39 lines (28 loc) · 873 Bytes
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
import sys
import yaml
input_file = "File-Name.yaml"
def main(args):
with open(input_file, 'r') as read_stream:
try:
documents = yaml.safe_load_all(read_stream)
transform(documents)
except yaml.YAMLError as exc:
print(exc)
def transform(documents):
counter = 0
for document in documents:
file_name = get_name(document, counter)
counter = counter + 1
with open(file_name, 'w') as write_stream:
yaml.dump(document, write_stream)
def get_name(document, counter):
if counter < 10:
string_counter = "0" + str(counter)
else:
string_counter = str(counter)
name = string_counter + document["kind"] + "-" + document["metadata"]["name"] + ".yaml"
return name
def run():
sys.exit(main(sys.argv[1:]))
if __name__ == '__main__':
run()