socializer/src/paths.py

73 lines
2.0 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 glob
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")
if len(glob.glob("Uninstall.exe")) > 0: # installed copy
mode= "installed"
2016-02-13 17:06:36 -06:00
def app_path():
return paths_.app_path()
def config_path():
global mode, directory
if mode == "portable":
2019-01-01 19:42:53 -06:00
if directory != None: path = os.path.join(directory, "config")
elif directory == None: path = os.path.join(app_path(), "config")
2016-02-13 17:06:36 -06:00
elif mode == "installed":
2019-01-01 19:42:53 -06:00
path = os.path.join(data_path(), "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":
2019-01-01 19:42:53 -06:00
if directory != None: path = os.path.join(directory, "logs")
elif directory == None: path = os.path.join(app_path(), "logs")
2016-02-13 17:06:36 -06:00
elif mode == "installed":
2019-01-01 19:42:53 -06:00
path = os.path.join(data_path(), "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():
2019-01-01 19:42:53 -06:00
return os.path.join(app_path(), "locales")
2016-02-13 17:06:36 -06:00
def sound_path():
2019-01-01 19:42:53 -06:00
return os.path.join(app_path(), "sounds")
2016-06-02 17:42:44 -05:00
def com_path():
global mode, directory
if mode == "portable":
2019-01-01 19:42:53 -06:00
if directory != None: path = os.path.join(directory, "com_cache")
elif directory == None: path = os.path.join(app_path(), "com_cache")
2016-06-02 17:42:44 -05:00
elif mode == "installed":
2019-01-01 19:42:53 -06:00
path = os.path.join(data_path(), "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