comparison 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
comparison
equal deleted inserted replaced
1044:85c110c0be86 1045:65fffdcb97f1
19 19
20 from sat.core.i18n import _ 20 from sat.core.i18n import _
21 21
22 import os.path 22 import os.path
23 import csv 23 import csv
24 from xdg import BaseDirectory
25 from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError 24 from ConfigParser import SafeConfigParser, NoOptionError, NoSectionError
26 from uuid import uuid4 25 from uuid import uuid4
27 from sat.core.log import getLogger 26 from sat.core.log import getLogger
28 log = getLogger(__name__) 27 log = getLogger(__name__)
29 from twisted.internet import defer, reactor 28 from twisted.internet import defer, reactor
33 from sat.memory.sqlite import SqliteStorage 32 from sat.memory.sqlite import SqliteStorage
34 from sat.memory.persistent import PersistentDict 33 from sat.memory.persistent import PersistentDict
35 from sat.memory.params import Params 34 from sat.memory.params import Params
36 from sat.memory.disco import Discovery 35 from sat.memory.disco import Discovery
37 from sat.memory.crypto import BlockCipher 36 from sat.memory.crypto import BlockCipher
37 from sat.tools.config import fixConfigOption
38 38
39 39
40 class Sessions(object): 40 class Sessions(object):
41 """Sessions are data associated to key used for a temporary moment, with optional profile checking.""" 41 """Sessions are data associated to key used for a temporary moment, with optional profile checking."""
42 DEFAULT_TIMEOUT = 600 42 DEFAULT_TIMEOUT = 600
178 return # nothing to do 178 return # nothing to do
179 old_default = '~/.sat' 179 old_default = '~/.sat'
180 if os.path.isfile(os.path.expanduser(old_default) + '/' + C.SAVEFILE_DATABASE): 180 if os.path.isfile(os.path.expanduser(old_default) + '/' + C.SAVEFILE_DATABASE):
181 if not silent: 181 if not silent:
182 log.warning(_("A database has been found in the default local_dir for previous versions (< 0.5)")) 182 log.warning(_("A database has been found in the default local_dir for previous versions (< 0.5)"))
183 config = SafeConfigParser() 183 fixConfigOption('', 'local_dir', old_default)
184 target_file = None
185 for file_ in C.CONFIG_FILES[::-1]:
186 # we will eventually update the existing file with the highest priority, if it's a user personal file...
187 if not silent:
188 log.debug(_("Testing file %s") % file_)
189 if os.path.isfile(file_):
190 if file_.startswith(os.path.expanduser('~')):
191 config.read([file_])
192 target_file = file_
193 break
194 if not target_file:
195 # ... otherwise we create a new config file for that user
196 target_file = BaseDirectory.save_config_path('sat') + '/sat.conf'
197 config.set('', 'local_dir', old_default)
198 with open(target_file, 'wb') as configfile:
199 config.write(configfile) # for the next time that user launches sat
200 if not silent:
201 log.warning(_("Auto-update: local_dir set to %(path)s in the file %(config_file)s") % {'path': old_default, 'config_file': target_file})
202 184
203 185
204 class Memory(object): 186 class Memory(object):
205 """This class manage all persistent informations""" 187 """This class manage all persistent informations"""
206 188