mirror of
https://github.com/MCV-Software/TWBlue.git
synced 2026-02-13 00:37:33 +01:00
Putting all the code from the current master branch of TWBlue
This commit is contained in:
66
src/paths.py
Normal file
66
src/paths.py
Normal file
@@ -0,0 +1,66 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
import platform
|
||||
import os
|
||||
import sys
|
||||
from platform_utils import paths as paths_
|
||||
|
||||
from functools import wraps
|
||||
|
||||
mode = None
|
||||
directory = None
|
||||
|
||||
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):
|
||||
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):
|
||||
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")
|
||||
Reference in New Issue
Block a user