socializer/src/paths.py

71 lines
2.1 KiB
Python
Raw Normal View History

2016-02-13 17:06:36 -06:00
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
import sys
2016-02-13 17:06:36 -06:00
import platform
import os
import sys
2016-06-29 17:21:00 -05:00
#import logging
2016-02-13 17:06:36 -06:00
from platform_utils import paths as paths_
from functools import wraps
mode = "portable"
directory = None
fsencoding = sys.getfilesystemencoding()
2016-02-13 17:06:36 -06:00
2016-06-29 17:21:00 -05:00
#log = logging.getLogger("paths")
2016-02-13 17:06:36 -06:00
def app_path():
return paths_.app_path()
def config_path():
global mode, directory
if mode == "portable":
if directory != None: path = os.path.join(directory.decode(fsencoding), "config")
elif directory == None: path = os.path.join(app_path().decode(fsencoding), "config")
2016-02-13 17:06:36 -06:00
elif mode == "installed":
path = os.path.join(data_path().decode(fsencoding), "config")
2016-02-13 17:06:36 -06:00
if not os.path.exists(path):
2016-06-29 17:21:00 -05:00
# log.debug("%s path does not exist, creating..." % (path,))
2016-02-13 17:06:36 -06:00
os.mkdir(path)
return path
def logs_path():
global mode, directory
if mode == "portable":
if directory != None: path = os.path.join(directory.decode(fsencoding), "logs")
elif directory == None: path = os.path.join(app_path().decode(fsencoding), "logs")
2016-02-13 17:06:36 -06:00
elif mode == "installed":
path = os.path.join(data_path().decode(fsencoding), "logs")
2016-02-13 17:06:36 -06:00
if not os.path.exists(path):
2016-06-29 17:21:00 -05:00
# log.debug("%s path does not exist, creating..." % (path,))
2016-02-13 17:06:36 -06:00
os.mkdir(path)
return path
def data_path(app_name='socializer'):
2016-02-13 17:06:36 -06:00
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().decode(fsencoding), "locales")
2016-02-13 17:06:36 -06:00
def sound_path():
return os.path.join(app_path().decode(fsencoding), "sounds")
2016-06-02 17:42:44 -05:00
def com_path():
global mode, directory
if mode == "portable":
if directory != None: path = os.path.join(directory.decode(fsencoding), "com_cache")
elif directory == None: path = os.path.join(app_path().decode(fsencoding), "com_cache")
2016-06-02 17:42:44 -05:00
elif mode == "installed":
path = os.path.join(data_path().decode(fsencoding), "com_cache")
2016-06-02 17:42:44 -05:00
if not os.path.exists(path):
2016-06-29 17:21:00 -05:00
# log.debug("%s path does not exist, creating..." % (path,))
2016-06-02 17:42:44 -05:00
os.mkdir(path)
return path