From cdea75836013f54183bb8b8e88baf383ff55c066 Mon Sep 17 00:00:00 2001 From: Bill Dengler Date: Tue, 25 Jul 2017 19:05:14 +0000 Subject: [PATCH] #148: Store user config in temporary OS storage. --- src/controller/mainController.py | 2 +- src/paths.py | 28 +++++++++++++++++----------- src/sessionmanager/manager.py | 2 +- src/sessionmanager/session.py | 8 ++++---- 4 files changed, 23 insertions(+), 17 deletions(-) diff --git a/src/controller/mainController.py b/src/controller/mainController.py index 8828fa0e..2fac285b 100644 --- a/src/controller/mainController.py +++ b/src/controller/mainController.py @@ -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() diff --git a/src/paths.py b/src/paths.py index 373f0876..873f9961 100644 --- a/src/paths.py +++ b/src/paths.py @@ -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") diff --git a/src/sessionmanager/manager.py b/src/sessionmanager/manager.py index 3c9dda23..f72f211d 100644 --- a/src/sessionmanager/manager.py +++ b/src/sessionmanager/manager.py @@ -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) diff --git a/src/sessionmanager/session.py b/src/sessionmanager/session.py index f376fdb2..26aeea38 100644 --- a/src/sessionmanager/session.py +++ b/src/sessionmanager/session.py @@ -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()