-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
41 lines (31 loc) · 1.02 KB
/
main.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 sys
import argparse
from pathlib import Path
import ruamel.yaml
parser = argparse.ArgumentParser()
parser.add_argument("-i", "--input", help="input file in yaml format", required=True, type=argparse.FileType('r'))
parser.add_argument("-o", "--output", help="output file in yaml format, defaults to output.yaml", default="output.yaml", type=argparse.FileType('w'))
args = parser.parse_args()
in_file = args.input
out_file = args.output
yaml = ruamel.yaml.YAML()
yaml.indent(mapping=2, sequence=4, offset=2)
yaml.preserve_quotes = True
data = yaml.load(in_file)
delete = []
def rm_merge(d, s):
if isinstance(d, dict):
if s in d:
del d[s]
for k in list(d.keys()):
if str(k).find(s) != -1:
del d[k]
else:
rm_merge(d[k], s)
elif isinstance(d, list):
for item in d:
rm_merge(item, s)
rm_merge(data, 'application/ld+json')
rm_merge(data, 'application/merge-patch+json')
rm_merge(data, '.jsonld')
yaml.dump(data, out_file)