]> oss.titaniummirror.com Git - webber.git/blobdiff - webber.py
webber.py: smaller __repr__() string for webber.Directory and
[webber.git] / webber.py
index 643aa25a1eef34c149c7359dfd1a77e88b5e2636..9913e81d0d4041e83149d6fa00982487452ebcf5 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:
@@ -445,12 +455,14 @@ 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():
@@ -777,7 +789,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")