Skip to content

Commit 2e2db97

Browse files
committed
Don't propagate loggers; add some logging.
1 parent eed8c66 commit 2e2db97

2 files changed

Lines changed: 31 additions & 33 deletions

File tree

src/debug.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,12 +48,15 @@
4848
'loggers': {
4949
'console_only': {
5050
'handlers': ['console'],
51+
'propagate' : 0
5152
},
5253
'file_only': {
5354
'handlers': ['file'],
55+
'propagate' : 0
5456
},
5557
'both': {
5658
'handlers': ['console', 'file'],
59+
'propagate' : 0
5760
},
5861
},
5962
'root': {

src/shared.py

Lines changed: 28 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,8 @@ def lookupAppdataFolder():
118118
if "HOME" in environ:
119119
dataFolder = path.join(os.environ["HOME"], "Library/Application Support/", APPNAME) + '/'
120120
else:
121-
print 'Could not find home folder, please report this message and your OS X version to the BitMessage Github.'
121+
logger.critical('Could not find home folder, please report this message and your '
122+
'OS X version to the BitMessage Github.')
122123
sys.exit()
123124

124125
elif 'win32' in sys.platform or 'win64' in sys.platform:
@@ -129,13 +130,14 @@ def lookupAppdataFolder():
129130
dataFolder = path.join(environ["XDG_CONFIG_HOME"], APPNAME)
130131
except KeyError:
131132
dataFolder = path.join(environ["HOME"], ".config", APPNAME)
133+
132134
# Migrate existing data to the proper location if this is an existing install
133-
try:
134-
print "Moving data folder to ~/.config/%s" % APPNAME
135-
move(path.join(environ["HOME"], ".%s" % APPNAME), dataFolder)
136-
dataFolder = dataFolder + '/'
137-
except IOError:
138-
dataFolder = dataFolder + '/'
135+
if not os.path.exists(dataFolder):
136+
try:
137+
logger.info("Moving data folder to ~/.config/%s" % APPNAME)
138+
move(path.join(environ["HOME"], ".%s" % APPNAME), dataFolder)
139+
except IOError:
140+
dataFolder = dataFolder + '/'
139141
return dataFolder
140142

141143
def isAddressInMyAddressBook(address):
@@ -200,9 +202,7 @@ def decodeWalletImportFormat(WIFstring):
200202

201203

202204
def reloadMyAddressHashes():
203-
printLock.acquire()
204-
print 'reloading keys from keys.dat file'
205-
printLock.release()
205+
logger.debug('reloading keys from keys.dat file')
206206
myECCryptorObjects.clear()
207207
myAddressesByHash.clear()
208208
#myPrivateKeys.clear()
@@ -221,9 +221,7 @@ def reloadMyAddressHashes():
221221
sys.stderr.write('Error in reloadMyAddressHashes: Can\'t handle address versions other than 2 or 3.\n')
222222

223223
def reloadBroadcastSendersForWhichImWatching():
224-
printLock.acquire()
225-
print 'reloading subscriptions...'
226-
printLock.release()
224+
logger.debug('reloading subscriptions...')
227225
broadcastSendersForWhichImWatching.clear()
228226
MyECSubscriptionCryptorObjects.clear()
229227
sqlLock.acquire()
@@ -246,46 +244,43 @@ def doCleanShutdown():
246244
knownNodesLock.acquire()
247245
UISignalQueue.put(('updateStatusBar','Saving the knownNodes list of peers to disk...'))
248246
output = open(appdata + 'knownnodes.dat', 'wb')
249-
print 'finished opening knownnodes.dat. Now pickle.dump'
247+
logger.info('finished opening knownnodes.dat. Now pickle.dump')
250248
pickle.dump(knownNodes, output)
251-
print 'Completed pickle.dump. Closing output...'
249+
logger.info('Completed pickle.dump. Closing output...')
252250
output.close()
253251
knownNodesLock.release()
254-
printLock.acquire()
255-
print 'Finished closing knownnodes.dat output file.'
256-
printLock.release()
252+
logger.info('Finished closing knownnodes.dat output file.')
257253
UISignalQueue.put(('updateStatusBar','Done saving the knownNodes list of peers to disk.'))
258254

259255
broadcastToSendDataQueues((0, 'shutdown', 'all'))
260256

261-
printLock.acquire()
262-
print 'Flushing inventory in memory out to disk...'
263-
printLock.release()
264-
UISignalQueue.put(('updateStatusBar','Flushing inventory in memory out to disk. This should normally only take a second...'))
257+
logger.info('Flushing inventory in memory out to disk...')
258+
UISignalQueue.put(('updateStatusBar','Flushing inventory in memory out to disk. '
259+
'This should normally only take a second...'))
265260
flushInventory()
266261

267-
#This one last useless query will guarantee that the previous flush committed before we close the program.
262+
# This one last useless query will guarantee that the previous flush committed before we close
263+
# the program.
268264
sqlLock.acquire()
269265
sqlSubmitQueue.put('SELECT address FROM subscriptions')
270266
sqlSubmitQueue.put('')
271267
sqlReturnQueue.get()
272268
sqlSubmitQueue.put('exit')
273269
sqlLock.release()
274-
printLock.acquire()
275-
print 'Finished flushing inventory.'
276-
printLock.release()
277-
278-
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.
270+
logger.info('Finished flushing inventory.')
271+
# Wait long enough to guarantee that any running proof of work worker threads will check the
272+
# shutdown variable and exit. If the main thread closes before they do then they won't stop.
273+
time.sleep(.25)
279274

280275
if safeConfigGetBoolean('bitmessagesettings','daemon'):
281-
printLock.acquire()
282-
print 'Done.'
283-
printLock.release()
276+
logger.info('Clean shutdown complete.')
284277
os._exit(0)
285278

286-
#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.
279+
# When you want to command a sendDataThread to do something, like shutdown or send some data, this
280+
# function puts your data into the queues for each of the sendDataThreads. The sendDataThreads are
281+
# responsible for putting their queue into (and out of) the sendDataQueues list.
287282
def broadcastToSendDataQueues(data):
288-
#print 'running broadcastToSendDataQueues'
283+
# logger.debug('running broadcastToSendDataQueues')
289284
for q in sendDataQueues:
290285
q.put((data))
291286

0 commit comments

Comments
 (0)