]> arthur.barton.de Git - bup.git/commitdiff
Merge branch 'dr/web'
authorAvery Pennarun <apenwarr@gmail.com>
Wed, 22 Sep 2010 02:00:00 +0000 (19:00 -0700)
committerAvery Pennarun <apenwarr@gmail.com>
Wed, 22 Sep 2010 02:00:03 +0000 (19:00 -0700)
* drweb:
  Add simple styling to bup web.
  If we are showing hidden files, continue to do so.
  Enable static resources. Move css to external file.

Makefile
cmd/web-cmd.py
lib/web/list-directory.html
lib/web/static/styles.css [new file with mode: 0644]

index 65a8e3d8c22ace200b2abe915a1b0ef48c07889c..0faf8a684ff7d4967878587bf0de56c18fa53617 100644 (file)
--- a/Makefile
+++ b/Makefile
@@ -34,7 +34,7 @@ LIBDIR=$(DESTDIR)/usr/lib/bup
 install: all
        $(INSTALL) -d $(MANDIR)/man1 $(DOCDIR) $(BINDIR) \
                $(LIBDIR)/bup $(LIBDIR)/cmd $(LIBDIR)/tornado \
-               $(LIBDIR)/web
+               $(LIBDIR)/web $(LIBDIR)/web/static
        [ ! -e Documentation/.docs-available ] || \
          $(INSTALL) -m 0644 \
                Documentation/*.1 \
@@ -57,8 +57,11 @@ install: all
                lib/tornado/*.py \
                $(LIBDIR)/tornado
        $(INSTALL) -m 0644 \
-               lib/web/* \
-               $(LIBDIR)/web
+               lib/web/static/* \
+               $(LIBDIR)/web/static/
+       $(INSTALL) -m 0644 \
+               lib/web/*.html \
+               $(LIBDIR)/web/
 %/all:
        $(MAKE) -C $* all
 
index d0ca73046f433f8fc274a5fab7b973c997c43a2a..4b988140338b40758be97b7dd9857c0abb6274c7 100755 (executable)
@@ -9,15 +9,18 @@ from bup.helpers import *
 handle_ctrl_c()
 
 
-def _compute_breadcrumbs(path):
+def _compute_breadcrumbs(path, show_hidden=False):
     """Returns a list of breadcrumb objects for a path."""
     breadcrumbs = []
     breadcrumbs.append(('[root]', '/'))
     path_parts = path.split('/')[1:-1]
     full_path = '/'
     for part in path_parts:
-        full_path += part + '/'
-        breadcrumbs.append((part, full_path))
+        full_path += part + "/"
+        url_append = ""
+        if show_hidden:
+            url_append = '?hidden=1'
+        breadcrumbs.append((part, full_path+url_append))
     return breadcrumbs
 
 
@@ -36,14 +39,18 @@ def _compute_dir_contents(n, show_hidden=False):
     for sub in n:
         display = link = sub.name
 
-        if not show_hidden and len(display)>1 and display.startswith('.'):
-            continue
-
         # link should be based on fully resolved type to avoid extra
         # HTTP redirect.
         if stat.S_ISDIR(sub.try_resolve().mode):
             link = sub.name + "/"
 
+        if not show_hidden and len(display)>1 and display.startswith('.'):
+            continue
+
+        url_append = ""
+        if show_hidden:
+            url_append = "?hidden=1"
+
         size = None
         if stat.S_ISDIR(sub.mode):
             display = sub.name + '/'
@@ -52,7 +59,7 @@ def _compute_dir_contents(n, show_hidden=False):
         else:
             size = sub.size()
 
-        yield (display, link, size)
+        yield (display, link + url_append, size)
 
 
 class BupRequestHandler(tornado.web.RequestHandler):
@@ -94,12 +101,10 @@ class BupRequestHandler(tornado.web.RequestHandler):
         self.render(
             'list-directory.html',
             path=path,
-            breadcrumbs=_compute_breadcrumbs(path),
+            breadcrumbs=_compute_breadcrumbs(path, show_hidden),
             files_hidden=_contains_hidden_files(n),
             hidden_shown=show_hidden,
-            dir_contents=_compute_dir_contents(n, show_hidden),
-            # We need the standard url_escape so we don't escape /
-            url_escape=urllib.quote)
+            dir_contents=_compute_dir_contents(n, show_hidden))
 
     def _get_file(self, path, n):
         """Process a request on a file.
@@ -178,6 +183,7 @@ top = vfs.RefList(None)
 settings = dict(
     debug = 1,
     template_path = resource_path('web'),
+    static_path = resource_path('web/static')
 )
 
 # Disable buffering on stdout, for debug messages
index b5b68ae5b8457afe3bcd402f33390e1d582074c7..14ce0ffd403d2f7d23dd77f892971e4b775cf216 100644 (file)
@@ -1,43 +1,39 @@
 <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
 <html>
-  <head>
-    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
-    <title>Directory listing for {{ escape(path) }}</title>
-    <style type="text/css">
-      body, table { font-family: sans-serif }
-      #breadcrumb { margin: 10px 0; }
-      .dir-name { text-align: left }
-      .dir-size { text-align: right }
-    </style>
-  </head>
-  <body>
-    <div id="breadcrumb">
-      {% for (display, part_path) in breadcrumbs[:-1] %}
-        <a href="{{ url_escape(part_path) }}">{{ escape(display) }}</a> /
-      {% end %}
-      <strong>{{ escape(breadcrumbs[-1][0]) }}</strong>
-    </div>
-    {% if files_hidden %}
-    <div id="message">
-      {% if hidden_shown %}
-      <a href=".">Hide hidden files</a>
-      {% else %}
-      <a href="?hidden=1">Show hidden files</a>
-      {% end %}
-    </div>
-    {% end %}
-    <table>
-      <tr>
-        <th class="dir-name">Name</th>
-        <th class="dir-size">Size</th>
-      </tr>
-      {% for (display, link, size) in dir_contents %}
-        <tr>
-          <td class="dir-name"><a href="{{ url_escape(link) }}">{{ escape(display) }}</a></td>
-          <td class="dir-size">{% if size != None %}{{ size }}{% else %}&nbsp;{% end %}</td>
-        </tr>
-      {% end %}
-    </table>
-  </body>
+    <head>
+        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
+        <title>Directory listing for {{ escape(path) }}</title>
+        <link rel="stylesheet" href="/static/styles.css" />
+    </head>
+    <body>
+        <div id="wrapper">
+            <div id="breadcrumb">
+                {% for (display, part_path) in breadcrumbs[:-1] %}
+                <a href="{{ part_path }}">{{ display }}</a> /
+                {% end %}
+                <strong>{{ breadcrumbs[-1][0] }}</strong>
+            </div>
+            {% if files_hidden %}
+            <div id="message">
+                {% if hidden_shown %}
+                    <a href=".">Hide hidden files</a>
+                {% else %}
+                    <a href="?hidden=1">Show hidden files</a>
+                {% end %}
+            </div>
+            {% end %}
+            <table>
+                <tr>
+                    <th class="dir-name">Name</th>
+                    <th class="dir-size">Size</th>
+                </tr>
+                {% for (display, link, size) in dir_contents %}
+                <tr>
+                    <td class="dir-name"><a href="{{ link }}">{{ display }}</a></td>
+                    <td class="dir-size">{% if size != None %}{{ size }}{% else %}&nbsp;{% end %}</td>
+                </tr>
+                {% end %}
+            </table>
+        </div>
+    </body>
 </html>
-
diff --git a/lib/web/static/styles.css b/lib/web/static/styles.css
new file mode 100644 (file)
index 0000000..12f6516
--- /dev/null
@@ -0,0 +1,28 @@
+body {
+    font-family: sans-serif
+}
+
+#wrapper {
+    width: 960px;
+    margin: auto;
+}
+
+#breadcrumb {
+    margin: 10px 0;
+}
+
+table {
+    width: 100%;
+}
+
+th {
+    text-align: left;
+}
+
+.dir-name {
+    width:80%;
+}
+
+.dir-size {
+    width:20%;
+}
\ No newline at end of file