X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=webber.py;h=687e182fa89b93b70bf5c96e5606d2b52144e9ef;hb=8723ab9b1ad7ede65752c1a8325d129690100a08;hp=80a4d61b4cb81f8f477f15bbcfd0c4899f31df87;hpb=9c266b6b4b213f7571c7b92e9eb9623cb31cf10e;p=webber.git diff --git a/webber.py b/webber.py index 80a4d61..687e182 100644 --- a/webber.py +++ b/webber.py @@ -11,21 +11,21 @@ from config import Holder __all__ = [ # Globals - "cfg", # configuration from webber.ini - "directories", # global hash of directories, by rel_path - "files", # global hash of files, by rel_path - "functions", # all exported template functions + "cfg", # configuration from webber.ini + "directories", # global hash of directories, by rel_path + "files", # global hash of files, by rel_path + "functions", # all exported template functions # Functions - "set_hook", # decorator for hook-functions - "set_macro", # define macro + "set_hook", # decorator for hook-functions + "set_macro", # define macro "set_function", # define functions for the template "get_file_for", "get_link_from", "get_current_file", # because mako-called functions cannot access the - # current File object + # current File object "get_program_directory", - "log", # misc logging functions + "log", # misc logging functions "info", "warning", "error", @@ -50,7 +50,15 @@ class Directory(Holder): def __init__(self, **kw): Holder.__init__(self, **kw) - directories[kw["rel_path"]] = self + kw["rel_path"] = self + if self.rel_path == "": + self.rel_path = "." + directories[self.rel_path] = self + try: + self.load(os.path.join(self.abs_path, "directory.conf")) + #print self + except IOError: + pass files = {} @@ -217,7 +225,7 @@ def get_link_from(source, dest): if not isinstance(dest, File): dest = get_file_for(dest) if not dest: - print "NO DEST" + warning("unknown link from %s to %s" % (source.rel_path, dest)) return "." rel_path = relpath(directories[source.direc].abs_path, directories[dest.direc].abs_path) try: @@ -229,7 +237,7 @@ def get_link_from(source, dest): if rel_path.startswith("./"): rel_path = rel_path[2:] #print " from path:", source.out_path - #print " to path: ", out_path + #print " to path: ", out_path #print " rel path: ", rel_path return rel_path @@ -255,10 +263,10 @@ def get_program_directory(): # # Logging # -# 1 Error -# 2 Warning -# 3 Info -# 4 Log +# 1 Error +# 2 Warning +# 3 Info +# 4 Log # 5... Debug # def log(s, level=4): @@ -288,43 +296,43 @@ def info(s): # IkiWiki does something like this: # At startup: -# getopt modify ARGV -# checkconfig check configuration -# refresh allow plugins to build source files +# getopt modify ARGV +# checkconfig check configuration +# refresh allow plugins to build source files # While scanning files: -# needsbuild detect if page needs to be rebuild -# filter arbitrary changes -# scan collect metadata +# needsbuild detect if page needs to be rebuild +# filter arbitrary changes +# scan collect metadata # While rendering files: -# filter arbitrary changes -# preprocess execute macros -# linkify change wikilinks into links -# htmlize turns text into html -# sanitize sanitize html -# templatefile allows changing of the template on a per-file basis -# pagetemplate fill template with page -# format similar to sanitize, but act on whole page body +# filter arbitrary changes +# preprocess execute macros +# linkify change wikilinks into links +# htmlize turns text into html +# sanitize sanitize html +# templatefile allows changing of the template on a per-file basis +# pagetemplate fill template with page +# format similar to sanitize, but act on whole page body # At the end: -# savestate plugins can save their state +# savestate plugins can save their state # # # We do something like this: # # At startup: -# addoptions allow plugins to add command-line options -# checkconfig check configuration +# addoptions allow plugins to add command-line options +# checkconfig check configuration # start # While reading files: -# read ask any reader (plugins!) to read the file -# filter ask anybody to filter the contents +# read ask any reader (plugins!) to read the file +# filter ask anybody to filter the contents # While scanning files: -# scan called per file, let plugins act on file data -# scan_done Allows post-processing of scanned data +# scan called per file, let plugins act on file data +# scan_done Allows post-processing of scanned data # While rendering files: -# htmlize turns text into html-part -# linkify convert link macros to HTML -# pagetemplate ask template engine (plugin!) to generate HTML out -# of template and body part +# htmlize turns text into html-part +# linkify convert link macros to HTML +# pagetemplate ask template engine (plugin!) to generate HTML out +# of template and body part # At the end: # finish # @@ -341,12 +349,7 @@ def load_plugins(): for s in cfg.plugin_dirs: sys.path.append(s) for s in cfg.plugins: - #print "import:", s - try: - exec "import %s" % s - except: - print "Could not import plugin '%s'" % s - sys.exit(1) + exec "import %s" % s def set_hook(name, last=False): @@ -482,9 +485,9 @@ def read_file(direc, file): return_holder=False) if not contents: return + file.contents = contents log("filtering file %s" % file.rel_path, level=6) - file.contents = contents res = run_hooks("filter", direc=direc, file=file) @@ -516,7 +519,7 @@ def walk_tree(dirpath): full_path = os.path.join(dirpath, s) ok = True if os.path.isdir(full_path): - for e in cfg.exclude_dir: + for e in cfg.exclude_dirs: if fnmatch.fnmatchcase(s, e): log("ignoring directory %s" % s, level=7) ok = False @@ -559,14 +562,14 @@ def walk_tree(dirpath): # reMacro = re.compile(r''' - \[\[\! # Begin of macro + \[\[\! # Begin of macro \s* - ([^\s\]]+) # Macro name + ([^\s\]]+) # Macro name (?: - \s+ # optional space - ([^\]]+) # optional argumens + \s+ # optional space + ([^\]]+) # optional argumens )? - \]\] # End of macro + \]\] # End of macro ''', re.VERBOSE) reMacroArgs = re.compile(r''' ([-_\w]+) # parameter name @@ -575,9 +578,9 @@ reMacroArgs = re.compile(r''' = \s* (?: - "([^"]*)" # single-quoted + "([^"]*)" # single-quoted | - (\S+) # unquoted + (\S+) # unquoted ) )? ''', re.VERBOSE) @@ -622,7 +625,7 @@ def scan_files(): direc = directories[file.direc] - # Output-Filename "berechnen" + # "calculate" output file name if file.render and file.render == "html": file.out_path = os.path.splitext(s)[0] + ".html" @@ -679,18 +682,16 @@ def render_files(): continue direc = directories[file.direc] - contents = run_hooks("linkify", + run_hooks("linkify", direc=direc, file=file, - return_holder=False) + return_holder=True) #print "contents after 'linkify':", contents - if not contents: + if not file.contents: continue - file.contents = contents - # TODO: einige Fragmente sollen u.U. in eine andere - # Webseite eingebaut werden und sollten daher nicht in - # ein HTML-File landen + # TODO: make it possible to render also "fragments", e.g. + # parts that don't end up immediately in a the HTML file. contents = run_hooks("pagetemplate", direc=direc, file=file, @@ -708,12 +709,13 @@ def render_files(): except OSError: pass - # TODO: evtl. überprüfen, ob contents == f.read(), dann nicht schreiben + # TODO: check if contents == f.read(). In this case we don't + # need to save. Probably overkill. log("writing file %s" % fname_out, level=6) f = open(fname_out, "w") f.write(contents) f.close() - # TODO: Time-Stamps setzen? + os.utime(fname_out, (file.mtime, file.mtime)) #print file.mtime, file.get("ctime","?") #print direc.keys() @@ -775,7 +777,12 @@ def main(): # link contents of webber.ini into cfg and set some defaults, # then let plugins fixup things in cfg.* cfg.inheritFrom(options) - cfg.setDefault("exclude_dir", ["plugins"]) + cfg.setDefault("exclude_dirs", []) + cfg.setDefault("exclude_files", ["webber.conf", "directory.conf", "*.tmpl"]) + cfg.setDefault("copy_files", []) + cfg.setDefault("input_encoding", "iso-8859-1") + cfg.setDefault("output_encoding", "iso-8859-1") + cfg.setDefault("template", "default") run_hooks("checkconfig") run_hooks("start")