a8c049f80f8f2c54ca9f9facf4c79234c7347a1f
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) 	
75) 	texs = [
fenris moved to html

fenris authored 8 years ago

76) 		os.path.join(dirs["source"],"html.php","folksprak.html.php"),
77) 		os.path.join(dirs["source"],"html.php","meta.html.php"),
78) 		os.path.join(dirs["source"],"html.php","preface.html.php"),
79) 		os.path.join(dirs["source"],"html.php","grammar.html.php"),
80) 		os.path.join(dirs["source"],"html.php","phonology_and_orthography.html.php"),
81) 		os.path.join(dirs["source"],"html.php","pronouns.html.php"),
82) 		os.path.join(dirs["source"],"html.php","conjugation.html.php"),
83) 		os.path.join(dirs["source"],"html.php","declension.html.php"),
84) 		os.path.join(dirs["source"],"html.php","attributes.html.php"),
fenris build-system

fenris authored 8 years ago

85) 	]
86) 	
87) 	rules = []
88) 	rules.append(
89) 		class_rule(
90) 			"all",
fenris moved to html

fenris authored 8 years ago

91) 			[
92) 				os.path.join(dirs["build"],"folksprak.html"),
93) 				os.path.join(dirs["build"],"folksprak.css"),
94) 				os.path.join(dirs["build"],"logo.svg"),
95) 			],
fenris build-system

fenris authored 8 years ago

96) 			[],
97) 			True
98) 		)
99) 	)
100) 	rules.append(
101) 		class_rule(
102) 			"clean",
103) 			[],
104) 			[
105) 				class_command_directory_remove({
106) 					"path": dirs["temp"],
107) 				}),
108) 			],
109) 			True
110) 		)
111) 	)
112) 	rules.append(
113) 		class_rule(
114) 			"clear",
115) 			["clean"],
116) 			[
117) 				class_command_directory_remove({
118) 					"path": dirs["build"],
119) 				}),
120) 			],
121) 			True
122) 		)
123) 	)
124) 	rules.append(
125) 		class_rule(
fenris moved to html

fenris authored 8 years ago

126) 			os.path.join(dirs["build"],"folksprak.html"),
127) 			texs,
fenris build-system

fenris authored 8 years ago

128) 			[
129) 				class_command_log({
fenris moved to html

fenris authored 8 years ago

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

fenris authored 8 years ago

131) 				}),
132) 				class_command_directory_create({
fenris moved to html

fenris authored 8 years ago

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

fenris authored 8 years ago

134) 				}),
fenris moved to html

fenris authored 8 years ago

135) 				class_command_php_compile({
136) 					"path-from": os.path.join(dirs["source"],"html.php","folksprak.html.php"),
137) 					"path-to": os.path.join(dirs["build"],"folksprak.html"),
fenris build-system

fenris authored 8 years ago

138) 				}),
139) 			]
140) 		)
141) 	)
142) 	rules.append(
143) 		class_rule(
fenris moved to html

fenris authored 8 years ago

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

fenris authored 8 years ago

146) 			[
147) 				class_command_log({
fenris moved to html

fenris authored 8 years ago

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

fenris authored 8 years ago

149) 				}),
150) 				class_command_directory_create({
fenris moved to html

fenris authored 8 years ago

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

fenris authored 8 years ago

152) 				}),
fenris moved to html

fenris authored 8 years ago

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

fenris authored 8 years ago

156) 				}),
157) 			]
158) 		)
159) 	)
160) 	rules.append(
161) 		class_rule(
fenris moved to html

fenris authored 8 years ago

162) 			os.path.join(dirs["build"],"folksprak.css"),
163) 			[os.path.join(dirs["source"],"less","common.less"), os.path.join(dirs["source"],"less","concrete.less")],
fenris build-system

fenris authored 8 years ago

164) 			[
fenris moved to html

fenris authored 8 years ago

165) 				class_command_log({
166) 					"message": "compiling style ..."
167) 				}),
168) 				class_command_directory_create({
169) 					"path": os.path.join(dirs["temp"]),
170) 				}),
171) 				class_command_file_concat({
172) 					"paths-from": [os.path.join(dirs["source"],"less","common.less"), os.path.join(dirs["source"],"less","concrete.less")],
173) 					"path-to": os.path.join(dirs["temp"],"folksprak.less"),
174) 				}),
fenris build-system

fenris authored 8 years ago

175) 				class_command_directory_create({
176) 					"path": os.path.join(dirs["build"]),
177) 				}),
fenris moved to html

fenris authored 8 years ago

178) 				class_command_lessc_compile({
179) 					"path-from": os.path.join(dirs["temp"],"folksprak.less"),
180) 					"path-to": os.path.join(dirs["build"],"folksprak.css"),