mirror of
https://github.com/jupyter/notebook.git
synced 2025-01-30 12:11:32 +08:00
ENH: Open a notebook from the command line
This commit lets you open notebook files from the command line, just like ipython can open (run) python files. For example: ipython notebook foo.ipynb Fixes #945.
This commit is contained in:
parent
1c957417e9
commit
1e9d2f4a1c
@ -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,
|
||||
@ -392,6 +395,10 @@ class NotebookApp(BaseIPythonApplication):
|
||||
# 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)
|
||||
@ -540,9 +547,20 @@ class NotebookApp(BaseIPythonApplication):
|
||||
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()
|
||||
|
Loading…
Reference in New Issue
Block a user