18080c63cada1df8fd6e8eda7bb06c367e016975
fenris build-system

fenris authored 8 years ago

1) import os
2) import sys
3) 
4) 
5) class class_rule(object):
6) 	
7) 	def __init__(self, name, dependencies, commands, phony = False):
8) 		self.name = name
9) 		self.dependencies = dependencies
10) 		self.commands = commands
11) 		self.phony = phony
12) 		
13) 	
14) 	def __str__(self):
15) 		output = ""
16) 		output += "%s: %s\n" % (self.name, " ".join(self.dependencies))
17) 		for command in self.commands:
18) 			output += ("\t@ %s\n" % (command.compile_unix()))
19) 		if (self.phony): output += (".PHONY: %s\n" % self.name)
20) 		return output
21) 		
22) 	
23) 
24) class class_command(object):
25) 	def __init__(self, parameters): self.parameters = parameters
26) 	def compile_unix(self): raise NotImplementedError
27) 	def compile_ant(self): raise NotImplementedError
28) 
29) class class_command_log(class_command):
30) 	def __init__(self, parameters): class_command.__init__(self, parameters)
31) 	def compile_unix(self): return ("echo -e '-- %s'" % (self.parameters["message"]))
32) 
33) class class_command_directory_create(class_command):
34) 	def __init__(self, parameters): class_command.__init__(self, parameters)
35) 	def compile_unix(self): return ("mkdir --parents %s" % (self.parameters["path"]))
36) 
37) class class_command_file_copy(class_command):
38) 	def __init__(self, parameters): class_command.__init__(self, parameters)
39) 	def compile_unix(self): return ("cp --recursive %s %s" % (self.parameters["path-from"], self.parameters["path-to"]))
40) 
fenris moved to html

fenris authored 8 years ago

41) class class_command_file_concat(class_command):
42) 	def __init__(self, parameters): class_command.__init__(self, parameters)
43) 	def compile_unix(self): return ("cat %s > %s" % (" ".join(self.parameters["paths-from"]), self.parameters["path-to"]))
44) 
fenris build-system

fenris authored 8 years ago

45) class class_command_directory_remove(class_command):
46) 	def __init__(self, parameters): class_command.__init__(self, parameters)
47) 	def compile_unix(self): return ("rm --recursive --force %s" % (self.parameters["path"]))
48) 
49) class class_command_image_convert(class_command):
50) 	def __init__(self, parameters): class_command.__init__(self, parameters)
51) 	def compile_unix(self): return ("convert %s %s" % (self.parameters["path-from"], self.parameters["path-to"]))
52) 
53) class class_command_latex_compile(class_command):
54) 	def __init__(self, parameters): class_command.__init__(self, parameters)
55) 	def compile_unix(self): return ("xelatex -output-directory=%s %s > /dev/null" % (self.parameters["output"], self.parameters["path"]))
56) 
fenris moved to html

fenris authored 8 years ago

57) class class_command_php_compile(class_command):
58) 	def __init__(self, parameters): class_command.__init__(self, parameters)
59) 	def compile_unix(self): return ("php %s > %s" % (self.parameters["path-from"], self.parameters["path-to"]))
60) 
61) class class_command_lessc_compile(class_command):
62) 	def __init__(self, parameters): class_command.__init__(self, parameters)
63) 	def compile_unix(self): return ("lessc %s > %s" % (self.parameters["path-from"], self.parameters["path-to"]))
64) 
fenris build-system

fenris authored 8 years ago

65) 
66) 
67) def main():
68) 	
69) 	dirs = {
70) 		"source": "source",
71) 		"temp": "temp",
72) 		"build": "build",
73) 	}
74) 	
fenris advanced

fenris authored 8 years ago

75) 	parts_data = [
76) 		os.path.join(dirs["source"],"data","phonology_and_orthography.json"),
77) 		os.path.join(dirs["source"],"data","personal_pronouns.json"),
fenris foo

fenris authored 8 years ago

78) 		os.path.join(dirs["source"],"data","word_functions.json"),
79) 		os.path.join(dirs["source"],"data","timeforms.json"),
fenris advanced

fenris authored 8 years ago

80) 	]
81) 	
82) 	parts_logic = [
fenris foo

fenris authored 8 years ago

83) 		os.path.join(dirs["source"],"logic","server","misc.php"),
fenris advanced

fenris authored 8 years ago

84) 		os.path.join(dirs["source"],"logic","server","data.php"),
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

85) 		os.path.join(dirs["source"],"logic","server","settings.php"),
fenris foo

fenris authored 8 years ago

86) 		os.path.join(dirs["source"],"logic","server","table.php"),
fenris advanced

fenris authored 8 years ago

87) 	]
88) 	
89) 	parts_structure = [
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

90) 		os.path.join(dirs["source"],"structure","draft.html.php"),
91) 		os.path.join(dirs["source"],"structure","meta.html.php"),
fenris advanced

fenris authored 8 years ago

92) 		os.path.join(dirs["source"],"structure","introduction.html.php"),
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

93) 		os.path.join(dirs["source"],"structure","preface.html.php"),
fenris foo

fenris authored 8 years ago

94) 		os.path.join(dirs["source"],"structure","key_parameters.html.php"),
95) 		os.path.join(dirs["source"],"structure","toc.html.php"),
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

96) 		os.path.join(dirs["source"],"structure","grammar.html.php"),
97) 		os.path.join(dirs["source"],"structure","phonology_and_orthography.html.php"),
98) 		os.path.join(dirs["source"],"structure","pronouns.html.php"),
99) 		os.path.join(dirs["source"],"structure","personal_pronouns.html.php"),
100) 		os.path.join(dirs["source"],"structure","correlatives.html.php"),
101) 		os.path.join(dirs["source"],"structure","conjugation.html.php"),
102) 		os.path.join(dirs["source"],"structure","declension.html.php"),
103) 		os.path.join(dirs["source"],"structure","attributes.html.php"),
fenris advanced

fenris authored 8 years ago

104) 		os.path.join(dirs["source"],"structure","sentence_structure.html.php"),
fenris foo

fenris authored 8 years ago

105) 		os.path.join(dirs["source"],"structure","word_functions.html.php"),
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

106) 		os.path.join(dirs["source"],"structure","vocabulary.html.php"),
fenris build-system

fenris authored 8 years ago

107) 	]
108) 	
109) 	rules = []
110) 	rules.append(
111) 		class_rule(
112) 			"all",
fenris moved to html

fenris authored 8 years ago

113) 			[
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

114) 				os.path.join(dirs["build"],"draft.html"),
115) 				os.path.join(dirs["build"],"draft.css"),
fenris advanced

fenris authored 8 years ago

116) 				os.path.join(dirs["build"],"draft.js"),
fenris moved to html

fenris authored 8 years ago

117) 				os.path.join(dirs["build"],"logo.svg"),
fenris foo

fenris authored 8 years ago

118) 				os.path.join(dirs["build"],"favicon.png"),
fenris moved to html

fenris authored 8 years ago

119) 			],
fenris build-system

fenris authored 8 years ago

120) 			[],
121) 			True
122) 		)
123) 	)
124) 	rules.append(
125) 		class_rule(
126) 			"clean",
127) 			[],
128) 			[
129) 				class_command_directory_remove({
130) 					"path": dirs["temp"],
131) 				}),
132) 			],
133) 			True
134) 		)
135) 	)
136) 	rules.append(
137) 		class_rule(
138) 			"clear",
139) 			["clean"],
140) 			[
141) 				class_command_directory_remove({
142) 					"path": dirs["build"],
143) 				}),
144) 			],
145) 			True
146) 		)
147) 	)
148) 	rules.append(
149) 		class_rule(
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

150) 			os.path.join(dirs["build"],"draft.html"),
fenris advanced

fenris authored 8 years ago

151) 			parts_data + parts_logic + parts_structure,
fenris build-system

fenris authored 8 years ago

152) 			[
153) 				class_command_log({
fenris moved to html

fenris authored 8 years ago

154) 					"message": "compiling document ..."
fenris build-system

fenris authored 8 years ago

155) 				}),
156) 				class_command_directory_create({
fenris moved to html

fenris authored 8 years ago

157) 					"path": dirs["build"],
fenris build-system

fenris authored 8 years ago

158) 				}),
fenris moved to html

fenris authored 8 years ago

159) 				class_command_php_compile({
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

160) 					"path-from": os.path.join(dirs["source"],"structure","draft.html.php"),
161) 					"path-to": os.path.join(dirs["build"],"draft.html"),
fenris build-system

fenris authored 8 years ago

162) 				}),
163) 			]
164) 		)
165) 	)
fenris advanced

fenris authored 8 years ago

166) 	rules.append(
167) 		class_rule(
168) 			os.path.join(dirs["build"],"draft.js"),
169) 			[os.path.join(dirs["source"],"logic","client","draft.js")],
170) 			[
171) 				class_command_log({
172) 					"message": "copying client-logic ..."
173) 				}),
174) 				class_command_directory_create({
175) 					"path": dirs["build"],
176) 				}),
177) 				class_command_file_copy({
178) 					"path-from": os.path.join(dirs["source"],"logic","client","draft.js"),
179) 					"path-to": os.path.join(dirs["build"],"draft.js"),
180) 				}),
181) 			]
182) 		)
183) 	)
fenris build-system

fenris authored 8 years ago

184) 	rules.append(
185) 		class_rule(
fenris moved to html

fenris authored 8 years ago

186) 			os.path.join(dirs["build"],"logo.svg"),
187) 			[os.path.join(dirs["source"],"media","logo.svg")],
fenris build-system

fenris authored 8 years ago

188) 			[
189) 				class_command_log({
fenris moved to html

fenris authored 8 years ago

190) 					"message": "copying logo ..."
fenris build-system

fenris authored 8 years ago

191) 				}),
192) 				class_command_directory_create({
fenris moved to html

fenris authored 8 years ago

193) 					"path": dirs["build"],
fenris build-system

fenris authored 8 years ago

194) 				}),
fenris moved to html

fenris authored 8 years ago

195) 				class_command_file_copy({
196) 					"path-from": os.path.join(dirs["source"],"media","logo.svg"),
197) 					"path-to": os.path.join(dirs["build"],"logo.svg"),
fenris build-system

fenris authored 8 years ago

198) 				}),
199) 			]
200) 		)
201) 	)
fenris foo

fenris authored 8 years ago

202) 	rules.append(
203) 		class_rule(
204) 			os.path.join(dirs["build"],"favicon.png"),
205) 			[os.path.join(dirs["source"],"media","folksprak_16x16.png")],
206) 			[
207) 				class_command_log({
208) 					"message": "copying favicon ..."
209) 				}),
210) 				class_command_directory_create({
211) 					"path": dirs["build"],
212) 				}),
213) 				class_command_file_copy({
214) 					"path-from": os.path.join(dirs["source"],"media","folksprak_16x16.png"),
215) 					"path-to": os.path.join(dirs["build"],"favicon.png"),
216) 				}),
217) 			]
218) 		)
219) 	)
fenris build-system

fenris authored 8 years ago

220) 	rules.append(
221) 		class_rule(
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

222) 			os.path.join(dirs["build"],"draft.css"),
223) 			[os.path.join(dirs["source"],"style","common.less"), os.path.join(dirs["source"],"style","concrete.less")],
fenris build-system

fenris authored 8 years ago

224) 			[
fenris moved to html

fenris authored 8 years ago

225) 				class_command_log({
226) 					"message": "compiling style ..."
227) 				}),
228) 				class_command_directory_create({
229) 					"path": os.path.join(dirs["temp"]),
230) 				}),
231) 				class_command_file_concat({
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

232) 					"paths-from": [os.path.join(dirs["source"],"style","common.less"), os.path.join(dirs["source"],"style","concrete.less")],
233) 					"path-to": os.path.join(dirs["temp"],"draft.less"),
fenris moved to html

fenris authored 8 years ago

234) 				}),
fenris build-system

fenris authored 8 years ago

235) 				class_command_directory_create({
236) 					"path": os.path.join(dirs["build"]),
237) 				}),
fenris moved to html

fenris authored 8 years ago

238) 				class_command_lessc_compile({
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

239) 					"path-from": os.path.join(dirs["temp"],"draft.less"),
240) 					"path-to": os.path.join(dirs["build"],"draft.css"),