From ad04559cbfac2a2a917836dc9a5972a27ed4b12d Mon Sep 17 00:00:00 2001 From: Yann Leboulanger Date: Wed, 12 Apr 2006 08:38:51 +0000 Subject: [PATCH] try to create unread_messages table only once when we update config file. --- src/common/check_paths.py | 39 +++------------------------------------ src/common/optparser.py | 28 ++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 36 deletions(-) diff --git a/src/common/check_paths.py b/src/common/check_paths.py index f0c5f16a2..18c0bdca1 100644 --- a/src/common/check_paths.py +++ b/src/common/check_paths.py @@ -35,37 +35,6 @@ Q_ = i18n.Q_ from pysqlite2 import dbapi2 as sqlite # DO NOT MOVE ABOVE OF import gajim -def assert_unread_msgs_table_exists(): - '''create table unread_messages if there is no such table''' - con = sqlite.connect(logger.LOG_DB_PATH) - cur = con.cursor() - needs_init_vars = False - try: - cur.executescript( - ''' - CREATE TABLE unread_messages ( - message_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, - jid_id INTEGER - ); - ''' - ) - con.commit() - needs_init_vars = True - except sqlite.OperationalError, e: - pass - # add column jid_id. if there is such column do nothing - try: - #FIXME: remove before release 0.10, it's temporary - cur.executescript('ALTER TABLE unread_messages ADD jid_id INTEGER;') - con.commit() - needs_init_vars = True - except sqlite.OperationalError, e: - pass - - if needs_init_vars: - gajim.logger.init_vars() - con.close() - def create_log_db(): print _('creating logs database') con = sqlite.connect(logger.LOG_DB_PATH) @@ -126,23 +95,21 @@ def check_and_possibly_create_paths(): print _('%s is file but it should be a directory') % VCARD_PATH print _('Gajim will now exit') sys.exit() - + if not os.path.exists(AVATAR_PATH): create_path(AVATAR_PATH) elif os.path.isfile(AVATAR_PATH): print _('%s is file but it should be a directory') % AVATAR_PATH print _('Gajim will now exit') sys.exit() - + if not os.path.exists(LOG_DB_PATH): create_log_db() elif os.path.isdir(LOG_DB_PATH): print _('%s is directory but should be file') % LOG_DB_PATH print _('Gajim will now exit') sys.exit() - else: - assert_unread_msgs_table_exists() - + else: # dot_gajim doesn't exist if dot_gajim: # is '' on win9x so avoid that create_path(dot_gajim) diff --git a/src/common/optparser.py b/src/common/optparser.py index 5aab15975..de3b4b27a 100644 --- a/src/common/optparser.py +++ b/src/common/optparser.py @@ -193,6 +193,32 @@ class OptionsParser: gajim.config.set('version', '0.9') + def assert_unread_msgs_table_exists(self): + '''create table unread_messages if there is no such table''' + import exceptions + try: + from pysqlite2 import dbapi2 as sqlite + except ImportError: + raise exceptions.PysqliteNotAvailable + import logger + + con = sqlite.connect(logger.LOG_DB_PATH) + cur = con.cursor() + try: + cur.executescript( + ''' + CREATE TABLE unread_messages ( + message_id INTEGER PRIMARY KEY AUTOINCREMENT UNIQUE, + jid_id INTEGER + ); + ''' + ) + con.commit() + logger.init_vars() + except sqlite.OperationalError, e: + pass + con.close() + def update_config_09_to_010(self): if self.old_values.has_key('usetabbedchat') and not \ self.old_values['usetabbedchat']: @@ -225,5 +251,7 @@ class OptionsParser: proxies_str = ', '.join(proxies) gajim.config.set_per('accounts', account, 'file_transfer_proxies', proxies_str) + # create unread_messages table if needed + self.assert_unread_msgs_table_exists() gajim.config.set('version', '0.10')