]> oss.titaniummirror.com Git - webber.git/blobdiff - webber.py
Fix directories key error in get_path_to_root
[webber.git] / webber.py
index 8d73f11c456f1679de1b04667b92147c6abd698a..ecd0351379decdc4a7ccc092ddd12057e424bfa6 100644 (file)
--- a/webber.py
+++ b/webber.py
@@ -60,6 +60,9 @@ class Directory(Holder):
                except IOError:
                        pass
 
+       def __repr__(self):
+               return "<Directory %s>" % self.rel_path
+
 
 files = {}
 current_file = None
@@ -128,6 +131,9 @@ class File(Holder):
 
                self.contents = "".join(txt)
 
+       def __repr__(self):
+               return "<File %s>" % 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:
@@ -458,6 +468,13 @@ def get_time(format=None):
 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