From 2e2db97250d38f190cdc7aeb600360ba9c4054a6 Mon Sep 17 00:00:00 2001 From: Gregor Robinson Date: Wed, 10 Jul 2013 19:50:18 +0100 Subject: [PATCH 1/2] Don't propagate loggers; add some logging. --- src/debug.py | 3 +++ src/shared.py | 61 +++++++++++++++++++++++---------------------------- 2 files changed, 31 insertions(+), 33 deletions(-) diff --git a/src/debug.py b/src/debug.py index d8033f2d..14214686 100644 --- a/src/debug.py +++ b/src/debug.py @@ -48,12 +48,15 @@ logging.config.dictConfig({ 'loggers': { 'console_only': { 'handlers': ['console'], + 'propagate' : 0 }, 'file_only': { 'handlers': ['file'], + 'propagate' : 0 }, 'both': { 'handlers': ['console', 'file'], + 'propagate' : 0 }, }, 'root': { diff --git a/src/shared.py b/src/shared.py index 4b3ef73b..313e2ac6 100644 --- a/src/shared.py +++ b/src/shared.py @@ -118,7 +118,8 @@ def lookupAppdataFolder(): if "HOME" in environ: dataFolder = path.join(os.environ["HOME"], "Library/Application Support/", APPNAME) + '/' else: - print 'Could not find home folder, please report this message and your OS X version to the BitMessage Github.' + logger.critical('Could not find home folder, please report this message and your ' + 'OS X version to the BitMessage Github.') sys.exit() elif 'win32' in sys.platform or 'win64' in sys.platform: @@ -129,13 +130,14 @@ def lookupAppdataFolder(): dataFolder = path.join(environ["XDG_CONFIG_HOME"], APPNAME) except KeyError: dataFolder = path.join(environ["HOME"], ".config", APPNAME) + # Migrate existing data to the proper location if this is an existing install - try: - print "Moving data folder to ~/.config/%s" % APPNAME - move(path.join(environ["HOME"], ".%s" % APPNAME), dataFolder) - dataFolder = dataFolder + '/' - except IOError: - dataFolder = dataFolder + '/' + if not os.path.exists(dataFolder): + try: + logger.info("Moving data folder to ~/.config/%s" % APPNAME) + move(path.join(environ["HOME"], ".%s" % APPNAME), dataFolder) + except IOError: + dataFolder = dataFolder + '/' return dataFolder def isAddressInMyAddressBook(address): @@ -200,9 +202,7 @@ def decodeWalletImportFormat(WIFstring): def reloadMyAddressHashes(): - printLock.acquire() - print 'reloading keys from keys.dat file' - printLock.release() + logger.debug('reloading keys from keys.dat file') myECCryptorObjects.clear() myAddressesByHash.clear() #myPrivateKeys.clear() @@ -221,9 +221,7 @@ def reloadMyAddressHashes(): sys.stderr.write('Error in reloadMyAddressHashes: Can\'t handle address versions other than 2 or 3.\n') def reloadBroadcastSendersForWhichImWatching(): - printLock.acquire() - print 'reloading subscriptions...' - printLock.release() + logger.debug('reloading subscriptions...') broadcastSendersForWhichImWatching.clear() MyECSubscriptionCryptorObjects.clear() sqlLock.acquire() @@ -246,46 +244,43 @@ def doCleanShutdown(): knownNodesLock.acquire() UISignalQueue.put(('updateStatusBar','Saving the knownNodes list of peers to disk...')) output = open(appdata + 'knownnodes.dat', 'wb') - print 'finished opening knownnodes.dat. Now pickle.dump' + logger.info('finished opening knownnodes.dat. Now pickle.dump') pickle.dump(knownNodes, output) - print 'Completed pickle.dump. Closing output...' + logger.info('Completed pickle.dump. Closing output...') output.close() knownNodesLock.release() - printLock.acquire() - print 'Finished closing knownnodes.dat output file.' - printLock.release() + logger.info('Finished closing knownnodes.dat output file.') UISignalQueue.put(('updateStatusBar','Done saving the knownNodes list of peers to disk.')) broadcastToSendDataQueues((0, 'shutdown', 'all')) - printLock.acquire() - print 'Flushing inventory in memory out to disk...' - printLock.release() - UISignalQueue.put(('updateStatusBar','Flushing inventory in memory out to disk. This should normally only take a second...')) + logger.info('Flushing inventory in memory out to disk...') + UISignalQueue.put(('updateStatusBar','Flushing inventory in memory out to disk. ' + 'This should normally only take a second...')) flushInventory() - #This one last useless query will guarantee that the previous flush committed before we close the program. + # This one last useless query will guarantee that the previous flush committed before we close + # the program. sqlLock.acquire() sqlSubmitQueue.put('SELECT address FROM subscriptions') sqlSubmitQueue.put('') sqlReturnQueue.get() sqlSubmitQueue.put('exit') sqlLock.release() - printLock.acquire() - print 'Finished flushing inventory.' - printLock.release() - - time.sleep(.25) #Wait long enough to guarantee that any running proof of work worker threads will check the shutdown variable and exit. If the main thread closes before they do then they won't stop. + logger.info('Finished flushing inventory.') + # Wait long enough to guarantee that any running proof of work worker threads will check the + # shutdown variable and exit. If the main thread closes before they do then they won't stop. + time.sleep(.25) if safeConfigGetBoolean('bitmessagesettings','daemon'): - printLock.acquire() - print 'Done.' - printLock.release() + logger.info('Clean shutdown complete.') os._exit(0) -#When you want to command a sendDataThread to do something, like shutdown or send some data, this function puts your data into the queues for each of the sendDataThreads. The sendDataThreads are responsible for putting their queue into (and out of) the sendDataQueues list. +# When you want to command a sendDataThread to do something, like shutdown or send some data, this +# function puts your data into the queues for each of the sendDataThreads. The sendDataThreads are +# responsible for putting their queue into (and out of) the sendDataQueues list. def broadcastToSendDataQueues(data): - #print 'running broadcastToSendDataQueues' + # logger.debug('running broadcastToSendDataQueues') for q in sendDataQueues: q.put((data)) -- 2.45.1 From 3179ea30f01912a55d1ede14b1fc161d48b7969a Mon Sep 17 00:00:00 2001 From: Gregor Robinson Date: Wed, 10 Jul 2013 20:15:04 +0100 Subject: [PATCH 2/2] These changes slipped from last commit. Sorry. --- src/shared.py | 16 +++++++++------- 1 file changed, 9 insertions(+), 7 deletions(-) diff --git a/src/shared.py b/src/shared.py index 313e2ac6..c706038a 100644 --- a/src/shared.py +++ b/src/shared.py @@ -21,6 +21,7 @@ import socket import random import highlevelcrypto import shared +from debug import logger config = ConfigParser.SafeConfigParser() myECCryptorObjects = {} @@ -132,11 +133,11 @@ def lookupAppdataFolder(): dataFolder = path.join(environ["HOME"], ".config", APPNAME) # Migrate existing data to the proper location if this is an existing install - if not os.path.exists(dataFolder): - try: - logger.info("Moving data folder to ~/.config/%s" % APPNAME) - move(path.join(environ["HOME"], ".%s" % APPNAME), dataFolder) - except IOError: + try: + logger.info("Moving data folder to %s" % (dataFolder)) + move(path.join(environ["HOME"], ".%s" % APPNAME), dataFolder) + except IOError: + pass dataFolder = dataFolder + '/' return dataFolder @@ -255,8 +256,9 @@ def doCleanShutdown(): broadcastToSendDataQueues((0, 'shutdown', 'all')) logger.info('Flushing inventory in memory out to disk...') - UISignalQueue.put(('updateStatusBar','Flushing inventory in memory out to disk. ' - 'This should normally only take a second...')) + UISignalQueue.put(( + 'updateStatusBar', + 'Flushing inventory in memory out to disk. This should normally only take a second...')) flushInventory() # This one last useless query will guarantee that the previous flush committed before we close -- 2.45.1