From 28c27a69921b3970d633713da0820d60f4cd5319 2014-11-03 18:18:04 From: KesterTong Date: 2014-11-03 18:18:04 Subject: [PATCH] Adds configuration options to use Google Drive content manager Adds the key contentmanager_js_source to webapp_settings that allows for specifying the content manager JavaScript source file. Also adds a NotebookManager subclass, ClientSideNotebookManager, which does minimal logic. This class is used when the JavaScript content manager doesn't use the Python notebook manager, but rather implements that logic client side, as is the case for the Google Drive based content manager. A sample command line that uses the Google Drive content manager, and the ClientSideNotebookManager, is ipython notebook --NotebookApp.webapp_settings="{'contentmanager_js_source': 'base/js/drive_contentmanager'}" --NotebookApp.notebook_manager_class="IPython.html.services.notebooks.clientsidenbmanager.ClientSideNotebookManager" --- diff --git a/IPython/html/base/handlers.py b/IPython/html/base/handlers.py index c64ebd7..b78a5eb 100644 --- a/IPython/html/base/handlers.py +++ b/IPython/html/base/handlers.py @@ -136,6 +136,13 @@ class IPythonHandler(AuthenticatedHandler): @property def ws_url(self): return self.settings.get('websocket_url', '') + + @property + def contentmanager_js_source(self): + self.log.debug("Using contentmanager: %s", self.settings.get('contentmanager_js_source', + 'base/js/contentmanager')) + return self.settings.get('contentmanager_js_source', + 'base/js/contentmanager') #--------------------------------------------------------------- # Manager objects @@ -224,7 +231,8 @@ class IPythonHandler(AuthenticatedHandler): logged_in=self.logged_in, login_available=self.login_available, static_url=self.static_url, - sys_info=sys_info + sys_info=sys_info, + contentmanager_js_source=self.contentmanager_js_source, ) def get_json_body(self): diff --git a/IPython/html/services/notebooks/clientsidenbmanager.py b/IPython/html/services/notebooks/clientsidenbmanager.py new file mode 100644 index 0000000..46ff3bb --- /dev/null +++ b/IPython/html/services/notebooks/clientsidenbmanager.py @@ -0,0 +1,43 @@ +"""A notebook manager for when the logic is done client side (in JavaScript).""" + +#----------------------------------------------------------------------------- +# Copyright (C) 2011 The IPython Development Team +# +# Distributed under the terms of the BSD License. The full license is in +# the file COPYING, distributed as part of this software. +#----------------------------------------------------------------------------- + +#----------------------------------------------------------------------------- +# Imports +#----------------------------------------------------------------------------- + +from .nbmanager import NotebookManager + +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, List + +#----------------------------------------------------------------------------- +# Classes +#----------------------------------------------------------------------------- + +class ClientSideNotebookManager(NotebookManager): + # The notebook directory is meaningless since we are not using + # the local filesystem. + notebook_dir = '' + + def path_exists(self, path): + # Always return true, because this check is now done client side. + return True + + def is_hidden(self, path): + # Always return false, because this check is now done client side. + return False + + def notebook_exists(self, name, path=''): + # Always return true, because this check is now done client side. + return True diff --git a/IPython/html/static/notebook/js/main.js b/IPython/html/static/notebook/js/main.js index 8eb84ea..4e5ca5f 100644 --- a/IPython/html/static/notebook/js/main.js +++ b/IPython/html/static/notebook/js/main.js @@ -5,7 +5,7 @@ require([ 'base/js/namespace', 'jquery', 'notebook/js/notebook', - 'base/js/contentmanager', + 'contentmanager', 'base/js/utils', 'base/js/page', 'notebook/js/layoutmanager', diff --git a/IPython/html/static/tree/js/main.js b/IPython/html/static/tree/js/main.js index 3670fea..853eabf 100644 --- a/IPython/html/static/tree/js/main.js +++ b/IPython/html/static/tree/js/main.js @@ -7,7 +7,7 @@ require([ 'base/js/events', 'base/js/page', 'base/js/utils', - 'base/js/contentmanager', + 'contentmanager', 'tree/js/notebooklist', 'tree/js/clusterlist', 'tree/js/sessionlist', diff --git a/IPython/html/templates/page.html b/IPython/html/templates/page.html index b3c67b8..ffad396 100644 --- a/IPython/html/templates/page.html +++ b/IPython/html/templates/page.html @@ -30,6 +30,7 @@ moment: "components/moment/moment", codemirror: 'components/codemirror', termjs: "components/term.js/src/term" + contentmanager: '{{ contentmanager_js_source }}', }, shim: { underscore: {