-
Notifications
You must be signed in to change notification settings - Fork 1
/
convert2newyaml.py
42 lines (33 loc) · 1.22 KB
/
convert2newyaml.py
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
import argparse
import os
import yaml
def convert(infile, outdir):
if outdir is None:
outdir = os.getcwd()
if not os.path.isdir(outdir):
os.mkdir(outdir)
inDict = dict()
sortedDict = {}
print("-- Loading file")
with open(infile, "r") as inyaml:
inDict = yaml.load(inyaml, Loader=yaml.SafeLoader)
print("-- Parsing keys")
for k, v in inDict.items():
keySplit = k.split("-")
newKey = keySplit[1] + ".DisConv_Blurb"
upkName = keySplit[0]
if upkName not in sortedDict:
sortedDict[upkName] = {}
sortedDict[upkName][newKey] = v
print("-- Writing to files")
for dk, dv in sortedDict.items():
path = os.path.join(outdir, (dk + ".yaml"))
yamlDict = dv
with open(path, "w", encoding="utf-8") as newYaml:
yaml.dump(yamlDict, newYaml, allow_unicode=True)
if __name__ == "__main__":
parser = argparse.ArgumentParser(description="Converts old yaml style to new (in this workspace)", epilog="May be unsused")
parser.add_argument("yamlfile", help="Input yaml file")
parser.add_argument("--output", help="Output dir")
args = parser.parse_args()
convert(args.yamlfile, args.output)