]> arthur.barton.de Git - bup.git/blobdiff - cmd/web-cmd.py
Adjust sparse restore tests for test fs block size
[bup.git] / cmd / web-cmd.py
index 32e4117905ed054a2e2294e44861c977b7dd4ab4..1c515e2d10d6ddfa0d488311adcd1f73315f11d8 100755 (executable)
@@ -1,5 +1,6 @@
 #!/usr/bin/env python
 import sys, stat, urllib, mimetypes, posixpath, time, webbrowser
+import urllib
 from bup import options, git, vfs
 from bup.helpers import *
 try:
@@ -47,21 +48,22 @@ def _compute_dir_contents(n, path, show_hidden=False):
     if path != "/":
         yield('..', '../' + url_append, '')
     for sub in n:
-        display = link = sub.name
+        display = sub.name
+        link = urllib.quote(sub.name)
 
         # link should be based on fully resolved type to avoid extra
         # HTTP redirect.
         if stat.S_ISDIR(sub.try_resolve().mode):
-            link = sub.name + "/"
+            link += "/"
 
         if not show_hidden and len(display)>1 and display.startswith('.'):
             continue
 
         size = None
         if stat.S_ISDIR(sub.mode):
-            display = sub.name + '/'
+            display += '/'
         elif stat.S_ISLNK(sub.mode):
-            display = sub.name + '@'
+            display += '@'
         else:
             size = sub.size()
             size = (opt.human_readable and format_filesize(size)) or size
@@ -143,6 +145,8 @@ class BupRequestHandler(tornado.web.RequestHandler):
                 self.request.connection.stream.write(blob,
                                                      callback=lambda: me(me))
             write_more(write_more)
+        else:
+            self.finish()
 
     def _guess_type(self, path):
         """Guess the type of a file.
@@ -225,8 +229,8 @@ if __name__ == "__main__":
 
     print "Serving HTTP on %s:%d..." % sock.getsockname()
 
-    if opt.browser:
-        webbrowser.open('http://' + address[0] + ':' + str(address[1]))
-
     loop = tornado.ioloop.IOLoop.instance()
+    if opt.browser:
+        browser_addr = 'http://' + address[0] + ':' + str(address[1])
+        loop.add_callback(lambda : webbrowser.open(browser_addr))
     loop.start()