##// END OF EJS Templates
add `ipython notebook trust` subcommand
MinRK -
Show More
@@ -83,12 +83,13 b' from IPython.kernel.zmq.kernelapp import ('
83 kernel_flags,
83 kernel_flags,
84 kernel_aliases,
84 kernel_aliases,
85 )
85 )
86 from IPython.nbformat import current, sign
86 from IPython.utils.importstring import import_item
87 from IPython.utils.importstring import import_item
87 from IPython.utils.localinterfaces import localhost
88 from IPython.utils.localinterfaces import localhost
88 from IPython.utils import submodule
89 from IPython.utils import submodule
89 from IPython.utils.traitlets import (
90 from IPython.utils.traitlets import (
90 Dict, Unicode, Integer, List, Bool, Bytes,
91 Dict, Unicode, Integer, List, Bool, Bytes,
91 DottedObjectName
92 DottedObjectName, Instance,
92 )
93 )
93 from IPython.utils import py3compat
94 from IPython.utils import py3compat
94 from IPython.utils.path import filefind, get_ipython_dir
95 from IPython.utils.path import filefind, get_ipython_dir
@@ -217,6 +218,10 b' class NotebookWebApplication(web.Application):'
217 return new_handlers
218 return new_handlers
218
219
219
220
221 #-----------------------------------------------------------------------------
222 # Subcommands
223 #-----------------------------------------------------------------------------
224
220 class NbserverListApp(BaseIPythonApplication):
225 class NbserverListApp(BaseIPythonApplication):
221
226
222 description="List currently running notebook servers in this profile."
227 description="List currently running notebook servers in this profile."
@@ -239,6 +244,37 b' class NbserverListApp(BaseIPythonApplication):'
239 else:
244 else:
240 print(serverinfo['url'], "::", serverinfo['notebook_dir'])
245 print(serverinfo['url'], "::", serverinfo['notebook_dir'])
241
246
247
248 class NotebookTrustApp(BaseIPythonApplication):
249
250 description="""Sign one or more IPython notebooks with your key,
251 to trust their dynamic (HTML, Javascript) output."""
252
253 examples="""ipython notebook trust mynotebook.ipynb"""
254
255 notary = Instance(sign.NotebookNotary)
256 def _notary_default(self):
257 return sign.NotebookNotary(parent=self, profile_dir=self.profile_dir)
258
259 def sign_notebook(self, notebook_path):
260 if not os.path.exists(notebook_path):
261 self.log.error("Notebook missing: %s" % notebook_path)
262 self.exit(1)
263 with io.open(notebook_path, encoding='utf8') as f:
264 nb = current.read(f, 'json')
265 sign.trust_notebook(nb, self.notary.secret, self.notary.signature_scheme)
266 with io.open(notebook_path, 'w', encoding='utf8') as f:
267 current.write(nb, f, 'json')
268
269 def start(self):
270 if not self.extra_args:
271 self.log.critical("Specify at least one notebook to sign.")
272 self.exit(1)
273
274 for notebook_path in self.extra_args:
275 print("Signing notebook: %s" % notebook_path)
276 self.sign_notebook(notebook_path)
277
242 #-----------------------------------------------------------------------------
278 #-----------------------------------------------------------------------------
243 # Aliases and Flags
279 # Aliases and Flags
244 #-----------------------------------------------------------------------------
280 #-----------------------------------------------------------------------------
@@ -313,6 +349,7 b' class NotebookApp(BaseIPythonApplication):'
313
349
314 subcommands = dict(
350 subcommands = dict(
315 list=(NbserverListApp, NbserverListApp.description.splitlines()[0]),
351 list=(NbserverListApp, NbserverListApp.description.splitlines()[0]),
352 trust=(NotebookTrustApp, NotebookTrustApp.description),
316 )
353 )
317
354
318 kernel_argv = List(Unicode)
355 kernel_argv = List(Unicode)
General Comments 0
You need to be logged in to leave comments. Login now