diff --git a/spyderlib/app/cli_options.py b/spyderlib/app/cli_options.py index b0597f6957a..d864ae3caac 100644 --- a/spyderlib/app/cli_options.py +++ b/spyderlib/app/cli_options.py @@ -20,7 +20,7 @@ def get_options(): parser.add_option('--defaults', dest="reset_to_defaults", action='store_true', default=False, help="Reset configuration settings to defaults") - parser.add_option('--reset', dest="reset_session", + parser.add_option('--reset', dest="reset_config_files", action='store_true', default=False, help="Remove all configuration files!") parser.add_option('--optimize', action='store_true', default=False, diff --git a/spyderlib/app/spyder.py b/spyderlib/app/spyder.py index dc2a9d508a1..2508a1f286e 100644 --- a/spyderlib/app/spyder.py +++ b/spyderlib/app/spyder.py @@ -128,7 +128,8 @@ from spyderlib.config.base import (get_conf_path, get_module_data_path, get_module_source_path, STDERR, DEBUG, debug_print, MAC_APP_NAME, - running_in_mac_app, get_module_path) + running_in_mac_app, get_module_path, + reset_config_files) from spyderlib.config.main import CONF, OPEN_FILES_PORT from spyderlib.config.utils import IMPORT_EXT, is_gtk_desktop from spyderlib.app.cli_options import get_options @@ -139,7 +140,7 @@ from spyderlib.utils import encoding, programs from spyderlib.utils import icon_manager as ima from spyderlib.utils.introspection import module_completion -from spyderlib.utils.iofuncs import load_session, save_session, reset_session +from spyderlib.utils.iofuncs import load_session, save_session from spyderlib.utils.programs import is_module_installed from spyderlib.utils.misc import select_port @@ -3016,16 +3017,15 @@ def main(): options, args = get_options() if set_attached_console_visible is not None: - set_attached_console_visible(DEBUG or options.show_console\ - or options.reset_session\ - or options.reset_to_defaults\ + set_attached_console_visible(DEBUG or options.show_console \ + or options.reset_config_files \ + or options.reset_to_defaults \ or options.optimize) app = initialize() - if options.reset_session: + if options.reset_config_files: # Remove all configuration files! - reset_session() -# CONF.reset_to_defaults(save=True) + reset_config_files() return elif options.reset_to_defaults: # Reset Spyder settings to defaults diff --git a/spyderlib/app/start.py b/spyderlib/app/start.py index 5a25ff49399..4b4848bd8b9 100644 --- a/spyderlib/app/start.py +++ b/spyderlib/app/start.py @@ -72,7 +72,7 @@ def main(): os.environ['SPYDER_ARGS'] = str(sys.argv[1:]) if CONF.get('main', 'single_instance') and not options.new_instance \ - and not running_in_mac_app(): + and not options.reset_config_files and not running_in_mac_app(): # Minimal delay (0.1-0.2 secs) to avoid that several # instances started at the same time step in their # own foots while trying to create the lock file diff --git a/spyderlib/config/base.py b/spyderlib/config/base.py index fb7891419ca..1aaabe7fa0f 100644 --- a/spyderlib/config/base.py +++ b/spyderlib/config/base.py @@ -18,6 +18,7 @@ import locale import os.path as osp import os +import shutil import sys # Local imports @@ -63,6 +64,7 @@ def debug_print(*message): else: print(*message, file=ss) + #============================================================================== # Configuration paths #============================================================================== @@ -189,7 +191,6 @@ def is_py2exe_or_cx_Freeze(): #============================================================================== # Image path list #============================================================================== - IMG_PATH = [] def add_image_path(path): if not osp.isdir(path): @@ -346,7 +347,6 @@ def translate_dumb(x): #============================================================================== # Namespace Browser (Variable Explorer) configuration management #============================================================================== - def get_supported_types(): """ Return a dictionnary containing types lists supported by the @@ -391,10 +391,10 @@ def get_supported_types(): 'Inf', 'Infinity', 'sctypes', 'rcParams', 'rcParamsDefault', 'sctypeNA', 'typeNA', 'False_', 'True_',] + #============================================================================== # Mac application utilities #============================================================================== - if PY3: MAC_APP_NAME = 'Spyder.app' else: @@ -405,3 +405,28 @@ def running_in_mac_app(): return True else: return False + + +#============================================================================== +# Reset config files +#============================================================================== +SAVED_CONFIG_FILES = ('help', 'onlinehelp', 'path', 'pylint.results', + 'spyder.ini', 'temp.py', 'temp.spydata', 'template.py', + 'history.py', 'history_internal.py', 'workingdir', + '.projects', '.spyderproject', '.ropeproject', + 'monitor.log', 'monitor_debug.log', 'rope.log', + 'langconfig', 'spyder.lock') + + +def reset_config_files(): + """Remove all config files""" + print("*** Reset Spyder settings to defaults ***", file=STDERR) + for fname in SAVED_CONFIG_FILES: + cfg_fname = get_conf_path(fname) + if osp.isfile(cfg_fname) or osp.islink(cfg_fname): + os.remove(cfg_fname) + elif osp.isdir(cfg_fname): + shutil.rmtree(cfg_fname) + else: + continue + print("removing:", cfg_fname, file=STDERR) diff --git a/spyderlib/utils/iofuncs.py b/spyderlib/utils/iofuncs.py index 7260631c4f9..da4a9e4804a 100644 --- a/spyderlib/utils/iofuncs.py +++ b/spyderlib/utils/iofuncs.py @@ -33,6 +33,7 @@ pd = None #analysis:ignore # Local imports +from spyderlib.config.base import get_conf_path from spyderlib.py3compat import pickle, to_text_string, getcwd, PY2 @@ -371,29 +372,6 @@ def load_dictionary(filename): return data, error_message -from spyderlib.config.base import get_conf_path, STDERR - -SAVED_CONFIG_FILES = ('help', 'onlinehelp', 'path', 'pylint.results', - 'spyder.ini', 'temp.py', 'temp.spydata', 'template.py', - 'history.py', 'history_internal.py', 'workingdir', - '.projects', '.spyderproject', '.ropeproject', - 'monitor.log', 'monitor_debug.log', 'rope.log', - 'langconfig') - -def reset_session(): - """Remove all config files""" - print("*** Reset Spyder settings to defaults ***", file=STDERR) - for fname in SAVED_CONFIG_FILES: - cfg_fname = get_conf_path(fname) - if osp.isfile(cfg_fname): - os.remove(cfg_fname) - elif osp.isdir(cfg_fname): - shutil.rmtree(cfg_fname) - else: - continue - print("removing:", cfg_fname, file=STDERR) - - def save_session(filename): """Save Spyder session""" local_fname = get_conf_path(osp.basename(filename))