diff src/memory/memory.py @ 1045:65fffdcb97f1

memory: auto-update configuration file with libervia's passphrase when migrating the database
author souliane <souliane@mailoo.org>
date Fri, 23 May 2014 09:59:15 +0200
parents 15f43b54d697
children a874a79ad0f5
line wrap: on
line diff
--- a/src/memory/memory.py	Wed May 21 23:17:51 2014 +0200
+++ b/src/memory/memory.py	Fri May 23 09:59:15 2014 +0200
@@ -21,7 +21,6 @@
 
 import os.path
 import csv
-from xdg import BaseDirectory
 from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError
 from uuid import uuid4
 from sat.core.log import getLogger
@@ -35,6 +34,7 @@
 from sat.memory.params import Params
 from sat.memory.disco import Discovery
 from sat.memory.crypto import BlockCipher
+from sat.tools.config import fixConfigOption
 
 
 class Sessions(object):
@@ -180,25 +180,7 @@
     if os.path.isfile(os.path.expanduser(old_default) + '/' + C.SAVEFILE_DATABASE):
         if not silent:
             log.warning(_("A database has been found in the default local_dir for previous versions (< 0.5)"))
-        config = SafeConfigParser()
-        target_file = None
-        for file_ in C.CONFIG_FILES[::-1]:
-            # we will eventually update the existing file with the highest priority, if it's a user personal file...
-            if not silent:
-                log.debug(_("Testing file %s") % file_)
-            if os.path.isfile(file_):
-                if file_.startswith(os.path.expanduser('~')):
-                    config.read([file_])
-                    target_file = file_
-                break
-        if not target_file:
-            # ... otherwise we create a new config file for that user
-            target_file = BaseDirectory.save_config_path('sat') + '/sat.conf'
-        config.set('', 'local_dir', old_default)
-        with open(target_file, 'wb') as configfile:
-            config.write(configfile)  # for the next time that user launches sat
-        if not silent:
-            log.warning(_("Auto-update: local_dir set to %(path)s in the file %(config_file)s") % {'path': old_default, 'config_file': target_file})
+        fixConfigOption('', 'local_dir', old_default)
 
 
 class Memory(object):