From 53f809d40742935ca856a2cf1f6d0acd4989bb39 Mon Sep 17 00:00:00 2001 From: Min RK Date: Tue, 3 Jan 2017 14:50:56 +0100 Subject: [PATCH] use a warning for failure to set file permissions instead of print --- notebook/auth/security.py | 9 +++++---- notebook/notebookapp.py | 4 +++- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/notebook/auth/security.py b/notebook/auth/security.py index 7441d5409..8f69148ee 100644 --- a/notebook/auth/security.py +++ b/notebook/auth/security.py @@ -9,8 +9,8 @@ import io import json import os import random -import sys import traceback +import warnings from ipython_genutils.py3compat import cast_bytes, str_to_bytes, cast_unicode from traitlets.config import Config, ConfigFileNotFound, JSONFileConfigLoader @@ -133,9 +133,10 @@ def persist_config(config_file=None, mode=0o600): try: os.chmod(config_file, mode) - except Exception: - print("Failed to set permissions on %s:" % config_file, file=sys.stderr) - traceback.print_exc(file=sys.stderr) + except Exception as e: + tb = traceback.format_exc() + warnings.warn("Failed to set permissions on %s:\n%s" % (config_file, tb), + RuntimeWarning) def set_password(password=None, config_file=None): diff --git a/notebook/notebookapp.py b/notebook/notebookapp.py index 82b68c5dd..ed14daa5c 100755 --- a/notebook/notebookapp.py +++ b/notebook/notebookapp.py @@ -331,9 +331,11 @@ class NotebookPasswordApp(JupyterApp): and removes the need for token-based authentication. """ + description = __doc__ + def _config_file_default(self): return os.path.join(self.config_dir, 'jupyter_notebook_config.json') - description = __doc__ + def start(self): from .auth.security import set_password set_password(config_file=self.config_file)