diff --git a/src/common/configpaths.py b/src/common/configpaths.py index 2ae780f22..2fcf50647 100644 --- a/src/common/configpaths.py +++ b/src/common/configpaths.py @@ -20,11 +20,10 @@ import tempfile # 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 # not displayed to the user, Unicode is not really necessary here. -# -# Update: Python stdlib seems broken, and uses sys.getdefaultencoding() instead -# of sys.getfilesystemencoding() for converting unicode paths in file operations. -# Additionally, PyGTK overrides defaultencoding to utf-8, overriding site.py. -# Therefore, we now use bytestrings and never unicode. (See #2812.) + +def fse(s): + '''Convert from filesystem encoding if not already Unicode''' + return unicode(s, sys.getfilesystemencoding()) class ConfigPaths: def __init__(self, root=None): @@ -39,12 +38,13 @@ class ConfigPaths: # How are we supposed to know what encoding the environment # variable 'appdata' is in? Assuming it to be in filesystem # encoding. - self.root = os.path.join(os.environ['appdata'], 'Gajim') + self.root = os.path.join(fse(os.environ[u'appdata']), u'Gajim') except KeyError: # win9x, in cwd - self.root = '' + self.root = u'' else: # Unices - self.root = os.path.expanduser('~/.gajim') + # Pass in an Unicode string, and hopefully get one back. + self.root = os.path.expanduser(u'~/.gajim') def add_from_root(self, name, path): self.paths[name] = (True, path) @@ -77,8 +77,8 @@ def init(): paths = ConfigPaths() # LOG is deprecated - k = ('LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS' ) - v = ('logs', 'logs.db', 'vcards', 'avatars', 'emoticons') + k = ( 'LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS' ) + v = (u'logs', u'logs.db', u'vcards', u'avatars', u'emoticons') if os.name == 'nt': v = map(lambda x: x.capitalize(), v) @@ -86,9 +86,9 @@ def init(): for n, p in zip(k, v): paths.add_from_root(n, p) - paths.add('DATA', os.path.join('..', windowsify('data'))) - paths.add('HOME', os.path.expanduser('~')) - paths.add('TMP', tempfile.gettempdir()) + paths.add('DATA', os.path.join(u'..', windowsify(u'data'))) + paths.add('HOME', fse(os.path.expanduser('~'))) + paths.add('TMP', fse(tempfile.gettempdir())) try: import svn_config @@ -104,17 +104,13 @@ def init(): gajimpaths = init() def init_profile(profile, paths=gajimpaths): - # no unicode - if isinstance(profile, unicode): - profile = profile.encode(sys.getfilesystemencoding()) - - conffile = windowsify('config') - pidfile = windowsify('gajim') + conffile = windowsify(u'config') + pidfile = windowsify(u'gajim') if len(profile) > 0: - conffile += '.' + profile - pidfile += '.' + profile - pidfile += '.pid' + conffile += u'.' + profile + pidfile += u'.' + profile + pidfile += u'.pid' paths.add_from_root('CONFIG_FILE', conffile) paths.add_from_root('PID_FILE', pidfile) diff --git a/src/common/logger.py b/src/common/logger.py index 7e70457ed..d8f4c7fcd 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -31,6 +31,7 @@ except ImportError: import configpaths LOG_DB_PATH = configpaths.gajimpaths['LOG_DB'] +LOG_DB_FOLDER, LOG_DB_FILE = os.path.split(LOG_DB_PATH) class Constants: def __init__(self): @@ -97,10 +98,18 @@ class Logger: def open_db(self): self.close_db() + # FIXME: sqlite3_open wants UTF8 strings. So a path with + # non-ascii chars doesn't work. See #2812 and + # http://lists.initd.org/pipermail/pysqlite/2005-August/000134.html + back = os.getcwd() + os.chdir(LOG_DB_FOLDER) + # if locked, wait up to 20 sec to unlock # before raise (hopefully should be enough) - self.con = sqlite.connect(LOG_DB_PATH, timeout = 20.0, + + self.con = sqlite.connect(LOG_DB_FILE, timeout = 20.0, isolation_level = 'IMMEDIATE') + os.chdir(back) self.cur = self.con.cursor() self.set_synchronous(False) diff --git a/src/common/optparser.py b/src/common/optparser.py index 409e96d68..37a5dc8d5 100644 --- a/src/common/optparser.py +++ b/src/common/optparser.py @@ -98,11 +98,6 @@ class OptionsParser: def write(self): (base_dir, filename) = os.path.split(self.__filename) - try: - base_dir = base_dir.decode(sys.getfilesystemencoding()) - filename = filename.decode(sys.getfilesystemencoding()) - except: - pass self.__tempfile = os.path.join(base_dir, '.' + filename) try: f = open(self.__tempfile, 'w') @@ -211,7 +206,11 @@ class OptionsParser: def assert_unread_msgs_table_exists(self): '''create table unread_messages if there is no such table''' - con = sqlite.connect(logger.LOG_DB_PATH) + #FIXME see #2812 + back = os.getcwd() + os.chdir(logger.LOG_DB_FOLDER) + con = sqlite.connect(logger.LOG_DB_FILE) + os.chdir(back) cur = con.cursor() try: cur.executescript( @@ -280,7 +279,11 @@ class OptionsParser: def update_config_to_01013(self): '''create table transports_cache if there is no such table''' - con = sqlite.connect(logger.LOG_DB_PATH) + #FIXME see #2812 + back = os.getcwd() + os.chdir(logger.LOG_DB_FOLDER) + con = sqlite.connect(logger.LOG_DB_FILE) + os.chdir(back) cur = con.cursor() try: cur.executescript( @@ -300,7 +303,11 @@ class OptionsParser: def update_config_to_01014(self): '''apply indeces to the logs database''' print _('migrating logs database to indices') - con = sqlite.connect(logger.LOG_DB_PATH) + #FIXME see #2812 + back = os.getcwd() + os.chdir(logger.LOG_DB_FOLDER) + con = sqlite.connect(logger.LOG_DB_FILE) + os.chdir(back) cur = con.cursor() # apply indeces try: @@ -319,7 +326,11 @@ class OptionsParser: def update_config_to_01015(self): '''clean show values in logs database''' - con = sqlite.connect(logger.LOG_DB_PATH) + #FIXME see #2812 + back = os.getcwd() + os.chdir(logger.LOG_DB_FOLDER) + con = sqlite.connect(logger.LOG_DB_FILE) + os.chdir(back) cur = con.cursor() status = dict((i[5:].lower(), logger.constants.__dict__[i]) for i in \ logger.constants.__dict__.keys() if i.startswith('SHOW_'))