Skip to content

Commit abde92e

Browse files
committed
Remove command variable and pass string in error_handler()
1 parent 7a5c319 commit abde92e

File tree

1 file changed

+35
-29
lines changed

1 file changed

+35
-29
lines changed

src/class_sqlThread.py

Lines changed: 35 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -173,8 +173,7 @@ def check_columns_can_store_binary_null(self):
173173
if str(err) != 'database or disk is full':
174174
logger.error(err)
175175
else:
176-
command = 'null value test'
177-
sqlThread().error_handler(err, command)
176+
sqlThread().error_handler(err, 'null value test')
178177

179178
def check_vacuum(self): # pylint: disable=too-many-locals, too-many-branches, too-many-statements,
180179
# Redefinition-of-parameters-type-from-tuple-to-str, R0204, line-too-long, E501
@@ -195,8 +194,7 @@ def check_vacuum(self): # pylint: disable=too-many-locals, too-many-branches, t
195194
try:
196195
self.cur.execute(''' VACUUM ''')
197196
except Exception as err:
198-
command = 'VACUUM'
199-
sqlThread().error_handler(err, command)
197+
sqlThread().error_handler(err, 'VACUUM')
200198
query = "update settings set value=? WHERE key='lastvacuumtime'"
201199
parameters = (int(time.time()),)
202200
self.cur.execute(query, parameters)
@@ -275,7 +273,9 @@ def upgrade_config_setting_version(self):
275273

276274
@staticmethod
277275
def error_handler(err, command):
278-
276+
"""
277+
Common error handler
278+
"""
279279
if str(err) == 'database or disk is full':
280280
logger.fatal(
281281
"(While %s) Alert: Your disk or data storage volume is full. sqlThread will now exit.", command
@@ -298,18 +298,17 @@ def is_query_commit(self):
298298
try:
299299
self.db.conn.commit()
300300
except Exception as err:
301-
command = 'committing'
302-
self.error_handler(err, command)
301+
self.error_handler(err, 'committing')
303302

304303
def is_query_movemessagstoprog(self):
305304
"""
306305
When query == 'movemessagstoprogs'
307306
"""
307+
logger.debug('the sqlThread is moving the messages.dat file to the local program directory.')
308308
try:
309309
self.db.conn.commit()
310310
except Exception as err:
311-
command = 'movemessagstoprog'
312-
self.error_handler(err, command)
311+
self.error_handler(err, 'movemessagstoprog')
313312
self.db.conn.close()
314313
shutil.move(
315314
paths.lookupAppdataFolder() + 'messages.dat', paths.lookupExeFolder() + 'messages.dat')
@@ -324,8 +323,7 @@ def is_query_deleteandvacuume(self):
324323
try:
325324
self.db.cur.execute(''' VACUUM ''')
326325
except Exception as err:
327-
command = 'deleteandvacuume'
328-
self.error_handler(err, command)
326+
self.error_handler(err, 'deleteandvacuume')
329327
self.db.cur.execute('''delete from inbox where folder='trash' ''')
330328
self.db.cur.execute('''delete from sent where folder='trash' ''')
331329
self.db.conn.commit()
@@ -354,8 +352,30 @@ def is_query_other(self, query):
354352
logger.fatal('This program shall now abruptly exit!')
355353
os._exit(0)
356354
else:
357-
command = 'cur.execute'
358-
self.error_handler(err, command)
355+
self.error_handler(err, 'cur.execute')
356+
357+
def is_query_movemessagestoappdata(self):
358+
"""
359+
When query == 'movemessagestoappdata'
360+
"""
361+
logger.debug('the sqlThread is moving the messages.dat file to the Appdata folder.')
362+
try:
363+
self.db.conn.commit()
364+
except Exception as err:
365+
self.error_handler(err, 'movemessagstoappdata')
366+
self.db.conn.close()
367+
shutil.move(
368+
paths.lookupExeFolder() + 'messages.dat', paths.lookupAppdataFolder() + 'messages.dat')
369+
self.db.conn = sqlite3.connect(paths.lookupAppdataFolder() + 'messages.dat')
370+
self.db.conn.text_factory = str
371+
self.db.cur = self.db.conn.cursor()
372+
373+
def is_query_exit(self):
374+
"""
375+
When query == 'exit'
376+
"""
377+
self.db.conn.close()
378+
logger.info('sqlThread exiting gracefully.')
359379

360380
def loop_queue(self):
361381
"""
@@ -365,31 +385,17 @@ def loop_queue(self):
365385
if query == 'commit':
366386
self.is_query_commit()
367387
elif query == 'exit':
368-
self.db.conn.close()
369-
logger.info('sqlThread exiting gracefully.')
388+
self.is_query_exit()
370389
return False
371390
elif query == 'movemessagstoprog':
372-
logger.debug('the sqlThread is moving the messages.dat file to the local program directory.')
373391
self.is_query_movemessagstoprog()
374392
elif query == 'movemessagstoappdata':
375-
logger.debug('the sqlThread is moving the messages.dat file to the Appdata folder.')
376-
try:
377-
self.db.conn.commit()
378-
except Exception as err:
379-
command = 'movemessagstoappdata'
380-
self.error_handler(err, command)
381-
self.db.conn.close()
382-
shutil.move(
383-
paths.lookupExeFolder() + 'messages.dat', paths.lookupAppdataFolder() + 'messages.dat')
384-
self.db.conn = sqlite3.connect(paths.lookupAppdataFolder() + 'messages.dat')
385-
self.db.conn.text_factory = str
386-
self.db.cur = self.db.conn.cursor()
393+
self.is_query_movemessagestoappdata()
387394
elif query == 'deleteandvacuume':
388395
self.is_query_deleteandvacuume()
389396
else:
390397
self.rowcount = self.is_query_other(query)
391398
helper_sql.sqlReturnQueue.put((self.db.cur.fetchall(), self.rowcount))
392-
# helper_sql.sqlSubmitQueue.task_done()
393399
return True
394400

395401
def run(self): # pylint: disable=R0204, E501

0 commit comments

Comments
 (0)