mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2024-11-23 03:38:08 -06:00
71 lines
1.7 KiB
Python
71 lines
1.7 KiB
Python
# -*- coding: utf-8 -*-
|
|
import platform
|
|
import os
|
|
import sys
|
|
import logging
|
|
from platform_utils import paths as paths_
|
|
|
|
from functools import wraps
|
|
|
|
mode = None
|
|
directory = None
|
|
|
|
log = logging.getLogger("paths")
|
|
|
|
def merge_paths(func):
|
|
@wraps(func)
|
|
def merge_paths_wrapper(*a):
|
|
return unicode(os.path.join(func(), *a))
|
|
return merge_paths_wrapper
|
|
|
|
@merge_paths
|
|
def app_path():
|
|
return paths_.app_path()
|
|
|
|
@merge_paths
|
|
def config_path():
|
|
global mode, directory
|
|
if mode == "portable":
|
|
if directory != None: path = os.path.join(directory, "config")
|
|
elif directory == None: path = app_path(u"config")
|
|
elif mode == "installed":
|
|
path = data_path("config")
|
|
if not os.path.exists(path):
|
|
log.debug("%s path does not exist, creating..." % (path,))
|
|
os.mkdir(path)
|
|
return path
|
|
|
|
@merge_paths
|
|
def logs_path():
|
|
global mode, directory
|
|
if mode == "portable":
|
|
if directory != None: path = os.path.join(directory, "logs")
|
|
elif directory == None: path = app_path(u"logs")
|
|
elif mode == "installed":
|
|
path = data_path("logs")
|
|
if not os.path.exists(path):
|
|
log.debug("%s path does not exist, creating..." % (path,))
|
|
os.mkdir(path)
|
|
return path
|
|
|
|
@merge_paths
|
|
def data_path(app_name='TW blue'):
|
|
# if platform.system() == "Windows":
|
|
# import shlobj
|
|
# data_path = os.path.join(shlobj.SHGetFolderPath(0, shlobj.CSIDL_APPDATA), app_name)
|
|
# else:
|
|
if platform.system() == "Windows":
|
|
data_path = os.path.join(os.getenv("AppData"), app_name)
|
|
else:
|
|
data_path = os.path.join(os.environ['HOME'], ".%s" % app_name)
|
|
if not os.path.exists(data_path):
|
|
os.mkdir(data_path)
|
|
return data_path
|
|
|
|
@merge_paths
|
|
def locale_path():
|
|
return app_path(u"locales")
|
|
|
|
@merge_paths
|
|
def sound_path():
|
|
return app_path(u"sounds") |