Handles non-english charset encoding for filesystem paths
This commit is contained in:
parent
7f2956e47a
commit
4b5d271ab4
@ -1,4 +1,5 @@
|
||||
# -*- coding: cp1252 -*-
|
||||
import os
|
||||
import config_utils
|
||||
import paths
|
||||
import logging
|
||||
@ -12,5 +13,5 @@ app = None
|
||||
def setup ():
|
||||
global app
|
||||
log.debug("Loading global app settings...")
|
||||
app = config_utils.load_config(paths.config_path(MAINFILE), paths.app_path(MAINSPEC))
|
||||
app = config_utils.load_config(os.path.join(paths.config_path(), MAINFILE), os.path.join(paths.app_path(), MAINSPEC))
|
||||
|
@ -7,5 +7,5 @@ log = logging.getLogger("fixes.fix_requests")
|
||||
|
||||
def fix():
|
||||
log.debug("Applying fix for requests...")
|
||||
os.environ["REQUESTS_CA_BUNDLE"] = paths.app_path("cacert.pem")
|
||||
log.debug("Changed CA path to %s" % (paths.app_path("cacert.pem"),))
|
||||
os.environ["REQUESTS_CA_BUNDLE"] = os.path.join(paths.app_path().decode(paths.fsencoding), "cacert.pem").encode(paths.fsencoding)
|
||||
log.debug("Changed CA path to %s" % (os.environ["REQUESTS_CA_BUNDLE"].decode(paths.fsencoding)))
|
@ -1,4 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import os
|
||||
import logging
|
||||
from logging.handlers import RotatingFileHandler
|
||||
import paths
|
||||
@ -19,12 +21,12 @@ logger.setLevel(logging.DEBUG)
|
||||
|
||||
#handlers
|
||||
|
||||
app_handler = RotatingFileHandler(paths.logs_path(APP_LOG_FILE), mode="w")
|
||||
app_handler = RotatingFileHandler(os.path.join(paths.logs_path(), APP_LOG_FILE), mode="w")
|
||||
app_handler.setFormatter(formatter)
|
||||
app_handler.setLevel(logging.DEBUG)
|
||||
logger.addHandler(app_handler)
|
||||
|
||||
error_handler = logging.FileHandler(paths.logs_path(ERROR_LOG_FILE), mode="w")
|
||||
error_handler = logging.FileHandler(os.path.join(paths.logs_path(), ERROR_LOG_FILE), mode="w")
|
||||
error_handler.setFormatter(formatter)
|
||||
error_handler.setLevel(logging.ERROR)
|
||||
logger.addHandler(error_handler)
|
||||
|
@ -21,7 +21,7 @@ def setup():
|
||||
log.debug("Starting Socializer %s" % (application.version,))
|
||||
config.setup()
|
||||
log.debug("Using %s %s" % (platform.system(), platform.architecture()[0]))
|
||||
log.debug("Application path is %s" % (paths.app_path(),))
|
||||
log.debug("Application path is %s" % (paths.app_path().decode(paths.fsencoding),))
|
||||
log.debug("config path is %s" % (paths.config_path(),))
|
||||
output.setup()
|
||||
languageHandler.setLanguage(config.app["app-settings"]["language"])
|
||||
|
40
src/paths.py
40
src/paths.py
@ -1,4 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
from __future__ import unicode_literals
|
||||
import sys
|
||||
import platform
|
||||
import os
|
||||
import sys
|
||||
@ -9,47 +11,38 @@ from functools import wraps
|
||||
|
||||
mode = "portable"
|
||||
directory = None
|
||||
fsencoding = sys.getfilesystemencoding()
|
||||
|
||||
#log = logging.getLogger("paths")
|
||||
|
||||
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")
|
||||
if directory != None: path = os.path.join(directory.decode(fsencoding), "config")
|
||||
elif directory == None: path = os.path.join(app_path().decode(fsencoding), "config")
|
||||
elif mode == "installed":
|
||||
path = data_path("config")
|
||||
path = os.path.join(data_path().decode(fsencoding), "config")
|
||||
if not os.path.exists(path):
|
||||
# log.debug("%s path does not exist, creating..." % (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")
|
||||
if directory != None: path = os.path.join(directory.decode(fsencoding), "logs")
|
||||
elif directory == None: path = os.path.join(app_path().decode(fsencoding), "logs")
|
||||
elif mode == "installed":
|
||||
path = data_path("logs")
|
||||
path = os.path.join(data_path().decode(fsencoding), "logs")
|
||||
if not os.path.exists(path):
|
||||
# log.debug("%s path does not exist, creating..." % (path,))
|
||||
os.mkdir(path)
|
||||
return path
|
||||
|
||||
@merge_paths
|
||||
def data_path(app_name='TW blue'):
|
||||
def data_path(app_name='socializer'):
|
||||
if platform.system() == "Windows":
|
||||
data_path = os.path.join(os.getenv("AppData"), app_name)
|
||||
else:
|
||||
@ -58,22 +51,19 @@ def data_path(app_name='TW blue'):
|
||||
os.mkdir(data_path)
|
||||
return data_path
|
||||
|
||||
@merge_paths
|
||||
def locale_path():
|
||||
return app_path(u"locales")
|
||||
return os.path.join(app_path().decode(fsencoding), "locales")
|
||||
|
||||
@merge_paths
|
||||
def sound_path():
|
||||
return app_path(u"sounds")
|
||||
return os.path.join(app_path().decode(fsencoding), "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")
|
||||
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")
|
||||
elif mode == "installed":
|
||||
path = data_path(u"com_cache")
|
||||
path = os.path.join(data_path().decode(fsencoding), "com_cache")
|
||||
if not os.path.exists(path):
|
||||
# log.debug("%s path does not exist, creating..." % (path,))
|
||||
os.mkdir(path)
|
||||
|
@ -23,10 +23,9 @@ class sessionManagerController(object):
|
||||
def fill_list(self):
|
||||
log.debug("Filling the session list...")
|
||||
for i in os.listdir(paths.config_path()):
|
||||
if os.path.isdir(paths.config_path(i)):
|
||||
if os.path.isdir(os.path.join(paths.config_path(), i)):
|
||||
log.debug("Adding session %s" % (i,))
|
||||
strconfig = "%s/session.conf" % (paths.config_path(i))
|
||||
config_test = Configuration(strconfig)
|
||||
config_test = Configuration(os.path.join(paths.config_path(), i, "session.conf"))
|
||||
name = config_test["vk"]["user"]
|
||||
if name != "" and config_test["vk"]["password"] != "":
|
||||
self.session = i
|
||||
@ -39,9 +38,8 @@ class sessionManagerController(object):
|
||||
location = (str(time.time())[-6:])
|
||||
log.debug("Creating session in the %s path" % (location,))
|
||||
s = session.vkSession(location)
|
||||
path = paths.config_path(location)
|
||||
path = os.path.join(paths.config_path(), location)
|
||||
if not os.path.exists(path):
|
||||
log.debug("Creating %s path" % (paths.config_path(path),))
|
||||
os.mkdir(path)
|
||||
s.get_configuration()
|
||||
self.get_authorisation(s)
|
||||
|
@ -1,5 +1,6 @@
|
||||
# -*- coding: utf-8 -*-
|
||||
""" Sound utilities for socialized."""
|
||||
from __future__ import unicode_literals
|
||||
import sys
|
||||
import os
|
||||
import logging as original_logger
|
||||
@ -17,12 +18,12 @@ class soundSystem(object):
|
||||
def check_soundpack(self):
|
||||
""" Checks if the folder where live the current soundpack exists."""
|
||||
self.soundpack_OK = False
|
||||
if os.path.exists(paths.sound_path(self.config["current_soundpack"])):
|
||||
self.path = paths.sound_path(self.config["current_soundpack"])
|
||||
if os.path.exists(os.path.join(paths.sound_path(), self.config["current_soundpack"])):
|
||||
self.path = os.path.join(paths.sound_path(), self.config["current_soundpack"])
|
||||
self.soundpack_OK = True
|
||||
elif os.path.exists(paths.sound_path("default")):
|
||||
elif os.path.exists(os.path.join(paths.sound_path(), "default")):
|
||||
log.error("The soundpack does not exist, using default...")
|
||||
self.path = paths.sound_path("default")
|
||||
self.path = os.path.join(paths.sound_path(), "default")
|
||||
self.soundpack_OK = True
|
||||
else:
|
||||
log.error("The current soundpack could not be found and the default soundpack has been deleted, Socializer will not play sounds.")
|
||||
|
Loading…
Reference in New Issue
Block a user