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
+
+ def __repr__(self):
+ return "<Directory %s>" % self.rel_path
files = {}
self.contents = "".join(txt)
+ def __repr__(self):
+ return "<File %s>" % self.rel_path
+
_get_file_for_cache = {}
def get_file_for(name):
#print " via linktitle:", s
_get_file_for_cache[name] = f
return f
+ if f.title == name:
+ #print " via title:", s
+ _get_file_for_cache[name] = f
+ return f
except:
pass
# Allow exact match as well
def get_link_from(source, dest):
- #print "get_link_from", source, dest
- #print source
+ if dest is None:
+ raise KeyError
if not isinstance(source, File):
source = get_file_for(source)
if not source:
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:
return int(time.mktime(t))
@set_function("format_date")
-def format_date(timestamp):
- return time.strftime(cfg.date_format, time.localtime(timestamp))
+def format_date(timestamp, format=None):
+ if not format:
+ format = cfg.date_format
+ return time.strftime(format, time.localtime(timestamp))
@set_function("get_time")
-def get_time():
- return format_date(time.time())
+def get_time(format=None):
+ return format_date(time.time(), format)
@set_function("get_current_file")
def get_current_file():
return current_file
+@set_function("get_path_to_root")
+def get_path_to_root():
+ rel_path = relpath(directories[current_file.direc].abs_path, directories['.'].abs_path)
+ rel_path = os.path.join(rel_path, os.path.split("")[1])
+ if rel_path[-1] == "/":
+ rel_path = rel_path[:-1]
+ return rel_path
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)
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
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"
if not file.contents:
continue
- # 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,
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()
# 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")