git.schokokeks.org
Repositories
Help
Report an Issue
fs-draft.git
Code
Commits
Branches
Tags
Suche
Strukturansicht:
18080c6
Branches
Tags
master
midgard
vorlage
fs-draft.git
genmake.py
foo
fenris
commited
18080c6
at 2016-04-24 18:00:07
genmake.py
Blame
History
Raw
import os import sys class class_rule(object): def __init__(self, name, dependencies, commands, phony = False): self.name = name self.dependencies = dependencies self.commands = commands self.phony = phony def __str__(self): output = "" output += "%s: %s\n" % (self.name, " ".join(self.dependencies)) for command in self.commands: output += ("\t@ %s\n" % (command.compile_unix())) if (self.phony): output += (".PHONY: %s\n" % self.name) return output class class_command(object): def __init__(self, parameters): self.parameters = parameters def compile_unix(self): raise NotImplementedError def compile_ant(self): raise NotImplementedError class class_command_log(class_command): def __init__(self, parameters): class_command.__init__(self, parameters) def compile_unix(self): return ("echo -e '-- %s'" % (self.parameters["message"])) class class_command_directory_create(class_command): def __init__(self, parameters): class_command.__init__(self, parameters) def compile_unix(self): return ("mkdir --parents %s" % (self.parameters["path"])) class class_command_file_copy(class_command): def __init__(self, parameters): class_command.__init__(self, parameters) def compile_unix(self): return ("cp --recursive %s %s" % (self.parameters["path-from"], self.parameters["path-to"])) class class_command_file_concat(class_command): def __init__(self, parameters): class_command.__init__(self, parameters) def compile_unix(self): return ("cat %s > %s" % (" ".join(self.parameters["paths-from"]), self.parameters["path-to"])) class class_command_directory_remove(class_command): def __init__(self, parameters): class_command.__init__(self, parameters) def compile_unix(self): return ("rm --recursive --force %s" % (self.parameters["path"])) class class_command_image_convert(class_command): def __init__(self, parameters): class_command.__init__(self, parameters) def compile_unix(self): return ("convert %s %s" % (self.parameters["path-from"], self.parameters["path-to"])) class class_command_latex_compile(class_command): def __init__(self, parameters): class_command.__init__(self, parameters) def compile_unix(self): return ("xelatex -output-directory=%s %s > /dev/null" % (self.parameters["output"], self.parameters["path"])) class class_command_php_compile(class_command): def __init__(self, parameters): class_command.__init__(self, parameters) def compile_unix(self): return ("php %s > %s" % (self.parameters["path-from"], self.parameters["path-to"])) class class_command_lessc_compile(class_command): def __init__(self, parameters): class_command.__init__(self, parameters) def compile_unix(self): return ("lessc %s > %s" % (self.parameters["path-from"], self.parameters["path-to"])) def main(): dirs = { "source": "source", "temp": "temp", "build": "build", } parts_data = [ os.path.join(dirs["source"],"data","phonology_and_orthography.json"), os.path.join(dirs["source"],"data","personal_pronouns.json"), os.path.join(dirs["source"],"data","word_functions.json"), os.path.join(dirs["source"],"data","timeforms.json"), ] parts_logic = [ os.path.join(dirs["source"],"logic","server","misc.php"), os.path.join(dirs["source"],"logic","server","data.php"), os.path.join(dirs["source"],"logic","server","settings.php"), os.path.join(dirs["source"],"logic","server","table.php"), ] parts_structure = [ os.path.join(dirs["source"],"structure","draft.html.php"), os.path.join(dirs["source"],"structure","meta.html.php"), os.path.join(dirs["source"],"structure","introduction.html.php"), os.path.join(dirs["source"],"structure","preface.html.php"), os.path.join(dirs["source"],"structure","key_parameters.html.php"), os.path.join(dirs["source"],"structure","toc.html.php"), os.path.join(dirs["source"],"structure","grammar.html.php"), os.path.join(dirs["source"],"structure","phonology_and_orthography.html.php"), os.path.join(dirs["source"],"structure","pronouns.html.php"), os.path.join(dirs["source"],"structure","personal_pronouns.html.php"), os.path.join(dirs["source"],"structure","correlatives.html.php"), os.path.join(dirs["source"],"structure","conjugation.html.php"), os.path.join(dirs["source"],"structure","declension.html.php"), os.path.join(dirs["source"],"structure","attributes.html.php"), os.path.join(dirs["source"],"structure","sentence_structure.html.php"), os.path.join(dirs["source"],"structure","word_functions.html.php"), os.path.join(dirs["source"],"structure","vocabulary.html.php"), ] rules = [] rules.append( class_rule( "all", [ os.path.join(dirs["build"],"draft.html"), os.path.join(dirs["build"],"draft.css"), os.path.join(dirs["build"],"draft.js"), os.path.join(dirs["build"],"logo.svg"), os.path.join(dirs["build"],"favicon.png"), ], [], True ) ) rules.append( class_rule( "clean", [], [ class_command_directory_remove({ "path": dirs["temp"], }), ], True ) ) rules.append( class_rule( "clear", ["clean"], [ class_command_directory_remove({ "path": dirs["build"], }), ], True ) ) rules.append( class_rule( os.path.join(dirs["build"],"draft.html"), parts_data + parts_logic + parts_structure, [ class_command_log({ "message": "compiling document ..." }), class_command_directory_create({ "path": dirs["build"], }), class_command_php_compile({ "path-from": os.path.join(dirs["source"],"structure","draft.html.php"), "path-to": os.path.join(dirs["build"],"draft.html"), }), ] ) ) rules.append( class_rule( os.path.join(dirs["build"],"draft.js"), [os.path.join(dirs["source"],"logic","client","draft.js")], [ class_command_log({ "message": "copying client-logic ..." }), class_command_directory_create({ "path": dirs["build"], }), class_command_file_copy({ "path-from": os.path.join(dirs["source"],"logic","client","draft.js"), "path-to": os.path.join(dirs["build"],"draft.js"), }), ] ) ) rules.append( class_rule( os.path.join(dirs["build"],"logo.svg"), [os.path.join(dirs["source"],"media","logo.svg")], [ class_command_log({ "message": "copying logo ..." }), class_command_directory_create({ "path": dirs["build"], }), class_command_file_copy({ "path-from": os.path.join(dirs["source"],"media","logo.svg"), "path-to": os.path.join(dirs["build"],"logo.svg"), }), ] ) ) rules.append( class_rule( os.path.join(dirs["build"],"favicon.png"), [os.path.join(dirs["source"],"media","folksprak_16x16.png")], [ class_command_log({ "message": "copying favicon ..." }), class_command_directory_create({ "path": dirs["build"], }), class_command_file_copy({ "path-from": os.path.join(dirs["source"],"media","folksprak_16x16.png"), "path-to": os.path.join(dirs["build"],"favicon.png"), }), ] ) ) rules.append( class_rule( os.path.join(dirs["build"],"draft.css"), [os.path.join(dirs["source"],"style","common.less"), os.path.join(dirs["source"],"style","concrete.less")], [ class_command_log({ "message": "compiling style ..." }), class_command_directory_create({ "path": os.path.join(dirs["temp"]), }), class_command_file_concat({ "paths-from": [os.path.join(dirs["source"],"style","common.less"), os.path.join(dirs["source"],"style","concrete.less")], "path-to": os.path.join(dirs["temp"],"draft.less"), }), class_command_directory_create({ "path": os.path.join(dirs["build"]), }), class_command_lessc_compile({ "path-from": os.path.join(dirs["temp"],"draft.less"), "path-to": os.path.join(dirs["build"],"draft.css"), }), ] ) ) for rule in rules: print(rule) sys.stderr.write("\n[information]\tThe output of this script is meant to be redirected into a GNU-makefile\n") main()