Strip leading slashes in directory headers
[geekigeeki.git] / geekigeeki.py
index 71920f370b9dd74f6c0df8b057bf308a404fa9f0..52010d6d33a1e0cd45e3c5033454be994b8dede6 100755 (executable)
@@ -337,6 +337,7 @@ def send_footer(mod_string=None):
         cgi.print_arguments()
         cgi.print_form(form)
         cgi.print_environ()
+        #FIXME link_inline("sys/footer")
     print('''
 <div id="footer"><hr />
 <p class="copyright">
@@ -556,7 +557,7 @@ class WikiFormatter:
             | (?P<url>   (http|https|ftp|mailto)\:[^\s'\"]+\S)
             | (?P<email> [-\w._+]+\@[\w.-]+)
 
-            # Lists, divs, spans
+            # Lists, divs, spans and inline objects
             | (?P<li>    ^\s+[\*\#]\s+)
             | (?P<pre>   \{\{\{|\s*\}\}\})
             | (?P<inl>   \{\{([^\s\|]+)(?:\s*\|\s*([^\]]+)|)\}\})
@@ -645,7 +646,7 @@ class Page:
     def format_dir(self):
         out = '== '
         pathname = ''
-        for dirname in self.page_name.split('/'):
+        for dirname in self.page_name.strip('/').split('/'):
             pathname = (pathname + '/' + dirname) if pathname else dirname
             out += '[[' + pathname + '|' + dirname + ']]/'
         out += ' ==\n'
@@ -795,6 +796,9 @@ class Page:
                 os.remove(name)
             except OSError, err:
                 if err.errno != errno.ENOENT: raise err
+        path = os.path.split(name)[0]
+        if not os.path.exists(path):
+            os.makedirs(path)
         os.rename(tmp_filename, name)
 
     def save(self, newdata, changelog):