-
Notifications
You must be signed in to change notification settings - Fork 0
/
quick-start-templater.py
64 lines (47 loc) · 2.05 KB
/
quick-start-templater.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
import sys
import re
import glob
distro=sys.argv[1]
distro_id=sys.argv[2]
def get_step_function_name(step_path):
path_parts = step_path.split("/")
return path_parts[-1].replace("-", "_")
def load_custom_installation_steps():
custom_steps = glob.glob("distros/{distro}/steps/*".format(distro=distro))
steps = {}
for step_path in custom_steps:
step_name = get_step_function_name(step_path)
steps[step_name] = step_path
return steps
def load_prerequisites_paths():
return [
"distros/{distro}/steps/core-prerequisites".format(distro = distro),
"distros/{distro}/steps/extension-prerequisites".format(distro = distro)
]
def parse_prerequesite(path, function_name):
prerequisite_content = []
with open(path) as prerequisites_file:
prerequisite_content = prerequisites_file.readlines()
parsed_content=[ "{name}(){{\n".format(name=function_name) ]
if re.search("^#!", prerequisite_content[0]):
prerequisite_content.pop(0)
for content_line in prerequisite_content:
command_line = content_line
if re.search("^sudo ", content_line): # is chaning user
command_line = content_line[5:]
parsed_content.append( " " + command_line)
parsed_content.append("}\n")
return parsed_content
def generate_prerequisites():
prerequisites_steps = load_custom_installation_steps()
prerequisite_script = [ "#!/bin/sh\n" ]
for function_name, prerequisite_path in prerequisites_steps.items():
parsed_prerequisite = parse_prerequesite(prerequisite_path, function_name)
prerequisite_script = prerequisite_script + parsed_prerequisite
return prerequisite_script
def write_prerequisites(prerequisites):
pre_requesite_script_path = "output/quickinstall/prerequisites/{distro_id}".format(distro=distro, distro_id=distro_id)
with open(pre_requesite_script_path, 'w') as output_file:
output_file.writelines(prerequisites)
prerequisites = generate_prerequisites()
write_prerequisites(prerequisites)