-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathapplyvariability.py
More file actions
32 lines (26 loc) · 872 Bytes
/
applyvariability.py
File metadata and controls
32 lines (26 loc) · 872 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
import glob
import subprocess
import yaml
import os
import sys
if len(sys.argv) != 2:
print(f"Syntax: {sys.argv[0]} <descriptordirectory>", file=sys.stderr)
sys.exit(1)
with open("chartsubs.yaml") as f:
chartsubs = yaml.load(f)
descriptors = glob.glob(f"{sys.argv[1]}/*.yaml")
for descriptor in descriptors:
print("*", descriptor)
namecomps = os.path.basename(descriptor).split("-")
chartbase = ""
for namecomp in namecomps:
if namecomp[0].isdigit():
break
if chartbase:
chartbase += "-"
chartbase += namecomp
if chartbase in chartsubs:
for k, v in chartsubs[chartbase].items():
print("CHARTBASE", chartbase, k, v)
replacer = v.replace("\"", "\\\"")
p = subprocess.run(f"sed -i -e 's/{k}: \(.*\)/{k}: {replacer}/g' {descriptor}", shell=True)