diff --git a/configure.ac b/configure.ac index 61f4052a45a9c9b1dcc3c0a244d73ee1e02decff..d5fcf0c680c5915d5b2f352bee1b27e224aeee28 100644 --- a/configure.ac +++ b/configure.ac @@ -1,5 +1,5 @@ AC_INIT([Gajim - A Jabber Instant Messager], - [0.13.10.1-dev],[http://trac.gajim.org/],[gajim]) + [0.13.10.2-dev],[http://trac.gajim.org/],[gajim]) AC_PREREQ([2.59]) AC_CONFIG_HEADER(config.h) diff --git a/src/common/check_paths.py b/src/common/check_paths.py index 57fcdf7b8f5b8ff8658e3fa2d1deb23ac6a9ca2c..d3a7d29df84d4dab6d33e2ce6c1b060022c33050 100644 --- a/src/common/check_paths.py +++ b/src/common/check_paths.py @@ -63,11 +63,6 @@ def create_log_db(): CREATE INDEX idx_unread_messages_jid_id ON unread_messages (jid_id); - CREATE TABLE transports_cache ( - transport TEXT UNIQUE, - type INTEGER - ); - CREATE TABLE logs( log_line_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, jid_id INTEGER, @@ -80,6 +75,23 @@ def create_log_db(): ); CREATE INDEX idx_logs_jid_id_time ON logs (jid_id, time DESC); + ''' + ) + + con.commit() + con.close() + +def create_cache_db(): + print _('creating cache database') + con = sqlite.connect(logger.CACHE_DB_PATH) + os.chmod(logger.CACHE_DB_PATH, 0600) # rw only for us + cur = con.cursor() + cur.executescript( + ''' + CREATE TABLE transports_cache ( + transport TEXT UNIQUE, + type INTEGER + ); CREATE TABLE caps_cache ( hash_method TEXT, @@ -115,6 +127,7 @@ def create_log_db(): def check_and_possibly_create_paths(): LOG_DB_PATH = logger.LOG_DB_PATH + CACHE_DB_PATH = logger.CACHE_DB_PATH VCARD_PATH = gajim.VCARD_PATH AVATAR_PATH = gajim.AVATAR_PATH dot_gajim = os.path.dirname(VCARD_PATH) @@ -149,6 +162,13 @@ def check_and_possibly_create_paths(): print _('Gajim will now exit') sys.exit() + if not os.path.exists(CACHE_DB_PATH): + create_cache_db() + elif os.path.isdir(CACHE_DB_PATH): + print _('%s is a directory but should be a file') % CACHE_DB_PATH + print _('Gajim will now exit') + sys.exit() + else: # dot_gajim doesn't exist if dot_gajim: # is '' on win9x so avoid that create_path(dot_gajim) @@ -159,6 +179,9 @@ def check_and_possibly_create_paths(): if not os.path.isfile(LOG_DB_PATH): create_log_db() gajim.logger.init_vars() + if not os.path.isfile(CACHE_DB_PATH): + create_cache_db() + gajim.logger.attach_cache_database() def create_path(directory): print _('creating %s directory') % directory diff --git a/src/common/configpaths.py b/src/common/configpaths.py index c1708ad11593c72933169364790c6022a0573c02..856eb7e043b49a9c131fdd1b8abd971360ea00da 100644 --- a/src/common/configpaths.py +++ b/src/common/configpaths.py @@ -105,11 +105,11 @@ def init(self, root = None): self.root = root # LOG is deprecated - k = ( 'LOG', 'LOG_DB', 'VCARD', 'AVATAR', 'MY_EMOTS', - 'MY_ICONSETS', 'MY_MOOD_ICONSETS', - 'MY_ACTIVITY_ICONSETS', 'MY_CACERTS') - v = (u'logs', u'logs.db', u'vcards', u'avatars', u'emoticons', - u'iconsets', u'moods', u'activities', u'cacerts.pem') + k = ( 'LOG', 'LOG_DB', 'CACHE_DB', 'VCARD', 'AVATAR', 'MY_EMOTS', + 'MY_ICONSETS', 'MY_MOOD_ICONSETS', 'MY_ACTIVITY_ICONSETS', + 'MY_CACERTS') + v = (u'logs', u'logs.db', u'cache.db', u'vcards', u'avatars', + u'emoticons', u'iconsets', u'moods', u'activities', u'cacerts.pem') if os.name == 'nt': v = [x.capitalize() for x in v] diff --git a/src/common/defs.py b/src/common/defs.py index 11a8d23a6fa0e0c79ddc027a96c73dbf55fe464b..615c825b292b385b45828f5f6fd3da5cfc0e19cc 100644 --- a/src/common/defs.py +++ b/src/common/defs.py @@ -27,7 +27,7 @@ basedir = '../' localedir = '../po' -version = '0.13.10.1-dev' +version = '0.13.10.2-dev' import sys, os.path for base in ('.', 'common'): diff --git a/src/common/logger.py b/src/common/logger.py index 507b29cfa0ef0f7dced1ac425d8c756d774bd22e..a9297c463ceedc3e6c050be665c879315f5162c5 100644 --- a/src/common/logger.py +++ b/src/common/logger.py @@ -43,6 +43,7 @@ import configpaths LOG_DB_PATH = configpaths.gajimpaths['LOG_DB'] LOG_DB_FOLDER, LOG_DB_FILE = os.path.split(LOG_DB_PATH) +CACHE_DB_PATH = configpaths.gajimpaths['CACHE_DB'] class Constants: def __init__(self): @@ -107,6 +108,11 @@ def __init__(self): # db is not created here but in src/common/checks_paths.py return self.init_vars() + if not os.path.exists(CACHE_DB_PATH): + # this can happen cache database is not present when gajim is launched + # db will be created in src/common/checks_paths.py + return + self.attach_cache_database() def close_db(self): if self.con: @@ -132,6 +138,12 @@ def open_db(self): self.cur = self.con.cursor() self.set_synchronous(False) + def attach_cache_database(self): + try: + self.cur.execute("ATTACH DATABASE '%s' AS cache" % CACHE_DB_PATH) + except sqlite.Error, e: + gajim.log.debug("Failed to attach cache database: %s" % str(e)) + def set_synchronous(self, sync): try: if sync: diff --git a/src/common/optparser.py b/src/common/optparser.py index 7b7fe911d5cac6d2ca4366aaced14283c4767c29..d0dbe3139850b062801ddbc960c2f3929d29bf10 100644 --- a/src/common/optparser.py +++ b/src/common/optparser.py @@ -216,8 +216,11 @@ def update_config(self, old_version, new_version): self.update_config_to_013100() if old < [0, 13, 10, 1] and new >= [0, 13, 10, 1]: self.update_config_to_013101() + if old < [0, 13, 10, 2] and new >= [0, 13, 10, 2]: + self.update_config_to_013102() gajim.logger.init_vars() + gajim.logger.attach_cache_database() gajim.config.set('version', new_version) caps_cache.capscache.initialize_from_db() @@ -880,4 +883,24 @@ def update_config_to_013101(self): con.close() gajim.config.set('version', '0.13.10.1') + def update_config_to_013102(self): + back = os.getcwd() + os.chdir(logger.LOG_DB_FOLDER) + con = sqlite.connect(logger.LOG_DB_FILE) + os.chdir(back) + cur = con.cursor() + cur.execute("ATTACH DATABASE '%s' AS cache" % logger.CACHE_DB_PATH) + for table in ('caps_cache', 'rooms_last_message_time', 'roster_entry', + 'roster_group', 'transports_cache'): + try: + cur.executescript( + 'INSERT INTO cache.%s SELECT * FROM %s;' % (table, table)) + con.commit() + cur.executescript('DROP TABLE %s;' % table) + con.commit() + except sqlite.OperationalError: + print >> sys.stderr, 'error moving table %s to cache.db' + con.close() + gajim.config.set('version', '0.13.10.2') + # vim: se ts=3: