9b21fc2c149922fab59041d1c4ac3afd213c2deb
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 Wolf advanced

Fenris Wolf authored 8 years ago

76) 		os.path.join(dirs["source"],"logic","server","settings.php"),
77) 		os.path.join(dirs["source"],"structure","draft.html.php"),
78) 		os.path.join(dirs["source"],"structure","meta.html.php"),
79) 		os.path.join(dirs["source"],"structure","preface.html.php"),
80) 		os.path.join(dirs["source"],"structure","grammar.html.php"),
81) 		os.path.join(dirs["source"],"structure","phonology_and_orthography.html.php"),
82) 		os.path.join(dirs["source"],"structure","pronouns.html.php"),
83) 		os.path.join(dirs["source"],"structure","personal_pronouns.html.php"),
84) 		os.path.join(dirs["source"],"structure","correlatives.html.php"),
85) 		os.path.join(dirs["source"],"structure","conjugation.html.php"),
86) 		os.path.join(dirs["source"],"structure","declension.html.php"),
87) 		os.path.join(dirs["source"],"structure","attributes.html.php"),
88) 		os.path.join(dirs["source"],"structure","vocabulary.html.php"),
fenris build-system

fenris authored 8 years ago

89) 	]
90) 	
91) 	rules = []
92) 	rules.append(
93) 		class_rule(
94) 			"all",
fenris moved to html

fenris authored 8 years ago

95) 			[
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

96) 				os.path.join(dirs["build"],"draft.html"),
97) 				os.path.join(dirs["build"],"draft.css"),
fenris moved to html

fenris authored 8 years ago

98) 				os.path.join(dirs["build"],"logo.svg"),
99) 			],
fenris build-system

fenris authored 8 years ago

100) 			[],
101) 			True
102) 		)
103) 	)
104) 	rules.append(
105) 		class_rule(
106) 			"clean",
107) 			[],
108) 			[
109) 				class_command_directory_remove({
110) 					"path": dirs["temp"],
111) 				}),
112) 			],
113) 			True
114) 		)
115) 	)
116) 	rules.append(
117) 		class_rule(
118) 			"clear",
119) 			["clean"],
120) 			[
121) 				class_command_directory_remove({
122) 					"path": dirs["build"],
123) 				}),
124) 			],
125) 			True
126) 		)
127) 	)
128) 	rules.append(
129) 		class_rule(
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

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

fenris authored 8 years ago

131) 			texs,
fenris build-system

fenris authored 8 years ago

132) 			[
133) 				class_command_log({
fenris moved to html

fenris authored 8 years ago

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

fenris authored 8 years ago

135) 				}),
136) 				class_command_directory_create({
fenris moved to html

fenris authored 8 years ago

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

fenris authored 8 years ago

138) 				}),
fenris moved to html

fenris authored 8 years ago

139) 				class_command_php_compile({
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

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

fenris authored 8 years ago

142) 				}),
143) 			]
144) 		)
145) 	)
146) 	rules.append(
147) 		class_rule(
fenris moved to html

fenris authored 8 years ago

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

fenris authored 8 years ago

150) 			[
151) 				class_command_log({
fenris moved to html

fenris authored 8 years ago

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

fenris authored 8 years ago

153) 				}),
154) 				class_command_directory_create({
fenris moved to html

fenris authored 8 years ago

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

fenris authored 8 years ago

156) 				}),
fenris moved to html

fenris authored 8 years ago

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

fenris authored 8 years ago

160) 				}),
161) 			]
162) 		)
163) 	)
164) 	rules.append(
165) 		class_rule(
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

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

fenris authored 8 years ago

168) 			[
fenris moved to html

fenris authored 8 years ago

169) 				class_command_log({
170) 					"message": "compiling style ..."
171) 				}),
172) 				class_command_directory_create({
173) 					"path": os.path.join(dirs["temp"]),
174) 				}),
175) 				class_command_file_concat({
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

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

fenris authored 8 years ago

178) 				}),
fenris build-system

fenris authored 8 years ago

179) 				class_command_directory_create({
180) 					"path": os.path.join(dirs["build"]),
181) 				}),
fenris moved to html

fenris authored 8 years ago

182) 				class_command_lessc_compile({
Fenris Wolf advanced

Fenris Wolf authored 8 years ago

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