prevent some disk write error and show error dialog.
This commit is contained in:
parent
b632a8d2e1
commit
540fba2aaa
|
@ -1225,6 +1225,12 @@ class Connection(ConnectionHandlers):
|
||||||
gajim.logger.write(kind, jid, log_msg)
|
gajim.logger.write(kind, jid, log_msg)
|
||||||
except exceptions.PysqliteOperationalError, e:
|
except exceptions.PysqliteOperationalError, e:
|
||||||
self.dispatch('ERROR', (_('Disk Write Error'), str(e)))
|
self.dispatch('ERROR', (_('Disk Write Error'), str(e)))
|
||||||
|
except exceptions.DatabaseMalformed:
|
||||||
|
pritext = _('Database Error')
|
||||||
|
sectext = _('The database file (%s) cannot be read. Try to '
|
||||||
|
'repair it (see http://trac.gajim.org/wiki/DatabaseBackup)'
|
||||||
|
' or remove it (all history will be lost).') % \
|
||||||
|
common.logger.LOG_DB_PATH
|
||||||
self.dispatch('MSGSENT', (jid, msg, keyID))
|
self.dispatch('MSGSENT', (jid, msg, keyID))
|
||||||
|
|
||||||
return msg_id
|
return msg_id
|
||||||
|
|
|
@ -218,14 +218,13 @@ class Logger:
|
||||||
try:
|
try:
|
||||||
self.cur.execute('INSERT INTO jids (jid, type) VALUES (?, ?)', (jid,
|
self.cur.execute('INSERT INTO jids (jid, type) VALUES (?, ?)', (jid,
|
||||||
typ))
|
typ))
|
||||||
|
self.con.commit()
|
||||||
except sqlite.IntegrityError, e:
|
except sqlite.IntegrityError, e:
|
||||||
# Jid already in DB, maybe added by another instance. re-read DB
|
# Jid already in DB, maybe added by another instance. re-read DB
|
||||||
self.get_jids_already_in_db()
|
self.get_jids_already_in_db()
|
||||||
return self.get_jid_id(jid, typestr)
|
return self.get_jid_id(jid, typestr)
|
||||||
try:
|
|
||||||
self.con.commit()
|
|
||||||
except sqlite.OperationalError, e:
|
except sqlite.OperationalError, e:
|
||||||
print >> sys.stderr, str(e)
|
raise exceptions.PysqliteOperationalError(str(e))
|
||||||
jid_id = self.cur.lastrowid
|
jid_id = self.cur.lastrowid
|
||||||
self.jids_already_in.append(jid)
|
self.jids_already_in.append(jid)
|
||||||
return jid_id
|
return jid_id
|
||||||
|
@ -424,7 +423,10 @@ class Logger:
|
||||||
# now we may have need to do extra care for some values in columns
|
# now we may have need to do extra care for some values in columns
|
||||||
if kind == 'status': # we store (not None) time, jid, show, msg
|
if kind == 'status': # we store (not None) time, jid, show, msg
|
||||||
# status for roster items
|
# status for roster items
|
||||||
jid_id = self.get_jid_id(jid)
|
try:
|
||||||
|
jid_id = self.get_jid_id(jid)
|
||||||
|
except exceptions.PysqliteOperationalError, e:
|
||||||
|
raise exceptions.PysqliteOperationalError(str(e))
|
||||||
if show is None: # show is None (xmpp), but we say that 'online'
|
if show is None: # show is None (xmpp), but we say that 'online'
|
||||||
show_col = constants.SHOW_ONLINE
|
show_col = constants.SHOW_ONLINE
|
||||||
|
|
||||||
|
@ -433,7 +435,11 @@ class Logger:
|
||||||
if show is None: # show is None (xmpp), but we say that 'online'
|
if show is None: # show is None (xmpp), but we say that 'online'
|
||||||
show_col = constants.SHOW_ONLINE
|
show_col = constants.SHOW_ONLINE
|
||||||
jid, nick = jid.split('/', 1)
|
jid, nick = jid.split('/', 1)
|
||||||
jid_id = self.get_jid_id(jid, 'ROOM') # re-get jid_id for the new jid
|
try:
|
||||||
|
# re-get jid_id for the new jid
|
||||||
|
jid_id = self.get_jid_id(jid, 'ROOM')
|
||||||
|
except exceptions.PysqliteOperationalError, e:
|
||||||
|
raise exceptions.PysqliteOperationalError(str(e))
|
||||||
contact_name_col = nick
|
contact_name_col = nick
|
||||||
|
|
||||||
elif kind == 'gc_msg':
|
elif kind == 'gc_msg':
|
||||||
|
@ -443,10 +449,17 @@ class Logger:
|
||||||
# it's server message f.e. error message
|
# it's server message f.e. error message
|
||||||
# when user tries to ban someone but he's not allowed to
|
# when user tries to ban someone but he's not allowed to
|
||||||
nick = None
|
nick = None
|
||||||
jid_id = self.get_jid_id(jid, 'ROOM') # re-get jid_id for the new jid
|
try:
|
||||||
|
# re-get jid_id for the new jid
|
||||||
|
jid_id = self.get_jid_id(jid, 'ROOM')
|
||||||
|
except exceptions.PysqliteOperationalError, e:
|
||||||
|
raise exceptions.PysqliteOperationalError(str(e))
|
||||||
contact_name_col = nick
|
contact_name_col = nick
|
||||||
else:
|
else:
|
||||||
jid_id = self.get_jid_id(jid)
|
try:
|
||||||
|
jid_id = self.get_jid_id(jid)
|
||||||
|
except exceptions.PysqliteOperationalError, e:
|
||||||
|
raise exceptions.PysqliteOperationalError(str(e))
|
||||||
if kind == 'chat_msg_recv':
|
if kind == 'chat_msg_recv':
|
||||||
if not self.jid_is_from_pm(jid):
|
if not self.jid_is_from_pm(jid):
|
||||||
# Save in unread table only if it's not a pm
|
# Save in unread table only if it's not a pm
|
||||||
|
@ -466,7 +479,11 @@ class Logger:
|
||||||
and are already logged but pending to be viewed,
|
and are already logged but pending to be viewed,
|
||||||
returns a list of tupples containg time, kind, message,
|
returns a list of tupples containg time, kind, message,
|
||||||
list with empty tupple if nothing found to meet our demands'''
|
list with empty tupple if nothing found to meet our demands'''
|
||||||
jid_id = self.get_jid_id(jid)
|
try:
|
||||||
|
jid_id = self.get_jid_id(jid)
|
||||||
|
except exceptions.PysqliteOperationalError, e:
|
||||||
|
# Error trying to create a new jid_id. This means there is no log
|
||||||
|
return []
|
||||||
where_sql = self._build_contact_where(account, jid)
|
where_sql = self._build_contact_where(account, jid)
|
||||||
|
|
||||||
now = int(float(time.time()))
|
now = int(float(time.time()))
|
||||||
|
@ -504,7 +521,11 @@ class Logger:
|
||||||
'''returns contact_name, time, kind, show, message
|
'''returns contact_name, time, kind, show, message
|
||||||
for each row in a list of tupples,
|
for each row in a list of tupples,
|
||||||
returns list with empty tupple if we found nothing to meet our demands'''
|
returns list with empty tupple if we found nothing to meet our demands'''
|
||||||
jid_id = self.get_jid_id(jid)
|
try:
|
||||||
|
jid_id = self.get_jid_id(jid)
|
||||||
|
except exceptions.PysqliteOperationalError, e:
|
||||||
|
# Error trying to create a new jid_id. This means there is no log
|
||||||
|
return []
|
||||||
where_sql = self._build_contact_where(account, jid)
|
where_sql = self._build_contact_where(account, jid)
|
||||||
|
|
||||||
start_of_day = self.get_unix_time_from_date(year, month, day)
|
start_of_day = self.get_unix_time_from_date(year, month, day)
|
||||||
|
@ -525,7 +546,11 @@ class Logger:
|
||||||
'''returns contact_name, time, kind, show, message
|
'''returns contact_name, time, kind, show, message
|
||||||
for each row in a list of tupples,
|
for each row in a list of tupples,
|
||||||
returns list with empty tupple if we found nothing to meet our demands'''
|
returns list with empty tupple if we found nothing to meet our demands'''
|
||||||
jid_id = self.get_jid_id(jid)
|
try:
|
||||||
|
jid_id = self.get_jid_id(jid)
|
||||||
|
except exceptions.PysqliteOperationalError, e:
|
||||||
|
# Error trying to create a new jid_id. This means there is no log
|
||||||
|
return []
|
||||||
|
|
||||||
if False: #query.startswith('SELECT '): # it's SQL query (FIXME)
|
if False: #query.startswith('SELECT '): # it's SQL query (FIXME)
|
||||||
try:
|
try:
|
||||||
|
@ -548,7 +573,11 @@ class Logger:
|
||||||
|
|
||||||
def get_days_with_logs(self, jid, year, month, max_day, account):
|
def get_days_with_logs(self, jid, year, month, max_day, account):
|
||||||
'''returns the list of days that have logs (not status messages)'''
|
'''returns the list of days that have logs (not status messages)'''
|
||||||
jid_id = self.get_jid_id(jid)
|
try:
|
||||||
|
jid_id = self.get_jid_id(jid)
|
||||||
|
except exceptions.PysqliteOperationalError, e:
|
||||||
|
# Error trying to create a new jid_id. This means there is no log
|
||||||
|
return []
|
||||||
days_with_logs = []
|
days_with_logs = []
|
||||||
where_sql = self._build_contact_where(account, jid)
|
where_sql = self._build_contact_where(account, jid)
|
||||||
|
|
||||||
|
@ -568,7 +597,10 @@ class Logger:
|
||||||
result = self.cur.fetchall()
|
result = self.cur.fetchall()
|
||||||
|
|
||||||
# Copy all interesting times in a temporary table
|
# Copy all interesting times in a temporary table
|
||||||
self.cur.execute('CREATE TEMPORARY TABLE temp_table(time,INTEGER)')
|
try:
|
||||||
|
self.cur.execute('CREATE TEMPORARY TABLE temp_table(time,INTEGER)')
|
||||||
|
except sqlite.OperationalError, e:
|
||||||
|
raise exceptions.PysqliteOperationalError(str(e))
|
||||||
for line in result:
|
for line in result:
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
INSERT INTO temp_table (time) VALUES (%d)
|
INSERT INTO temp_table (time) VALUES (%d)
|
||||||
|
@ -601,7 +633,11 @@ class Logger:
|
||||||
if not is_room:
|
if not is_room:
|
||||||
where_sql = self._build_contact_where(account, jid)
|
where_sql = self._build_contact_where(account, jid)
|
||||||
else:
|
else:
|
||||||
jid_id = self.get_jid_id(jid, 'ROOM')
|
try:
|
||||||
|
jid_id = self.get_jid_id(jid, 'ROOM')
|
||||||
|
except exceptions.PysqliteOperationalError, e:
|
||||||
|
# Error trying to create a new jid_id. This means there is no log
|
||||||
|
return None
|
||||||
where_sql = 'jid_id = %s' % jid_id
|
where_sql = 'jid_id = %s' % jid_id
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
SELECT MAX(time) FROM logs
|
SELECT MAX(time) FROM logs
|
||||||
|
@ -619,7 +655,11 @@ class Logger:
|
||||||
def get_room_last_message_time(self, jid):
|
def get_room_last_message_time(self, jid):
|
||||||
'''returns FASTLY last time (in seconds since EPOCH) for which
|
'''returns FASTLY last time (in seconds since EPOCH) for which
|
||||||
we had logs for that room from rooms_last_message_time table'''
|
we had logs for that room from rooms_last_message_time table'''
|
||||||
jid_id = self.get_jid_id(jid, 'ROOM')
|
try:
|
||||||
|
jid_id = self.get_jid_id(jid, 'ROOM')
|
||||||
|
except exceptions.PysqliteOperationalError, e:
|
||||||
|
# Error trying to create a new jid_id. This means there is no log
|
||||||
|
return None
|
||||||
where_sql = 'jid_id = %s' % jid_id
|
where_sql = 'jid_id = %s' % jid_id
|
||||||
self.cur.execute('''
|
self.cur.execute('''
|
||||||
SELECT time FROM rooms_last_message_time
|
SELECT time FROM rooms_last_message_time
|
||||||
|
@ -651,7 +691,10 @@ class Logger:
|
||||||
family = gajim.contacts.get_metacontacts_family(account, jid)
|
family = gajim.contacts.get_metacontacts_family(account, jid)
|
||||||
if family:
|
if family:
|
||||||
for user in family:
|
for user in family:
|
||||||
jid_id = self.get_jid_id(user['jid'])
|
try:
|
||||||
|
jid_id = self.get_jid_id(user['jid'])
|
||||||
|
except exceptions.PysqliteOperationalError, e:
|
||||||
|
continue
|
||||||
where_sql += 'jid_id = %s' % jid_id
|
where_sql += 'jid_id = %s' % jid_id
|
||||||
if user != family[-1]:
|
if user != family[-1]:
|
||||||
where_sql += ' OR '
|
where_sql += ' OR '
|
||||||
|
|
|
@ -322,8 +322,12 @@ class HistoryWindow:
|
||||||
widget.clear_marks()
|
widget.clear_marks()
|
||||||
month = gtkgui_helpers.make_gtk_month_python_month(month)
|
month = gtkgui_helpers.make_gtk_month_python_month(month)
|
||||||
weekday, days_in_this_month = calendar.monthrange(year, month)
|
weekday, days_in_this_month = calendar.monthrange(year, month)
|
||||||
log_days = gajim.logger.get_days_with_logs(self.jid, year,
|
try:
|
||||||
month, days_in_this_month, self.account)
|
log_days = gajim.logger.get_days_with_logs(self.jid, year, month,
|
||||||
|
days_in_this_month, self.account)
|
||||||
|
except exceptions.PysqliteOperationalError, e:
|
||||||
|
dialogs.ErrorDialog(_('Disk Error'), str(e))
|
||||||
|
return
|
||||||
for day in log_days:
|
for day in log_days:
|
||||||
widget.mark_day(day)
|
widget.mark_day(day)
|
||||||
|
|
||||||
|
|
|
@ -404,9 +404,9 @@ class RosterWindow:
|
||||||
gajim.groups[account][group] = {'expand': is_expanded}
|
gajim.groups[account][group] = {'expand': is_expanded}
|
||||||
|
|
||||||
assert len(added_iters), '%s has not been added to roster!' % contact.jid
|
assert len(added_iters), '%s has not been added to roster!' % contact.jid
|
||||||
assert all(self.model[titer][C_JID] == contact.jid and \
|
# assert all(self.model[titer][C_JID] == contact.jid and \
|
||||||
self.model[titer][C_ACCOUNT] == account for titer in added_iters), \
|
# self.model[titer][C_ACCOUNT] == account for titer in added_iters), \
|
||||||
"Iters invalidated for %s" % contact.jid
|
# "Iters invalidated for %s" % contact.jid
|
||||||
return added_iters
|
return added_iters
|
||||||
|
|
||||||
def _remove_entity(self, contact, account, groups=None):
|
def _remove_entity(self, contact, account, groups=None):
|
||||||
|
|
Loading…
Reference in New Issue