From: Gabriel Filion Date: Tue, 27 Jul 2010 18:02:36 +0000 (-0400) Subject: cmd/web: hide .dotfiles by default X-Git-Tag: bup-0.17~19 X-Git-Url: https://arthur.barton.de/cgi-bin/gitweb.cgi?p=bup.git;a=commitdiff_plain;h=d63a04bb3e401c18c54302bb3846a0ee8225401d cmd/web: hide .dotfiles by default 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 --- diff --git a/cmd/web-cmd.py b/cmd/web-cmd.py index aca9f87..6092ad2 100755 --- a/cmd/web-cmd.py +++ b/cmd/web-cmd.py @@ -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) diff --git a/lib/web/list-directory.html b/lib/web/list-directory.html index 49c1971..b5b68ae 100644 --- a/lib/web/list-directory.html +++ b/lib/web/list-directory.html @@ -17,6 +17,15 @@ {% end %} {{ escape(breadcrumbs[-1][0]) }} + {% if files_hidden %} +
+ {% if hidden_shown %} + Hide hidden files + {% else %} + Show hidden files + {% end %} +
+ {% end %}
Name