##// END OF EJS Templates
Command line entry point to list running notebook servers
Thomas Kluyver -
Show More
@@ -214,6 +214,27 b' class NotebookWebApplication(web.Application):'
214 return new_handlers
214 return new_handlers
215
215
216
216
217 class NbserverListApp(BaseIPythonApplication):
218
219 description="List currently running notebook servers in this profile."
220
221 flags = dict(
222 json=({'NbserverListApp': {'json': True}},
223 "Produce machine-readable JSON output."),
224 )
225
226 json = Bool(False, config=True,
227 help="If True, each line of output will be a JSON object with the "
228 "details from the server info file.")
229
230 def start(self):
231 if not self.json:
232 print("Currently running servers:")
233 for serverinfo in discover_running_servers(self.profile):
234 if self.json:
235 print(json.dumps(serverinfo))
236 else:
237 print(serverinfo['url'], "::", serverinfo['notebookdir'])
217
238
218 #-----------------------------------------------------------------------------
239 #-----------------------------------------------------------------------------
219 # Aliases and Flags
240 # Aliases and Flags
@@ -286,6 +307,10 b' class NotebookApp(BaseIPythonApplication):'
286 FileNotebookManager]
307 FileNotebookManager]
287 flags = Dict(flags)
308 flags = Dict(flags)
288 aliases = Dict(aliases)
309 aliases = Dict(aliases)
310
311 subcommands = dict(
312 list=(NbserverListApp, NbserverListApp.description.splitlines()[0]),
313 )
289
314
290 kernel_argv = List(Unicode)
315 kernel_argv = List(Unicode)
291
316
@@ -746,6 +771,9 b' class NotebookApp(BaseIPythonApplication):'
746
771
747 This method takes no arguments so all configuration and initialization
772 This method takes no arguments so all configuration and initialization
748 must be done prior to calling this method."""
773 must be done prior to calling this method."""
774 if self.subapp is not None:
775 return self.subapp.start()
776
749 info = self.log.info
777 info = self.log.info
750 for line in self.notebook_info().split("\n"):
778 for line in self.notebook_info().split("\n"):
751 info(line)
779 info(line)
@@ -789,7 +817,7 b' class NotebookApp(BaseIPythonApplication):'
789 self.remove_server_info_file()
817 self.remove_server_info_file()
790
818
791
819
792 def discover_running_servers(profile='default'):
820 def list_running_servers(profile='default'):
793 """Iterate over the server info files of running notebook servers.
821 """Iterate over the server info files of running notebook servers.
794
822
795 Given a profile name, find nbserver-* files in the security directory of
823 Given a profile name, find nbserver-* files in the security directory of
@@ -27,7 +27,7 b' def test_help_output():'
27 def test_server_info_file():
27 def test_server_info_file():
28 nbapp = notebookapp.NotebookApp(profile='nbserver_file_test')
28 nbapp = notebookapp.NotebookApp(profile='nbserver_file_test')
29 def get_servers():
29 def get_servers():
30 return list(notebookapp.discover_running_servers(profile='nbserver_file_test'))
30 return list(notebookapp.list_running_servers(profile='nbserver_file_test'))
31 nbapp.initialize(argv=[])
31 nbapp.initialize(argv=[])
32 nbapp.write_server_info_file()
32 nbapp.write_server_info_file()
33 servers = get_servers()
33 servers = get_servers()
General Comments 0
You need to be logged in to leave comments. Login now