]> arthur.barton.de Git - bup.git/blobdiff - cmd/web-cmd.py
Merge initial bup gc command
[bup.git] / cmd / web-cmd.py
index fc4d117d4c6ef582a3a5cf72fa131e731794139d..9d5d8a1445b0d0454da06c636e7e27e785006899 100755 (executable)
@@ -1,7 +1,15 @@
-#!/usr/bin/env python
-import sys, stat, urllib, mimetypes, posixpath, time, webbrowser
+#!/bin/sh
+"""": # -*-python-*-
+bup_python="$(dirname "$0")/bup-python" || exit $?
+exec "$bup_python" "$0" ${1+"$@"}
+"""
+# end of bup preamble
+
+import mimetypes, os, posixpath, stat, sys, time, urllib, webbrowser
+
 from bup import options, git, vfs
-from bup.helpers import *
+from bup.helpers import debug1, handle_ctrl_c, log, resource_path
+
 try:
     import tornado.httpserver
     import tornado.ioloop
@@ -10,6 +18,7 @@ except ImportError:
     log('error: cannot find the python "tornado" module; please install it\n')
     sys.exit(1)
 
+
 handle_ctrl_c()
 
 
@@ -47,21 +56,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
@@ -103,7 +113,7 @@ class BupRequestHandler(tornado.web.RequestHandler):
 
         try:
             show_hidden = int(self.request.arguments.get('hidden', [0])[-1])
-        except ValueError, e:
+        except ValueError as e:
             show_hidden = False
 
         self.render(
@@ -222,7 +232,7 @@ if __name__ == "__main__":
 
     try:
         sock = http_server._socket # tornado < 2.0
-    except AttributeError, e:
+    except AttributeError as e:
         sock = http_server._sockets.values()[0]
 
     print "Serving HTTP on %s:%d..." % sock.getsockname()