Converted print statement in class_sqlThread to logger calls

This commit is contained in:
Jordan Hall 2013-08-11 00:02:38 +01:00
parent 7850e9aa68
commit f83b636bc0
1 changed files with 17 additions and 23 deletions

View File

@ -59,11 +59,10 @@ class sqlThread(threading.Thread):
self.cur.execute( '''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
int(time.time()),))
self.conn.commit()
print 'Created messages database file'
logger.info('Created messages database file')
except Exception as err:
if str(err) == 'table inbox already exists':
with shared.printLock:
print 'Database file already exists.'
logger.debug('Database file already exists.')
else:
sys.stderr.write(
@ -145,13 +144,13 @@ class sqlThread(threading.Thread):
self.cur.execute(item, parameters)
if self.cur.fetchall() == []:
# The settings table doesn't exist. We need to make it.
print 'In messages.dat database, creating new \'settings\' table.'
logger.debug('In messages.dat database, creating new \'settings\' table.')
self.cur.execute(
'''CREATE TABLE settings (key text, value blob, UNIQUE(key) ON CONFLICT REPLACE)''' )
self.cur.execute( '''INSERT INTO settings VALUES('version','1')''')
self.cur.execute( '''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
int(time.time()),))
print 'In messages.dat database, removing an obsolete field from the pubkeys table.'
logger.debug('In messages.dat database, removing an obsolete field from the pubkeys table.')
self.cur.execute(
'''CREATE TEMPORARY TABLE pubkeys_backup(hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE);''')
self.cur.execute(
@ -162,17 +161,17 @@ class sqlThread(threading.Thread):
self.cur.execute(
'''INSERT INTO pubkeys SELECT hash, transmitdata, time, usedpersonally FROM pubkeys_backup;''')
self.cur.execute( '''DROP TABLE pubkeys_backup;''')
print 'Deleting all pubkeys from inventory. They will be redownloaded and then saved with the correct times.'
logger.debug('Deleting all pubkeys from inventory. They will be redownloaded and then saved with the correct times.')
self.cur.execute(
'''delete from inventory where objecttype = 'pubkey';''')
print 'replacing Bitmessage announcements mailing list with a new one.'
logger.debug('replacing Bitmessage announcements mailing list with a new one.')
self.cur.execute(
'''delete from subscriptions where address='BM-BbkPSZbzPwpVcYZpU4yHwf9ZPEapN5Zx' ''')
self.cur.execute(
'''INSERT INTO subscriptions VALUES('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
print 'Commiting.'
logger.debug('Commiting.')
self.conn.commit()
print 'Vacuuming message.dat. You might notice that the file size gets much smaller.'
logger.debug('Vacuuming message.dat. You might notice that the file size gets much smaller.')
self.cur.execute( ''' VACUUM ''')
# After code refactoring, the possible status values for sent messages
@ -203,11 +202,11 @@ class sqlThread(threading.Thread):
self.cur.execute('''DELETE FROM pubkeys WHERE hash='1234' ''')
self.conn.commit()
if transmitdata == '':
sys.stderr.write('Problem: The version of SQLite you have cannot store Null values. Please download and install the latest revision of your version of Python (for example, the latest Python 2.7 revision) and try again.\n')
sys.stderr.write('PyBitmessage will now exit very abruptly. You may now see threading errors related to this abrupt exit but the problem you need to solve is related to SQLite.\n\n')
logger.fatal('Problem: The version of SQLite you have cannot store Null values. Please download and install the latest revision of your version of Python (for example, the latest Python 2.7 revision) and try again.\n')
logger.fatal('PyBitmessage will now exit very abruptly. You may now see threading errors related to this abrupt exit but the problem you need to solve is related to SQLite.\n\n')
os._exit(0)
except Exception as err:
print err
logger.error(err)
# Let us check to see the last time we vaccumed the messages.dat file.
# If it has been more than a month let's do it now.
@ -218,7 +217,7 @@ class sqlThread(threading.Thread):
for row in queryreturn:
value, = row
if int(value) < int(time.time()) - 2592000:
print 'It has been a long time since the messages.dat file has been vacuumed. Vacuuming now...'
logger.info('It has been a long time since the messages.dat file has been vacuumed. Vacuuming now...')
self.cur.execute( ''' VACUUM ''')
item = '''update settings set value=? WHERE key='lastvacuumtime';'''
parameters = (int(time.time()),)
@ -230,13 +229,11 @@ class sqlThread(threading.Thread):
self.conn.commit()
elif item == 'exit':
self.conn.close()
with shared.printLock:
print 'sqlThread exiting gracefully.'
logger.info('sqlThread exiting gracefully.')
return
elif item == 'movemessagstoprog':
with shared.printLock:
print 'the sqlThread is moving the messages.dat file to the local program directory.'
logger.debug('the sqlThread is moving the messages.dat file to the local program directory.')
self.conn.commit()
self.conn.close()
@ -246,8 +243,7 @@ class sqlThread(threading.Thread):
self.conn.text_factory = str
self.cur = self.conn.cursor()
elif item == 'movemessagstoappdata':
with shared.printLock:
print 'the sqlThread is moving the messages.dat file to the Appdata folder.'
logger.debug('the sqlThread is moving the messages.dat file to the Appdata folder.')
self.conn.commit()
self.conn.close()
@ -268,10 +264,8 @@ class sqlThread(threading.Thread):
try:
self.cur.execute(item, parameters)
except Exception as err:
with shared.printLock:
sys.stderr.write('\nMajor error occurred when trying to execute a SQL statement within the sqlThread. Please tell Atheros about this error message or post it in the forum! Error occurred while trying to execute statement: "' + str(
item) + '" Here are the parameters; you might want to censor this data with asterisks (***) as it can contain private information: ' + str(repr(parameters)) + '\nHere is the actual error message thrown by the sqlThread: ' + str(err) + '\n')
sys.stderr.write('This program shall now abruptly exit!\n')
logger.fatal('Major error occurred when trying to execute a SQL statement within the sqlThread. Please tell Atheros about this error message or post it in the forum! Error occurred while trying to execute statement: "%s" Here are the parameters; you might want to censor this data with asterisks (***) as it can contain private information: %s. Here is the actual error message thrown by the sqlThread: %s', str(item), str(repr(parameters)), str(err))
logger.fatal('This program shall now abruptly exit!')
os._exit(0)