##// END OF EJS Templates
Merge pull request #5216 from minrk/notebook-dir-cli...
Thomas Kluyver -
r15490:ad096bf7 merge
parent child Browse files
Show More
@@ -332,7 +332,12 b' class NotebookApp(BaseIPythonApplication):'
332 auto_create = Bool(True)
332 auto_create = Bool(True)
333
333
334 # file to be opened in the notebook server
334 # file to be opened in the notebook server
335 file_to_run = Unicode('')
335 file_to_run = Unicode('', config=True)
336 def _file_to_run_changed(self, name, old, new):
337 path, base = os.path.split(new)
338 if path:
339 self.file_to_run = base
340 self.notebook_dir = path
336
341
337 # Network related information.
342 # Network related information.
338
343
@@ -545,10 +550,13 b' class NotebookApp(BaseIPythonApplication):'
545 if not os.path.exists(f):
550 if not os.path.exists(f):
546 self.log.critical("No such file or directory: %s", f)
551 self.log.critical("No such file or directory: %s", f)
547 self.exit(1)
552 self.exit(1)
553
554 # Use config here, to ensure that it takes higher priority than
555 # anything that comes from the profile.
548 if os.path.isdir(f):
556 if os.path.isdir(f):
549 self.notebook_dir = f
557 self.config.NotebookApp.notebook_dir = f
550 elif os.path.isfile(f):
558 elif os.path.isfile(f):
551 self.file_to_run = f
559 self.config.NotebookApp.file_to_run = f
552
560
553 def init_kernel_argv(self):
561 def init_kernel_argv(self):
554 """construct the kernel arguments"""
562 """construct the kernel arguments"""
@@ -799,24 +807,17 b' class NotebookApp(BaseIPythonApplication):'
799 self.log.warn('No web browser found: %s.' % e)
807 self.log.warn('No web browser found: %s.' % e)
800 browser = None
808 browser = None
801
809
802 f = self.file_to_run
810 if self.file_to_run:
803 if f:
811 fullpath = os.path.join(self.notebook_dir, self.file_to_run)
804 nbdir = os.path.abspath(self.notebook_manager.notebook_dir)
812 if not os.path.exists(fullpath):
805 if f.startswith(nbdir):
813 self.log.critical("%s does not exist" % fullpath)
806 f = f[len(nbdir):]
814 self.exit(1)
807 else:
815
808 self.log.warn(
816 uri = url_path_join('notebooks', self.file_to_run)
809 "Probably won't be able to open notebook %s "
810 "because it is not in notebook_dir %s",
811 f, nbdir,
812 )
813
814 if os.path.isfile(self.file_to_run):
815 url = url_path_join('notebooks', f)
816 else:
817 else:
817 url = url_path_join('tree', f)
818 uri = 'tree'
818 if browser:
819 if browser:
819 b = lambda : browser.open("%s%s" % (self.connection_url, url),
820 b = lambda : browser.open(url_path_join(self.connection_url, uri),
820 new=2)
821 new=2)
821 threading.Thread(target=b).start()
822 threading.Thread(target=b).start()
822 try:
823 try:
General Comments 0
You need to be logged in to leave comments. Login now