forked from run-x/opta
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rejigdirs.py
75 lines (58 loc) · 2.15 KB
/
rejigdirs.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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# type: ignore
import os
import shutil
allFilePaths = set([])
def make_valid_files_list(
ignoreDirs=[".git", "dist", "tests", "__pycache__", ".mypy_cache"]
):
for root, dirs, files in os.walk(".", topdown=False):
for name in files:
addToList = True
filePath = os.path.join(root, name)
for ignoreDir in ignoreDirs:
if ignoreDir + "/" in filePath:
addToList = False
break
if addToList:
allFilePaths.add(filePath)
def get_all_module_names():
modset = set([])
for root, dirs, files in os.walk("./config/registry"):
for name in files:
if name.endswith("yaml"):
modset.add(name.split(".yaml")[0])
return modset
def get_underscore_module_name(module_name):
rtn_val = module_name
if "-" in module_name:
rtn_val = "_".join(module_name.split("-"))
return rtn_val
def get_all_module_files(module_name):
moduleFiles = []
_module_name = module_name
if "-" in module_name:
_module_name = get_underscore_module_name(module_name)
for aFilePath in allFilePaths:
if module_name in aFilePath or _module_name in aFilePath:
moduleFiles.append(aFilePath)
return moduleFiles
def copy_over_files(aModule):
module_files = get_all_module_files(aModule)
targetDir = os.path.join("modules", get_underscore_module_name(aModule))
os.makedirs(targetDir, exist_ok=True)
for aPath in module_files:
tgt = targetDir
if "tf_modules" in aPath:
tgt = os.path.join(targetDir, "tf_module")
os.makedirs(tgt, exist_ok=True)
shutil.copy(aPath, os.path.join(tgt, os.path.basename(aPath)))
# Entrypoint
make_valid_files_list()
for aModule in get_all_module_names():
copy_over_files(aModule)
# Manual steps needed
# k8s-service tf to aws_k8s_service/ and rename to tf_module
# k8s-base to aws_k8s_base/ and rename to tf_module
# Copy opta-k8s-service-helm to modules/
# manually copy aws_document_db.py into modules/aws_documentdb.py and rename it
# manually copy base.py and custom_terraform.py into modules/