2014-10-27 16:29:04 -06:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
import platform
|
|
|
|
import os
|
|
|
|
import sys
|
2015-01-18 17:19:39 -06:00
|
|
|
import logging
|
2014-10-27 16:29:04 -06:00
|
|
|
from platform_utils import paths as paths_
|
|
|
|
|
|
|
|
from functools import wraps
|
|
|
|
|
2016-01-19 12:52:09 -06:00
|
|
|
mode = "portable"
|
2014-10-27 16:29:04 -06:00
|
|
|
directory = None
|
|
|
|
|
2015-01-18 17:19:39 -06:00
|
|
|
log = logging.getLogger("paths")
|
|
|
|
|
2014-10-27 16:29:04 -06:00
|
|
|
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":
|
2015-10-24 16:01:23 -05:00
|
|
|
path = data_path(u"config")
|
2014-10-27 16:29:04 -06:00
|
|
|
if not os.path.exists(path):
|
2015-01-18 17:19:39 -06:00
|
|
|
log.debug("%s path does not exist, creating..." % (path,))
|
2014-10-27 16:29:04 -06:00
|
|
|
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":
|
2015-10-24 16:01:23 -05:00
|
|
|
path = data_path(u"logs")
|
2014-10-27 16:29:04 -06:00
|
|
|
if not os.path.exists(path):
|
2015-01-18 17:19:39 -06:00
|
|
|
log.debug("%s path does not exist, creating..." % (path,))
|
2014-10-27 16:29:04 -06:00
|
|
|
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":
|
2015-12-09 10:05:17 -06:00
|
|
|
import winpaths
|
|
|
|
data_path = os.path.join(winpaths.get_appdata(), app_name)
|
2014-10-27 16:29:04 -06:00
|
|
|
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():
|
2016-05-08 04:54:10 -05:00
|
|
|
return app_path(u"sounds")
|
|
|
|
|
|
|
|
@merge_paths
|
|
|
|
def com_path():
|
|
|
|
global mode, directory
|
|
|
|
if mode == "portable":
|
|
|
|
if directory != None: path = os.path.join(directory, "com_cache")
|
|
|
|
elif directory == None: path = app_path(u"com_cache")
|
|
|
|
elif mode == "installed":
|
|
|
|
path = data_path(u"com_cache")
|
|
|
|
if not os.path.exists(path):
|
|
|
|
log.debug("%s path does not exist, creating..." % (path,))
|
|
|
|
os.mkdir(path)
|
|
|
|
return path
|