From 38b3add27e48c987b1be0ddd36dd748965877573 2014-02-28 19:37:26 From: Thomas Kluyver Date: 2014-02-28 19:37:26 Subject: [PATCH] Make hidden directories configurable --- diff --git a/IPython/html/services/notebooks/filenbmanager.py b/IPython/html/services/notebooks/filenbmanager.py index 6431295..d5728fa 100644 --- a/IPython/html/services/notebooks/filenbmanager.py +++ b/IPython/html/services/notebooks/filenbmanager.py @@ -187,7 +187,7 @@ class FileNotebookManager(NotebookManager): for name in dir_names: os_path = self._get_os_path(name, path) if os.path.isdir(os_path) and not is_hidden(os_path, self.notebook_dir)\ - and not name.startswith('_'): + and self.should_list(name): try: model = self.get_dir_model(name, path) except IOError: @@ -233,7 +233,8 @@ class FileNotebookManager(NotebookManager): """ path = path.strip('/') notebook_names = self.get_notebook_names(path) - notebooks = [self.get_notebook(name, path, content=False) for name in notebook_names] + notebooks = [self.get_notebook(name, path, content=False) + for name in notebook_names if self.should_list(name)] notebooks = sorted(notebooks, key=sort_key) return notebooks diff --git a/IPython/html/services/notebooks/nbmanager.py b/IPython/html/services/notebooks/nbmanager.py index a9d397d..f3fb3fc 100644 --- a/IPython/html/services/notebooks/nbmanager.py +++ b/IPython/html/services/notebooks/nbmanager.py @@ -17,12 +17,13 @@ Authors: # Imports #----------------------------------------------------------------------------- +from fnmatch import fnmatch import itertools import os from IPython.config.configurable import LoggingConfigurable from IPython.nbformat import current, sign -from IPython.utils.traitlets import Instance, Unicode +from IPython.utils.traitlets import Instance, Unicode, List #----------------------------------------------------------------------------- # Classes @@ -36,6 +37,10 @@ class NotebookManager(LoggingConfigurable): def _notary_default(self): return sign.NotebookNotary(parent=self) + hide_globs = List(Unicode, [u'__pycache__'], config=True, help=""" + Glob patterns to hide in file and directory listings. + """) + # NotebookManager API part 1: methods that must be # implemented in subclasses. @@ -241,3 +246,6 @@ class NotebookManager(LoggingConfigurable): self.log.warn("Notebook %s/%s is not trusted", path, name) self.notary.mark_cells(nb, trusted) + def should_list(self, name): + """Should this file/directory name be displayed in a listing?""" + return not any(fnmatch(name, glob) for glob in self.hide_globs)