twblue/src/paths.py

68 lines
2.0 KiB
Python
Raw Normal View History

# -*- coding: utf-8 -*-
2019-06-06 11:52:23 -05:00
import sys
import platform
import os
2019-06-06 11:52:23 -05:00
import glob
from platform_utils import paths as paths_
mode = "portable"
directory = None
2019-06-06 11:52:23 -05:00
fsencoding = sys.getfilesystemencoding()
2019-06-06 11:52:23 -05:00
if len(glob.glob("Uninstall.exe")) > 0: # installed copy
mode= "installed"
def app_path():
return paths_.app_path()
def config_path():
global mode, directory
if mode == "portable":
if directory != None: path = os.path.join(directory, "config")
elif directory == None: path = os.path.join(app_path(), "config")
elif mode == "installed":
path = os.path.join(data_path(), "config")
if not os.path.exists(path):
# log.debug("%s path does not exist, creating..." % (path,))
os.mkdir(path)
return path
def logs_path():
global mode, directory
if mode == "portable":
if directory != None: path = os.path.join(directory, "logs")
elif directory == None: path = os.path.join(app_path(), "logs")
elif mode == "installed":
path = os.path.join(data_path(), "logs")
if not os.path.exists(path):
# log.debug("%s path does not exist, creating..." % (path,))
os.mkdir(path)
return path
def data_path(app_name='TW Blue'):
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
def locale_path():
return os.path.join(app_path(), "locales")
def sound_path():
return os.path.join(app_path(), "sounds")
def com_path():
global mode, directory
if mode == "portable":
if directory != None: path = os.path.join(directory, "com_cache")
elif directory == None: path = os.path.join(app_path(), "com_cache")
elif mode == "installed":
path = os.path.join(data_path(), "com_cache")
if not os.path.exists(path):
# log.debug("%s path does not exist, creating..." % (path,))
os.mkdir(path)
return path