diff --git a/IPython/html/nbextensions.py b/IPython/html/nbextensions.py index 78b3eba..3dcf564 100644 --- a/IPython/html/nbextensions.py +++ b/IPython/html/nbextensions.py @@ -99,3 +99,78 @@ def install_nbextension(files, overwrite=False, ipython_dir=None, verbose=1): else: src = path _maybe_copy(src, dest, verbose) + +#---------------------------------------------------------------------- +# install nbextension app +#---------------------------------------------------------------------- + +import logging +from IPython.utils.traitlets import Bool, Enum +from IPython.core.application import BaseIPythonApplication + +flags = { + "overwrite" : ({ + "NBExtensionApp" : { + "overwrite" : True, + }}, "Force overwrite of existing files" + ), + "debug" : ({ + "NBExtensionApp" : { + "verbose" : 2, + }}, "Extra output" + ), + "quiet" : ({ + "NBExtensionApp" : { + "verbose" : 0, + }}, "Minimal output" + ), +} +aliases = { + "ipython-dir" : "NBExtensionApp.ipython_dir" +} + +class NBExtensionApp(BaseIPythonApplication): + """Entry point for installing notebook extensions""" + + description = """Install IPython notebook extensions + + Usage + + ipython install-nbextension file [more files or folders] + + This copies files and/or folders into the IPython nbextensions directory. + If the requested files are already up to date, no action is taken + unless --overwrite is specified. + """ + + examples = """ + ipython install-nbextension /path/to/d3.js /path/to/myextension + """ + aliases = aliases + flags = flags + + overwrite = Bool(False, config=True, help="Force overwrite of existing files") + verbose = Enum((0,1,2), default_value=1, config=True, + help="Verbosity level" + ) + + def install_extensions(self): + install_nbextension(self.extra_args, + overwrite=self.overwrite, + verbose=self.verbose, + ipython_dir=self.ipython_dir, + ) + + def start(self): + if not self.extra_args: + nbext = pjoin(self.ipython_dir, u'nbextensions') + print("Notebook extensions in %s:" % nbext) + for ext in os.listdir(nbext): + print(u" %s" % ext) + else: + self.install_extensions() + + +if __name__ == '__main__': + NBExtensionApp.launch_instance() + \ No newline at end of file diff --git a/IPython/terminal/ipapp.py b/IPython/terminal/ipapp.py index 4f15d20..4394edc 100755 --- a/IPython/terminal/ipapp.py +++ b/IPython/terminal/ipapp.py @@ -224,7 +224,7 @@ class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp): StoreMagics, ] - subcommands = Dict(dict( + subcommands = dict( qtconsole=('IPython.qt.console.qtconsoleapp.IPythonQtConsoleApp', """Launch the IPython Qt Console.""" ), @@ -253,6 +253,10 @@ class TerminalIPythonApp(BaseIPythonApplication, InteractiveShellApp): "Sign notebooks to trust their potentially unsafe contents at load." ), )) + subcommands['install-nbextension'] = ( + "IPython.html.nbextensions.NBExtensionApp", + "Install IPython notebook extension files" + ) # *do* autocreate requested profile, but don't create the config file. auto_create=Bool(True)