def pwnbook(_parser, cmd, args): # pragma: no cover """ Start a jupyter notebook with the pwnypack enhanced kernel pre-loaded. """ notebook = NotebookApp(kernel_spec_manager_class=KSM) notebook.initialize(args) notebook.start()
def start(self): # Save current config for the node script. config = dict(baseUrl=self.connection_url, token=self.token) with open('config.json', 'w') as fid: json.dump(config, fid) messaging_pipeline = Queue() messaging_pipeline.put(config) p1 = Process(target=start_node_server, args=(messaging_pipeline, )) p1.start() NotebookApp.start(self)
def __call__(self, args): kwargs = {} from notebook.notebookapp import NotebookApp print( "You must choose a password so that others cannot connect to " "your notebook." ) pw = ytcfg.get("yt", "notebook_password") if len(pw) == 0 and not args.no_password: import IPython.lib pw = IPython.lib.passwd() print("If you would like to use this password in the future,") print("place a line like this inside the [yt] section in your") print("yt configuration file at ~/.config/yt/yt.toml") print() print(f"notebook_password = {pw}") print() elif args.no_password: pw = None if args.port != 0: kwargs["port"] = int(args.port) if args.profile is not None: kwargs["profile"] = args.profile if pw is not None: kwargs["password"] = pw app = NotebookApp(open_browser=args.open_browser, **kwargs) app.initialize(argv=[]) print() print("***************************************************************") print() print("The notebook is now live at:") print() print(f" http://127.0.0.1:{app.port}/") print() print("Recall you can create a new SSH tunnel dynamically by pressing") print(f"~C and then typing -L{app.port}:localhost:{app.port}") print("where the first number is the port on your local machine. ") print() print( "If you are using %s on your machine already, try " "-L8889:localhost:%s" % (app.port, app.port) ) print() print("***************************************************************") print() app.start()
def launch_notebook(argv=None): """ Launch a Jupyter Notebook, with custom Untitled filenames and a prepopulated first cell with necessary boilerplate code. Notes ----- To populate the first cell, the function `new_notebook` imported in notebook.services.contents needs to be monkey patched. Dirty but functional. Same thing could be achieved with custom.js or a ContentsManager subclass, but this is easier! """ try: import nbformat.v4 as nbf from notebook.notebookapp import NotebookApp from notebook.services.contents import manager from traitlets.config import Config except ImportError: sys.exit("ERROR: Jupyter Notebook not installed in this environment. " "Try with `conda install ipython jupyter notebook`") else: nbf._original_new_notebook = nbf.new_notebook def _prepopulate_nb_patch(): nb = nbf._original_new_notebook() cell = nbf.new_code_cell("# Run this cell to complete Chimera initialization\n" "from pychimera import enable_chimera, enable_chimera_inline, chimera_view\n" "enable_chimera()\nenable_chimera_inline()\nimport chimera") nb['cells'].append(cell) return nb manager.new_notebook = _prepopulate_nb_patch app = NotebookApp() c = Config() c.FileContentsManager.untitled_notebook = "Untitled PyChimera Notebook" app.update_config(c) app.initialize(argv) app.start()
def start(self): add_handlers(self.web_app, self.lab_config) NotebookApp.start(self)
def start(self): """Start the application. """ IOLoop.current().add_callback(self._run_command) NotebookApp.start(self)
parameter_path = os.path.join(notebook_dir, 'parameters.json') if not os.path.isfile(parameter_path): raise IOError('parameter file does not exist: ' + parameter_path) with open(parameter_path, 'r') as parameter_fd: parameters = json.load(parameter_fd) # set further parameters info_file = os.path.join(notebook_dir, 'server_info.json') connection_file = os.path.join(notebook_dir, 'connection_file.json') _set_parameter_if_absent(parameters, 'extra_services', ['jupyter_singleton.handlers']) _set_parameter_if_absent(parameters, 'info_file', info_file) _set_parameter_if_absent(parameters, 'connection_file', connection_file) _set_parameter_if_absent(parameters, 'connection_dir', notebook_dir) _set_parameter_if_absent(parameters, 'open_browser', False) _set_parameter_if_absent(parameters, 'notebook_dir', notebook_dir) # start kernel connector, telling the server to connect to **the** client immediately after start threading.Thread(target=start_kernel_connection, args=(info_file, )).start() # wrap the kernel manager notebook_app = NotebookApp(**parameters) singleton_kernel_manager_class = singletonkernelmanager.get_class( notebook_app.kernel_manager_class) notebook_app.kernel_manager_class = singleton_kernel_manager_class # start the jupyter server notebook_app.initialize(argv=[]) notebook_app.start()
def start(self): """Start the application. """ add_handlers(self.web_app, self.lab_config) IOLoop.current().add_callback(self._run_command) NotebookApp.start(self)