]> arthur.barton.de Git - bup.git/commitdiff
cmd/web: hide .dotfiles by default
authorGabriel Filion <lelutin@gmail.com>
Tue, 27 Jul 2010 18:02:36 +0000 (14:02 -0400)
committerAvery Pennarun <apenwarr@gmail.com>
Tue, 27 Jul 2010 18:15:14 +0000 (14:15 -0400)
Make all files begining with a dot be hidden by default. The hidden
files can be shown by giving the argument "hidden" with a vlue of 1 in
the URL.

Also, in _compute_dir_contents, remove the line "contents = []" since it
is never used.

Finally add a "Show/Hide hidden files" link on the pages where content
is hidden.

Signed-off-by: Gabriel Filion <lelutin@gmail.com>
cmd/web-cmd.py
lib/web/list-directory.html

index aca9f87a5f21a35c73defeeb56d756c899363469..6092ad24b1ebceeabe3a33afda629e1962b1bebb 100755 (executable)
@@ -22,12 +22,24 @@ def _compute_breadcrumbs(path):
     return breadcrumbs
 
 
-def _compute_dir_contents(n):
+def _contains_hidden_files(n):
+    """Return True if n contains files starting with a '.', False otherwise."""
+    for sub in n:
+        name = sub.name
+        if len(name)>1 and name.startswith('.'):
+            return True
+
+    return False
+
+
+def _compute_dir_contents(n, show_hidden=False):
     """Given a vfs node, returns an iterator for display info of all subs."""
-    contents = []
     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):
@@ -75,11 +87,18 @@ class BupRequestHandler(tornado.web.RequestHandler):
             print 'Redirecting from %s to %s' % (path, path + '/')
             return self.redirect(path + '/', permanent=True)
 
+        try:
+            show_hidden = int(self.request.arguments.get('hidden', [0])[-1])
+        except ValueError, e:
+            show_hidden = False
+
         self.render(
             'list-directory.html',
             path=path,
             breadcrumbs=_compute_breadcrumbs(path),
-            dir_contents=_compute_dir_contents(n),
+            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)
 
index 49c1971719aaa42bc9f4ac5d85dd8a51142e4748..b5b68ae5b8457afe3bcd402f33390e1d582074c7 100644 (file)
       {% 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>