- Use bytestrings instead of unicode for filesystem paths. See #2812 and close if fix works.
This commit is contained in:
parent
35ecad1188
commit
7f44b60267
|
@ -20,10 +20,11 @@ import tempfile
|
||||||
# happily pass to functions that operate on files and directories, so we can
|
# happily pass to functions that operate on files and directories, so we can
|
||||||
# just leave it as is. Since these paths are meant to be internal to Gajim and
|
# just leave it as is. Since these paths are meant to be internal to Gajim and
|
||||||
# not displayed to the user, Unicode is not really necessary here.
|
# not displayed to the user, Unicode is not really necessary here.
|
||||||
|
#
|
||||||
def fse(s):
|
# Update: Python stdlib seems broken, and uses sys.getdefaultencoding() instead
|
||||||
'''Convert from filesystem encoding if not already Unicode'''
|
# of sys.getfilesystemencoding() for converting unicode paths in file operations.
|
||||||
return unicode(s, sys.getfilesystemencoding())
|
# Additionally, PyGTK overrides defaultencoding to utf-8, overriding site.py.
|
||||||
|
# Therefore, we now use bytestrings and never unicode. (See #2812.)
|
||||||
|
|
||||||
class ConfigPaths:
|
class ConfigPaths:
|
||||||
def __init__(self, root=None):
|
def __init__(self, root=None):
|
||||||
|
@ -38,13 +39,12 @@ class ConfigPaths:
|
||||||
# How are we supposed to know what encoding the environment
|
# How are we supposed to know what encoding the environment
|
||||||
# variable 'appdata' is in? Assuming it to be in filesystem
|
# variable 'appdata' is in? Assuming it to be in filesystem
|
||||||
# encoding.
|
# encoding.
|
||||||
self.root = os.path.join(fse(os.environ[u'appdata']), u'Gajim')
|
self.root = os.path.join(os.environ['appdata'], 'Gajim')
|
||||||
except KeyError:
|
except KeyError:
|
||||||
# win9x, in cwd
|
# win9x, in cwd
|
||||||
self.root = u''
|
self.root = ''
|
||||||
else: # Unices
|
else: # Unices
|
||||||
# Pass in an Unicode string, and hopefully get one back.
|
self.root = os.path.expanduser('~/.gajim')
|
||||||
self.root = os.path.expanduser(u'~/.gajim')
|
|
||||||
|
|
||||||
def add_from_root(self, name, path):
|
def add_from_root(self, name, path):
|
||||||
self.paths[name] = (True, path)
|
self.paths[name] = (True, path)
|
||||||
|
@ -78,7 +78,7 @@ def init():
|
||||||
|
|
||||||
# LOG is deprecated
|
# LOG is deprecated
|
||||||
k = ('LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS' )
|
k = ('LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS' )
|
||||||
v = (u'logs', u'logs.db', u'vcards', u'avatars', u'emoticons')
|
v = ('logs', 'logs.db', 'vcards', 'avatars', 'emoticons')
|
||||||
|
|
||||||
if os.name == 'nt':
|
if os.name == 'nt':
|
||||||
v = map(lambda x: x.capitalize(), v)
|
v = map(lambda x: x.capitalize(), v)
|
||||||
|
@ -86,9 +86,9 @@ def init():
|
||||||
for n, p in zip(k, v):
|
for n, p in zip(k, v):
|
||||||
paths.add_from_root(n, p)
|
paths.add_from_root(n, p)
|
||||||
|
|
||||||
paths.add('DATA', os.path.join(u'..', windowsify(u'data')))
|
paths.add('DATA', os.path.join('..', windowsify('data')))
|
||||||
paths.add('HOME', fse(os.path.expanduser('~')))
|
paths.add('HOME', os.path.expanduser('~'))
|
||||||
paths.add('TMP', fse(tempfile.gettempdir()))
|
paths.add('TMP', tempfile.gettempdir())
|
||||||
|
|
||||||
try:
|
try:
|
||||||
import svn_config
|
import svn_config
|
||||||
|
@ -97,19 +97,22 @@ def init():
|
||||||
pass
|
pass
|
||||||
|
|
||||||
# for k, v in paths.iteritems():
|
# for k, v in paths.iteritems():
|
||||||
# print "%s: %s" % (k, v)
|
# print "%s: %s" % (repr(k), repr(v))
|
||||||
|
|
||||||
return paths
|
return paths
|
||||||
|
|
||||||
gajimpaths = init()
|
gajimpaths = init()
|
||||||
|
|
||||||
def init_profile(profile, paths=gajimpaths):
|
def init_profile(profile, paths=gajimpaths):
|
||||||
conffile = windowsify(u'config')
|
conffile = windowsify('config')
|
||||||
pidfile = windowsify(u'gajim')
|
pidfile = windowsify('gajim')
|
||||||
|
|
||||||
if len(profile) > 0:
|
if len(profile) > 0:
|
||||||
conffile += u'.' + profile
|
conffile += '.' + profile
|
||||||
pidfile += u'.' + profile
|
pidfile += '.' + profile
|
||||||
pidfile += u'.pid'
|
pidfile += '.pid'
|
||||||
paths.add_from_root('CONFIG_FILE', conffile)
|
paths.add_from_root('CONFIG_FILE', conffile)
|
||||||
paths.add_from_root('PID_FILE', pidfile)
|
paths.add_from_root('PID_FILE', pidfile)
|
||||||
|
|
||||||
|
# for k, v in paths.iteritems():
|
||||||
|
# print "%s: %s" % (repr(k), repr(v))
|
||||||
|
|
Loading…
Reference in New Issue