You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

17 lines
556 B

4 years ago
  1. import os
  2. def get_server_root_dir(settings):
  3. # notebook >= 5.0.0 has this in the settings
  4. if 'server_root_dir' in settings:
  5. return settings['server_root_dir']
  6. # This copies the logic added in the notebook in
  7. # https://github.com/jupyter/notebook/pull/2234
  8. contents_manager = settings['contents_manager']
  9. root_dir = contents_manager.root_dir
  10. home = os.path.expanduser('~')
  11. if root_dir.startswith(home + os.path.sep):
  12. # collapse $HOME to ~
  13. root_dir = '~' + root_dir[len(home):]
  14. return root_dir