Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

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
@minrk minrk authored
Showing with 21 additions and 3 deletions.
  1. +21 −3 IPython/frontend/html/notebook/notebookapp.py
View
24 IPython/frontend/html/notebook/notebookapp.py
@@ -257,6 +257,9 @@ class NotebookApp(BaseIPythonApplication):
# create requested profiles by default, if they don't exist:
auto_create = Bool(True)
+ # file to be opened in the notebook server
+ file_to_run = Unicode('')
+
# Network related information.
ip = Unicode(LOCALHOST, config=True,
@@ -376,6 +379,10 @@ def parse_command_line(self, argv=None):
# Kernel should inherit default config file from frontend
self.kernel_argv.append("--KernelApp.parent_appname='%s'"%self.name)
+ if self.extra_args:
+ self.file_to_run = os.path.abspath(self.extra_args[0])
+ self.config.NotebookManager.notebook_dir = os.path.dirname(self.file_to_run)
+
def init_configurables(self):
# force Session default to be secure
default_secure(self.config)
@@ -524,9 +531,20 @@ def start(self):
browser = webbrowser.get(self.browser)
else:
browser = webbrowser.get()
- b = lambda : browser.open("%s://%s:%i%s" % (proto, ip, self.port,
- self.base_project_url),
- new=2)
+
+ if self.file_to_run:
+ filename, _ = os.path.splitext(os.path.basename(self.file_to_run))
+ for nb in self.notebook_manager.list_notebooks():
+ if filename == nb['name']:
+ url = nb['notebook_id']
+ break
+ else:
+ url = ''
+ else:
+ url = ''
+ b = lambda : browser.open("%s://%s:%i%s%s" % (proto, ip,
+ self.port, self.base_project_url, url),
+ new=2)
threading.Thread(target=b).start()
try:
ioloop.IOLoop.instance().start()
Please sign in to comment.
Something went wrong with that request. Please try again.