##// END OF EJS Templates
Remove old config files on startup if they match the default (i.e. were never modified by the user)
Thomas Kluyver -
Show More
@@ -16,6 +16,7 b' Utilities for path handling.'
16 16
17 17 import os
18 18 import sys
19 from hashlib import md5
19 20
20 21 import IPython
21 22 from IPython.utils import warn
@@ -402,6 +403,18 b' def target_update(target,deps,cmd):'
402 403 if target_outdated(target,deps):
403 404 system(cmd)
404 405
406 def filehash(path):
407 """Make an MD5 hash of a file, ignoring any differences in line
408 ending characters."""
409 with open(path, "rU") as f:
410 return md5(f.read()).hexdigest()
411
412 # If the config is unmodified from the default, we'll just delete it.
413 # These are consistent for 0.10.x, thankfully. We're not going to worry about
414 # older versions.
415 old_config_md5 = {'ipy_user_conf.py': 'fc108bedff4b9a00f91fa0a5999140d3',
416 'ipythonrc': '12a68954f3403eea2eec09dc8fe5a9b5'}
417
405 418 def check_for_old_config(ipython_dir=None):
406 419 """Check for old config files, and present a warning if they exist.
407 420
@@ -418,8 +431,12 b' def check_for_old_config(ipython_dir=None):'
418 431 for cfg in old_configs:
419 432 f = os.path.join(ipython_dir, cfg)
420 433 if os.path.exists(f):
421 warned = True
422 warn.warn("Found old IPython config file %r"%f)
434 if filehash(f) == old_config_md5[cfg]:
435 os.unlink(f)
436 warn.info("Removed unmodified old IPython config file %r"%f)
437 else:
438 warned = True
439 warn.warn("Found old IPython config file %r (modified by user)"%f)
423 440
424 441 if warned:
425 442 warn.warn("""
General Comments 0
You need to be logged in to leave comments. Login now