mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2025-04-20 09:31:43 -04:00
#148: Store user config in temporary OS storage.
This commit is contained in:
parent
277cb433ef
commit
cdea758360
@ -651,7 +651,7 @@ class Controller(object):
|
|||||||
log.debug("Shelving database for " + session_.sessions[item].session_id)
|
log.debug("Shelving database for " + session_.sessions[item].session_id)
|
||||||
session_.sessions[item].shelve()
|
session_.sessions[item].shelve()
|
||||||
if config.app['app-settings']['paranoid']:
|
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":
|
if system == "Windows":
|
||||||
self.systrayIcon.RemoveIcon()
|
self.systrayIcon.RemoveIcon()
|
||||||
widgetUtils.exit_application()
|
widgetUtils.exit_application()
|
||||||
|
28
src/paths.py
28
src/paths.py
@ -4,29 +4,35 @@ import platform
|
|||||||
import os
|
import os
|
||||||
import sys
|
import sys
|
||||||
import logging
|
import logging
|
||||||
|
import tempfile
|
||||||
from platform_utils import paths as paths_
|
from platform_utils import paths as paths_
|
||||||
|
|
||||||
from functools import wraps
|
from functools import wraps
|
||||||
|
|
||||||
mode = "portable"
|
mode = "portable"
|
||||||
directory = None
|
directory = None
|
||||||
|
paranoidpath = None
|
||||||
log = logging.getLogger("paths")
|
log = logging.getLogger("paths")
|
||||||
|
|
||||||
def merge_paths(func):
|
def merge_paths(func):
|
||||||
@wraps(func)
|
@wraps(func)
|
||||||
def merge_paths_wrapper(*a):
|
def merge_paths_wrapper(*a,paranoid=False):
|
||||||
return str(os.path.join(func(), *a))
|
return str(os.path.join(func(paranoid=paranoid), *a))
|
||||||
return merge_paths_wrapper
|
return merge_paths_wrapper
|
||||||
|
|
||||||
@merge_paths
|
@merge_paths
|
||||||
def app_path():
|
def app_path(paranoid=False):
|
||||||
return paths_.app_path()
|
return paths_.app_path()
|
||||||
|
|
||||||
@merge_paths
|
@merge_paths
|
||||||
def config_path():
|
def config_path(paranoid=False):
|
||||||
global mode, directory
|
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")
|
if directory != None: path = os.path.join(directory, "config")
|
||||||
elif directory == None: path = app_path("config")
|
elif directory == None: path = app_path("config")
|
||||||
elif mode == "installed":
|
elif mode == "installed":
|
||||||
@ -37,7 +43,7 @@ def config_path():
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
@merge_paths
|
@merge_paths
|
||||||
def logs_path():
|
def logs_path(paranoid=False):
|
||||||
global mode, directory
|
global mode, directory
|
||||||
if mode == "portable":
|
if mode == "portable":
|
||||||
if directory != None: path = os.path.join(directory, "logs")
|
if directory != None: path = os.path.join(directory, "logs")
|
||||||
@ -50,7 +56,7 @@ def logs_path():
|
|||||||
return path
|
return path
|
||||||
|
|
||||||
@merge_paths
|
@merge_paths
|
||||||
def data_path(app_name='TW blue'):
|
def data_path(app_name='TW blue',paranoid=False):
|
||||||
# if platform.system() == "Windows":
|
# if platform.system() == "Windows":
|
||||||
# import shlobj
|
# import shlobj
|
||||||
# data_path = os.path.join(shlobj.SHGetFolderPath(0, shlobj.CSIDL_APPDATA), app_name)
|
# 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
|
return data_path
|
||||||
|
|
||||||
@merge_paths
|
@merge_paths
|
||||||
def locale_path():
|
def locale_path(paranoid=False):
|
||||||
return app_path("locales")
|
return app_path("locales")
|
||||||
|
|
||||||
@merge_paths
|
@merge_paths
|
||||||
def sound_path():
|
def sound_path(paranoid=False):
|
||||||
return app_path("sounds")
|
return app_path("sounds")
|
||||||
|
|
||||||
@merge_paths
|
@merge_paths
|
||||||
def com_path():
|
def com_path(paranoid=False):
|
||||||
global mode, directory
|
global mode, directory
|
||||||
if mode == "portable":
|
if mode == "portable":
|
||||||
if directory != None: path = os.path.join(directory, "com_cache")
|
if directory != None: path = os.path.join(directory, "com_cache")
|
||||||
|
@ -32,7 +32,7 @@ class sessionManager(object):
|
|||||||
|
|
||||||
def add_session(self, id):
|
def add_session(self, id):
|
||||||
log.debug("Adding a new session: %s" % (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):
|
if not os.path.exists(path):
|
||||||
log.debug("Creating %s path" % (paths.config_path(path),))
|
log.debug("Creating %s path" % (paths.config_path(path),))
|
||||||
os.mkdir(path)
|
os.mkdir(path)
|
||||||
|
@ -130,10 +130,10 @@ class Session(object):
|
|||||||
|
|
||||||
""" Gets settings for a session."""
|
""" Gets settings for a session."""
|
||||||
|
|
||||||
file_ = "%s/session.conf" % (self.session_id,)
|
file_ = os.path.join(self.session_id,"session.conf")
|
||||||
# try:
|
# try:
|
||||||
log.debug("Creating config file %s" % (file_,))
|
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.init_sound()
|
||||||
self.deshelve()
|
self.deshelve()
|
||||||
# except:
|
# except:
|
||||||
@ -434,13 +434,13 @@ class Session(object):
|
|||||||
|
|
||||||
def deshelve(self):
|
def deshelve(self):
|
||||||
"Import a shelved database."
|
"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 self.settings["general"]["persist_size"] == 0:
|
||||||
if os.path.exists(shelfname):
|
if os.path.exists(shelfname):
|
||||||
os.remove(shelfname)
|
os.remove(shelfname)
|
||||||
return
|
return
|
||||||
try:
|
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()):
|
for key,value in list(shelf.items()):
|
||||||
self.db[key]=value
|
self.db[key]=value
|
||||||
shelf.close()
|
shelf.close()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user