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

View File

@ -59,11 +59,10 @@ class sqlThread(threading.Thread):
self.cur.execute( '''INSERT INTO settings VALUES('lastvacuumtime',?)''', ( self.cur.execute( '''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
int(time.time()),)) int(time.time()),))
self.conn.commit() self.conn.commit()
print 'Created messages database file' logger.info('Created messages database file')
except Exception as err: except Exception as err:
if str(err) == 'table inbox already exists': if str(err) == 'table inbox already exists':
with shared.printLock: logger.debug('Database file already exists.')
print 'Database file already exists.'
else: else:
sys.stderr.write( sys.stderr.write(
@ -145,13 +144,13 @@ class sqlThread(threading.Thread):
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
if self.cur.fetchall() == []: if self.cur.fetchall() == []:
# The settings table doesn't exist. We need to make it. # 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( self.cur.execute(
'''CREATE TABLE settings (key text, value blob, UNIQUE(key) ON CONFLICT REPLACE)''' ) '''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('version','1')''')
self.cur.execute( '''INSERT INTO settings VALUES('lastvacuumtime',?)''', ( self.cur.execute( '''INSERT INTO settings VALUES('lastvacuumtime',?)''', (
int(time.time()),)) 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( self.cur.execute(
'''CREATE TEMPORARY TABLE pubkeys_backup(hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE);''') '''CREATE TEMPORARY TABLE pubkeys_backup(hash blob, transmitdata blob, time int, usedpersonally text, UNIQUE(hash) ON CONFLICT REPLACE);''')
self.cur.execute( self.cur.execute(
@ -162,17 +161,17 @@ class sqlThread(threading.Thread):
self.cur.execute( self.cur.execute(
'''INSERT INTO pubkeys SELECT hash, transmitdata, time, usedpersonally FROM pubkeys_backup;''') '''INSERT INTO pubkeys SELECT hash, transmitdata, time, usedpersonally FROM pubkeys_backup;''')
self.cur.execute( '''DROP TABLE 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( self.cur.execute(
'''delete from inventory where objecttype = 'pubkey';''') '''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( self.cur.execute(
'''delete from subscriptions where address='BM-BbkPSZbzPwpVcYZpU4yHwf9ZPEapN5Zx' ''') '''delete from subscriptions where address='BM-BbkPSZbzPwpVcYZpU4yHwf9ZPEapN5Zx' ''')
self.cur.execute( self.cur.execute(
'''INSERT INTO subscriptions VALUES('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''') '''INSERT INTO subscriptions VALUES('Bitmessage new releases/announcements','BM-GtovgYdgs7qXPkoYaRgrLFuFKz1SFpsw',1)''')
print 'Commiting.' logger.debug('Commiting.')
self.conn.commit() 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 ''') self.cur.execute( ''' VACUUM ''')
# After code refactoring, the possible status values for sent messages # 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.cur.execute('''DELETE FROM pubkeys WHERE hash='1234' ''')
self.conn.commit() self.conn.commit()
if transmitdata == '': 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') 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')
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('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) os._exit(0)
except Exception as err: except Exception as err:
print err logger.error(err)
# Let us check to see the last time we vaccumed the messages.dat file. # 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. # 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: for row in queryreturn:
value, = row value, = row
if int(value) < int(time.time()) - 2592000: 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 ''') self.cur.execute( ''' VACUUM ''')
item = '''update settings set value=? WHERE key='lastvacuumtime';''' item = '''update settings set value=? WHERE key='lastvacuumtime';'''
parameters = (int(time.time()),) parameters = (int(time.time()),)
@ -230,13 +229,11 @@ class sqlThread(threading.Thread):
self.conn.commit() self.conn.commit()
elif item == 'exit': elif item == 'exit':
self.conn.close() self.conn.close()
with shared.printLock: logger.info('sqlThread exiting gracefully.')
print 'sqlThread exiting gracefully.'
return return
elif item == 'movemessagstoprog': elif item == 'movemessagstoprog':
with shared.printLock: logger.debug('the sqlThread is moving the messages.dat file to the local program directory.')
print 'the sqlThread is moving the messages.dat file to the local program directory.'
self.conn.commit() self.conn.commit()
self.conn.close() self.conn.close()
@ -246,8 +243,7 @@ class sqlThread(threading.Thread):
self.conn.text_factory = str self.conn.text_factory = str
self.cur = self.conn.cursor() self.cur = self.conn.cursor()
elif item == 'movemessagstoappdata': elif item == 'movemessagstoappdata':
with shared.printLock: logger.debug('the sqlThread is moving the messages.dat file to the Appdata folder.')
print 'the sqlThread is moving the messages.dat file to the Appdata folder.'
self.conn.commit() self.conn.commit()
self.conn.close() self.conn.close()
@ -268,10 +264,8 @@ class sqlThread(threading.Thread):
try: try:
self.cur.execute(item, parameters) self.cur.execute(item, parameters)
except Exception as err: except Exception as err:
with shared.printLock: 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))
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( logger.fatal('This program shall now abruptly exit!')
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')
os._exit(0) os._exit(0)