-
Notifications
You must be signed in to change notification settings - Fork 0
/
template.py
44 lines (33 loc) · 1.24 KB
/
template.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
import os
from string import Template
def getTextFromTemplateFile(file, vars):
# open the file
filein = open(file)
# read it
src = Template(filein.read())
# do the substitution
result = src.substitute(vars)
# result = cf.format(src, title=title, subtitle=sibtitle, list=list)
# print(result)
return result
def createFileFromTemplate(newfile, template, vars):
text = getTextFromTemplateFile(template, vars)
createFile(newfile, text)
def createFile(file, text):
file = open(file, "w")
file.write(text)
file.close()
def envTemplate(Env):
os_ext_script = 'sh'
script = Env.command + '.' + os_ext_script
template = os.path.join('environment', Env.name, script + '.$')
scriptpath = os.path.join('environment', Env.name, script)
createFileFromTemplate(scriptpath, template, {'folder': Env.folder})
return scriptpath
def sourcecodeTemplate(Env):
os_ext_script = 'sh'
script = Env.command + '.' + os_ext_script
template = os.path.join('environment', Env.name, script + '.$')
scriptpath = os.path.join('environment', Env.name, script)
createFileFromTemplate(scriptpath, template, {'domain': Env.domain, 'folder': Env.folder, 'github': Env.github})
return scriptpath