#148: Store user config in temporary OS storage.

This commit is contained in:
Bill Dengler 2017-07-25 19:05:14 +00:00
parent 277cb433ef
commit cdea758360
4 changed files with 23 additions and 17 deletions

View File

@ -651,7 +651,7 @@ class Controller(object):
log.debug("Shelving database for " + session_.sessions[item].session_id)
session_.sessions[item].shelve()
if config.app['app-settings']['paranoid']:
shutil.rmtree(paths.config_path(session_.sessions[item].session_id))
shutil.rmtree(paths.config_path(session_.sessions[item].session_id,paranoid=config.app['app-settings']['paranoid']))
if system == "Windows":
self.systrayIcon.RemoveIcon()
widgetUtils.exit_application()

View File

@ -4,29 +4,35 @@ import platform
import os
import sys
import logging
import tempfile
from platform_utils import paths as paths_
from functools import wraps
mode = "portable"
directory = None
paranoidpath = None
log = logging.getLogger("paths")
def merge_paths(func):
@wraps(func)
def merge_paths_wrapper(*a):
return str(os.path.join(func(), *a))
def merge_paths_wrapper(*a,paranoid=False):
return str(os.path.join(func(paranoid=paranoid), *a))
return merge_paths_wrapper
@merge_paths
def app_path():
def app_path(paranoid=False):
return paths_.app_path()
@merge_paths
def config_path():
def config_path(paranoid=False):
global mode, directory
if mode == "portable":
if paranoid:
global paranoidpath
if not paranoidpath:
paranoidpath=tempfile.mkdtemp()
path = paranoidpath
elif mode == "portable":
if directory != None: path = os.path.join(directory, "config")
elif directory == None: path = app_path("config")
elif mode == "installed":
@ -37,7 +43,7 @@ def config_path():
return path
@merge_paths
def logs_path():
def logs_path(paranoid=False):
global mode, directory
if mode == "portable":
if directory != None: path = os.path.join(directory, "logs")
@ -50,7 +56,7 @@ def logs_path():
return path
@merge_paths
def data_path(app_name='TW blue'):
def data_path(app_name='TW blue',paranoid=False):
# if platform.system() == "Windows":
# import shlobj
# data_path = os.path.join(shlobj.SHGetFolderPath(0, shlobj.CSIDL_APPDATA), app_name)
@ -65,15 +71,15 @@ def data_path(app_name='TW blue'):
return data_path
@merge_paths
def locale_path():
def locale_path(paranoid=False):
return app_path("locales")
@merge_paths
def sound_path():
def sound_path(paranoid=False):
return app_path("sounds")
@merge_paths
def com_path():
def com_path(paranoid=False):
global mode, directory
if mode == "portable":
if directory != None: path = os.path.join(directory, "com_cache")

View File

@ -32,7 +32,7 @@ class sessionManager(object):
def add_session(self, id):
log.debug("Adding a new session: %s" % (id,))
path = paths.config_path(id)
path = paths.config_path(id,paranoid=config.app['app-settings']['paranoid'])
if not os.path.exists(path):
log.debug("Creating %s path" % (paths.config_path(path),))
os.mkdir(path)

View File

@ -130,10 +130,10 @@ class Session(object):
""" Gets settings for a session."""
file_ = "%s/session.conf" % (self.session_id,)
file_ = os.path.join(self.session_id,"session.conf")
# try:
log.debug("Creating config file %s" % (file_,))
self.settings = config_utils.load_config(paths.config_path(file_), paths.app_path("Conf.defaults"))
self.settings = config_utils.load_config(paths.config_path(file_,paranoid=config.app['app-settings']['paranoid']), paths.app_path("Conf.defaults"))
self.init_sound()
self.deshelve()
# except:
@ -434,13 +434,13 @@ class Session(object):
def deshelve(self):
"Import a shelved database."
shelfname=paths.config_path(str(self.session_id)+"/cache.db")
shelfname=paths.config_path(str(self.session_id)+"/cache.db",paranoid=config.app['app-settings']['paranoid'])
if self.settings["general"]["persist_size"] == 0:
if os.path.exists(shelfname):
os.remove(shelfname)
return
try:
shelf=shelve.open(paths.config_path(shelfname),'c')
shelf=shelve.open(paths.config_path(shelfname,paranoid=config.app['app-settings']['paranoid']),'c')
for key,value in list(shelf.items()):
self.db[key]=value
shelf.close()