Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Merge pull request #1686 from punchagan/notebook-cmd-line

ENH: Open a notebook from the command line

open notebook files from the command line, just
like ipython can open (run) python files.  For example:

     ipython notebook foo.ipynb

closes #945
  • Loading branch information...
commit 83e0ea6027294545dba4442a42e60a153050faa4 2 parents b9c986f + 4d888f5
Min RK minrk authored

Showing 1 changed file with 21 additions and 3 deletions. Show diff stats Hide diff stats

  1. +21 3 IPython/frontend/html/notebook/notebookapp.py
24 IPython/frontend/html/notebook/notebookapp.py
@@ -257,6 +257,9 @@ class NotebookApp(BaseIPythonApplication):
257 257 # create requested profiles by default, if they don't exist:
258 258 auto_create = Bool(True)
259 259
  260 + # file to be opened in the notebook server
  261 + file_to_run = Unicode('')
  262 +
260 263 # Network related information.
261 264
262 265 ip = Unicode(LOCALHOST, config=True,
@@ -376,6 +379,10 @@ def parse_command_line(self, argv=None):
376 379 # Kernel should inherit default config file from frontend
377 380 self.kernel_argv.append("--KernelApp.parent_appname='%s'"%self.name)
378 381
  382 + if self.extra_args:
  383 + self.file_to_run = os.path.abspath(self.extra_args[0])
  384 + self.config.NotebookManager.notebook_dir = os.path.dirname(self.file_to_run)
  385 +
379 386 def init_configurables(self):
380 387 # force Session default to be secure
381 388 default_secure(self.config)
@@ -524,9 +531,20 @@ def start(self):
524 531 browser = webbrowser.get(self.browser)
525 532 else:
526 533 browser = webbrowser.get()
527   - b = lambda : browser.open("%s://%s:%i%s" % (proto, ip, self.port,
528   - self.base_project_url),
529   - new=2)
  534 +
  535 + if self.file_to_run:
  536 + filename, _ = os.path.splitext(os.path.basename(self.file_to_run))
  537 + for nb in self.notebook_manager.list_notebooks():
  538 + if filename == nb['name']:
  539 + url = nb['notebook_id']
  540 + break
  541 + else:
  542 + url = ''
  543 + else:
  544 + url = ''
  545 + b = lambda : browser.open("%s://%s:%i%s%s" % (proto, ip,
  546 + self.port, self.base_project_url, url),
  547 + new=2)
530 548 threading.Thread(target=b).start()
531 549 try:
532 550 ioloop.IOLoop.instance().start()

0 comments on commit 83e0ea6

Please sign in to comment.
Something went wrong with that request. Please try again.