Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Remove lock file as part of --reset #3357

Merged
merged 4 commits into from
Aug 17, 2016
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion spyderlib/app/cli_options.py
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
16 changes: 8 additions & 8 deletions spyderlib/app/spyder.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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

Expand Down Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion spyderlib/app/start.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
31 changes: 28 additions & 3 deletions spyderlib/config/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
import locale
import os.path as osp
import os
import shutil
import sys

# Local imports
Expand Down Expand Up @@ -63,6 +64,7 @@ def debug_print(*message):
else:
print(*message, file=ss)


#==============================================================================
# Configuration paths
#==============================================================================
Expand Down Expand Up @@ -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):
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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:
Expand All @@ -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)
24 changes: 1 addition & 23 deletions spyderlib/utils/iofuncs.py
Original file line number Diff line number Diff line change
Expand Up @@ -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


Expand Down Expand Up @@ -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))
Expand Down