web: handle symlinks in bzrbrowse.cgi, fix images.
authorRusty Russell <rusty@rustcorp.com.au>
Sat, 7 Aug 2010 03:11:24 +0000 (12:41 +0930)
committerRusty Russell <rusty@rustcorp.com.au>
Sat, 7 Aug 2010 03:11:24 +0000 (12:41 +0930)
Makefile-web
web/bzrbrowse/bzrbrowse.cgi
web/bzrbrowse/symlink.png [new file with mode: 0644]

index 1fb0cb2051ad6cae88a754f86d1d41968c4d0e1d..b1bf415f96a5ae259462132cdd8ee4f50e52ffb0 100644 (file)
@@ -10,7 +10,7 @@ WEB_SUBDIRS=$(WEBDIR)/tarballs $(WEBDIR)/junkcode $(WEBDIR)/tarballs/with-deps $
 JUNKDIRS=$(wildcard junkcode/*)
 JUNKPAGES=$(JUNKDIRS:%=$(WEBDIR)/%.html)
 JUNKBALLS=$(JUNKDIRS:%=$(WEBDIR)/%.tar.bz2)
 JUNKDIRS=$(wildcard junkcode/*)
 JUNKPAGES=$(JUNKDIRS:%=$(WEBDIR)/%.html)
 JUNKBALLS=$(JUNKDIRS:%=$(WEBDIR)/%.tar.bz2)
-BZRBROWSE=$(WEBDIR)/bzrbrowse.cgi $(WEBDIR)/file.png $(WEBDIR)/folder.png
+BZRBROWSE=$(WEBDIR)/bzrbrowse.cgi $(WEBDIR)/file.png $(WEBDIR)/folder.png $(WEBDIR)/symlink.png
 
 upload: fastcheck webpages
        bzr push
 
 upload: fastcheck webpages
        bzr push
index 3be2f216cdab083f08ec0b540819022f16901b7a..2e3bf3c8471c703e360a8c714dd5b3c0da4ad53a 100755 (executable)
 config = {
     'root': '/home/ccan/ccan',
     'base_url': '/browse',
 config = {
     'root': '/home/ccan/ccan',
     'base_url': '/browse',
-    'images_url': '/browse',
+    'images_url': '',
     'branch_url': 'http://ccan.ozlabs.org/repo',
 }
 
     'branch_url': 'http://ccan.ozlabs.org/repo',
 }
 
-import os, sys
+import os, sys, string
 from bzrlib.branch import Branch
 from bzrlib.errors import NotBranchError
 from bzrlib import urlutils, osutils
 
 from bzrlib.branch import Branch
 from bzrlib.errors import NotBranchError
 from bzrlib import urlutils, osutils
 
-__version__ = '0.0.1'
+__version__ = '0.0.1-rusty'
 
 
 class HTTPError(Exception):
 
 
 class HTTPError(Exception):
@@ -55,6 +55,7 @@ class BzrBrowse(object):
     icons = {
         'file': 'file.png',
         'directory': 'folder.png',
     icons = {
         'file': 'file.png',
         'directory': 'folder.png',
+        'symlink': 'symlink.png',
     }
 
     page_tmpl = '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
     }
 
     page_tmpl = '''<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.1//EN" "http://www.w3.org/TR/xhtml11/DTD/xhtml11.dtd">
@@ -147,12 +148,24 @@ code { background-color: #000; color: #FFF; font-size: 90%%;}
                 linenumbers + '</pre></td><td class="text"><pre>' + escape_html(text) +
                 '</pre></td></tr></table>')
 
                 linenumbers + '</pre></td><td class="text"><pre>' + escape_html(text) +
                 '</pre></td></tr></table>')
 
+    # Symlinks in ccan contain .., and bzr refuses to serve that.  Simplify.
+    def squish(self, linkname):
+        result = []
+        for elem in string.split(linkname, os.sep):
+            if elem == '..':
+                result = result[:-1]
+            else:
+                result.append(elem)
+        return string.join(result, os.sep)
+
     def list_branch_directory(self, branch, path, relpath):
         tree = branch.basis_tree()
         file_id = tree.path2id(relpath)
         ie = tree.inventory[file_id]
         if ie.kind == 'file':
             return self.view_branch_file(tree, ie)
     def list_branch_directory(self, branch, path, relpath):
         tree = branch.basis_tree()
         file_id = tree.path2id(relpath)
         ie = tree.inventory[file_id]
         if ie.kind == 'file':
             return self.view_branch_file(tree, ie)
+        if ie.kind == 'symlink':
+            return self.list_branch_directory(branch, path, self.squish(osutils.dirname(relpath) + os.sep + ie.symlink_target))
         entries = []
         if path:
             entries.append({
         entries = []
         if path:
             entries.append({
diff --git a/web/bzrbrowse/symlink.png b/web/bzrbrowse/symlink.png
new file mode 100644 (file)
index 0000000..da3fa78
Binary files /dev/null and b/web/bzrbrowse/symlink.png differ