memory: auto-update configuration file with libervia's passphrase when migrating the database

This commit is contained in:
souliane 2014-05-23 09:59:15 +02:00
commit c68b147398

View file

@ -21,7 +21,6 @@ from sat.core.i18n import _
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.persistent import PersistentDict
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 @@ def fixLocalDir(silent=True):
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):