X-Git-Url: https://oss.titaniummirror.com/gitweb?a=blobdiff_plain;f=webber.py;h=ecd0351379decdc4a7ccc092ddd12057e424bfa6;hb=HEAD;hp=687e182fa89b93b70bf5c96e5606d2b52144e9ef;hpb=2dd3390846afc798333bfb8ffac9ebd9ad2682cc;p=webber.git diff --git a/webber.py b/webber.py index 687e182..ecd0351 100644 --- a/webber.py +++ b/webber.py @@ -60,6 +60,9 @@ class Directory(Holder): except IOError: pass + def __repr__(self): + return "" % self.rel_path + files = {} current_file = None @@ -128,6 +131,9 @@ class File(Holder): self.contents = "".join(txt) + def __repr__(self): + return "" % self.rel_path + _get_file_for_cache = {} def get_file_for(name): @@ -147,6 +153,10 @@ 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 @@ -215,8 +225,8 @@ def relpath(base_path, target): 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: @@ -445,17 +455,26 @@ def iso_to_time(val): 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