def initialize(webapp, root_dir, connection_url, settings): if os.name == 'nt': default_shell = 'powershell.exe' else: default_shell = which('sh') shell = settings.get('shell_command', [os.environ.get('SHELL') or default_shell]) # Enable login mode - to automatically source the /etc/profile script if os.name != 'nt': shell.append('-l') terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager( shell_command=shell, extra_env={ 'JUPYTER_SERVER_ROOT': root_dir, 'JUPYTER_SERVER_URL': connection_url, }, ) terminal_manager.log = app_log base_url = webapp.settings['base_url'] handlers = [ (ujoin(base_url, r"/terminals/(\w+)"), TerminalHandler), (ujoin(base_url, r"/terminals/websocket/(\w+)"), TermSocket, { 'term_manager': terminal_manager }), (ujoin(base_url, r"/api/terminals"), api_handlers.TerminalRootHandler), (ujoin(base_url, r"/api/terminals/(\w+)"), api_handlers.TerminalHandler), ] webapp.add_handlers(".*$", handlers)
def initialize(webapp, notebook_dir, connection_url, settings): if os.name == 'nt': default_shell = 'powershell.exe' else: default_shell = which('sh') shell = settings.get('shell_command', [os.environ.get('SHELL') or default_shell]) terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager( shell_command=shell, extra_env={ 'JUPYTER_SERVER_ROOT': notebook_dir, 'JUPYTER_SERVER_URL': connection_url, }, ) terminal_manager.log = app_log base_url = webapp.settings['base_url'] handlers = [ (ujoin(base_url, r"/terminals/(\w+)"), TerminalHandler), (ujoin(base_url, r"/terminals/websocket/(\w+)"), TermSocket, { 'term_manager': terminal_manager }), (ujoin(base_url, r"/api/terminals"), api_handlers.TerminalRootHandler), (ujoin(base_url, r"/api/terminals/(\w+)"), api_handlers.TerminalHandler), ] webapp.add_handlers(".*$", handlers)
def initialize(webapp, notebook_dir, connection_url, settings): if os.name == 'nt': default_shell = 'powershell.exe' else: # The SHELL value could be inherited from a user who starts Jupyter Notebook, such as root or nginx, # with possibly non-standard SHELL setting. So the script should explicitly query the /etc/passwd instead import pwd default_shell = pwd.getpwuid(os.getuid()).pw_shell shell = settings.get('shell_command', [os.environ.get('SHELL') or default_shell] ) # Enable login mode - to automatically source the /etc/profile script if os.name != 'nt': shell.append('-l') terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager( shell_command=shell, extra_env={'JUPYTER_SERVER_ROOT': notebook_dir, 'JUPYTER_SERVER_URL': connection_url, }, ) terminal_manager.log = app_log base_url = webapp.settings['base_url'] handlers = [ (ujoin(base_url, r"/terminals/(\w+)"), TerminalHandler), (ujoin(base_url, r"/terminals/websocket/(\w+)"), TermSocket, {'term_manager': terminal_manager}), (ujoin(base_url, r"/api/terminals"), api_handlers.TerminalRootHandler), (ujoin(base_url, r"/api/terminals/(\w+)"), api_handlers.TerminalHandler), ] webapp.add_handlers(".*$", handlers)
def initialize(webapp, root_dir, connection_url, settings): if os.name == "nt": default_shell = "powershell.exe" else: default_shell = which("sh") shell = settings.get("shell_command", [os.environ.get("SHELL") or default_shell]) # Enable login mode - to automatically source the /etc/profile script if os.name != "nt": shell.append("-l") terminal_manager = webapp.settings["terminal_manager"] = NamedTermManager( shell_command=shell, extra_env={ "JUPYTER_SERVER_ROOT": root_dir, "JUPYTER_SERVER_URL": connection_url, }, ) terminal_manager.log = app_log base_url = webapp.settings["base_url"] handlers = [ (ujoin(base_url, r"/terminals/(\w+)"), TerminalHandler), ( ujoin(base_url, r"/terminals/websocket/(\w+)"), TermSocket, {"term_manager": terminal_manager}, ), (ujoin(base_url, r"/api/terminals"), api_handlers.TerminalRootHandler), (ujoin(base_url, r"/api/terminals/(\w+)"), api_handlers.TerminalHandler), ] webapp.add_handlers(".*$", handlers)
def initialize(webapp, root_dir, connection_url, settings): if os.name == 'nt': default_shell = 'powershell.exe' else: default_shell = which('sh') shell_override = settings.get('shell_command') shell = ( [os.environ.get('SHELL') or default_shell] if shell_override is None else shell_override ) # When the notebook server is not running in a terminal (e.g. when # it's launched by a JupyterHub spawner), it's likely that the user # environment hasn't been fully set up. In that case, run a login # shell to automatically source /etc/profile and the like, unless # the user has specifically set a preferred shell command. if os.name != 'nt' and shell_override is None and not sys.stdout.isatty(): shell.append('-l') terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager( shell_command=shell, extra_env={'JUPYTER_SERVER_ROOT': root_dir, 'JUPYTER_SERVER_URL': connection_url, }, ) terminal_manager.log = app_log base_url = webapp.settings['base_url'] handlers = [ (ujoin(base_url, r"/terminals/websocket/(\w+)"), TermSocket, {'term_manager': terminal_manager}), (ujoin(base_url, r"/api/terminals"), api_handlers.TerminalRootHandler), (ujoin(base_url, r"/api/terminals/(\w+)"), api_handlers.TerminalHandler), ] webapp.add_handlers(".*$", handlers)
def initialize(webapp): shell = os.environ.get('SHELL', 'sh') terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager(shell_command=[shell]) base_url = webapp.settings['base_url'] handlers = [ (ujoin(base_url, r"/terminals/(\w+)"), TerminalHandler), (ujoin(base_url, r"/terminals/websocket/(\w+)"), TermSocket, {'term_manager': terminal_manager}), (ujoin(base_url, r"/api/terminals"), api_handlers.TerminalRootHandler), (ujoin(base_url, r"/api/terminals/(\w+)"), api_handlers.TerminalHandler), ] webapp.add_handlers(".*$", handlers)
def main(): term_manager = NamedTermManager(shell_command=['bash'], max_terminals=100) ##logging.basicConfig(filename="config.log",filemode="a",format="%(asctime)s-%(name)s-%(levelname)s-%(message)s",level=logging.DEBUG) handlers = [(r"/_websocket/(\w+)", TermSocket, { 'term_manager': term_manager }), (r"/new", NewTerminalHandler), (r"/(\w+)/?", TerminalPageHandler), (r"/xstatic/(.*)", tornado_xstatic.XStaticFileHandler)] application = tornado.web.Application( handlers, static_path=STATIC_DIR, template_path=TEMPLATE_DIR, xstatic_url=tornado_xstatic.url_maker('/xstatic/'), term_manager=term_manager) application.listen(8700) run_and_show_browser("http://localhost:8700/new", term_manager)
def main(): term_manager = NamedTermManager(shell_command=['bash'], max_terminals=100) handlers = [(r"/_websocket/(\w+)", TermSocket, { 'term_manager': term_manager }), (r"/new/?", NewTerminalHandler), (r"/(\w+)/?", TerminalPageHandler), (r"/xstatic/(.*)", tornado_xstatic.XStaticFileHandler)] application = tornado.web.Application( handlers, static_path=STATIC_DIR, template_path=TEMPLATE_DIR, xstatic_url=tornado_xstatic.url_maker('/xstatic/'), term_manager=term_manager) application.listen(8700, 'localhost') run_and_show_browser("http://localhost:8700/new", term_manager)
def initialize(webapp, notebook_dir, connection_url, settings): # remove existing terminal web handlers for host_rule in webapp.default_router.rules: if not hasattr(host_rule.matcher, "host_pattern"): continue if host_rule.matcher.host_pattern.pattern != ".*$": continue new_rules = [] for path_rule in host_rule.target.rules: if not hasattr(path_rule.matcher, "regex"): continue pattern = path_rule.matcher.regex.pattern if pattern.find("/terminals/" ) == -1 and not pattern.endswith("/terminals$"): new_rules.append(path_rule) host_rule.target.rules = new_rules if os.name == "nt": default_shell = "powershell.exe" else: default_shell = which("sh") shell = settings.get("shell_command", [os.environ.get("SHELL") or default_shell]) if os.name != "nt": shell.append("-l") terminal_manager = webapp.settings["terminal_manager"] = NamedTermManager( shell_command=shell, extra_env={ "JUPYTER_SERVER_ROOT": notebook_dir, "JUPYTER_SERVER_URL": connection_url, }, ) terminal_manager.log = app_log base_url = webapp.settings["base_url"] new_handlers = [ (ujoin(base_url, r"/terminals/([^/]+)"), TerminalHandler), (ujoin(base_url, r"/terminals/websocket/([^/]+)"), term_handlers.TermSocket, { "term_manager": terminal_manager }), (ujoin(base_url, r"/api/terminals"), APITerminalRootHandler), (ujoin(base_url, r"/api/terminals/([^/]+)"), APITerminalHandler), (ujoin(base_url, r"/terminal_extension"), TerminalExtensionHandler), ] webapp.add_handlers(".*$", new_handlers)
def initialize(webapp, notebook_dir, connection_url): shell = os.environ.get('SHELL') or 'sh' terminal_manager = webapp.settings['terminal_manager'] = NamedTermManager( shell_command=[shell], extra_env={'JUPYTER_SERVER_ROOT': notebook_dir, 'JUPYTER_SERVER_URL': connection_url, }, ) terminal_manager.log = app_log base_url = webapp.settings['base_url'] handlers = [ (ujoin(base_url, r"/terminals/(\w+)"), TerminalHandler), (ujoin(base_url, r"/terminals/websocket/(\w+)"), TermSocket, {'term_manager': terminal_manager}), (ujoin(base_url, r"/api/terminals"), api_handlers.TerminalRootHandler), (ujoin(base_url, r"/api/terminals/(\w+)"), api_handlers.TerminalHandler), ] webapp.add_handlers(".*$", handlers)
def main(): print("Starting") term_manager = NamedTermManager(shell_command=['zsh'], max_terminals=100) handlers = [(r"/_websocket/(\w+)", TermSocket, { 'term_manager': term_manager }), (r"/multi/?", MultiTerm), (r"/new/?", NewTerminalHandler), (r"/(\w+)/?", TerminalPageHandler), (r"/xstatic/(.*)", tornado_xstatic.XStaticFileHandler), (r"/static/(.*)", tornado.web.StaticFileHandler)] application = tornado.web.Application( handlers, static_path=STATIC_DIR, template_path=TEMPLATE_DIR, xstatic_url=tornado_xstatic.url_maker('/xstatic/'), term_manager=term_manager) application.listen(5001, '0.0.0.0') tornado.ioloop.IOLoop.current().start()