From 0f357529edfc1ded9991bdacf33fe7d877beef41 Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Tue, 6 Aug 2013 22:28:21 +0100 Subject: [PATCH 1/8] bitmessagemain, changing prints tologger functions --- src/bitmessagemain.py | 34 +++++++++++++++------------------- 1 file changed, 15 insertions(+), 19 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index b156cd0d..126c502b 100644 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -34,11 +34,13 @@ from class_addressGenerator import * # Helper Functions import helper_bootstrap +# Debug logger +from debug import logger + import sys if sys.platform == 'darwin': if float("{1}.{2}".format(*sys.version_info)) < 7.5: - print "You should use python 2.7.5 or greater." - print "Your version: {0}.{1}.{2}".format(*sys.version_info) + logger.critical("You should use python 2.7.5 or greater. Your version: {0}.{1}.{2}".format(*sys.version_info)) sys.exit(0) def connectToStream(streamNumber): @@ -126,7 +128,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): else: return False else: - print 'Authentication failed because header lacks Authentication field' + logger.warn('Authentication failed because header lacks Authentication field') time.sleep(2) return False @@ -276,7 +278,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): if numberOfAddresses > 999: return 'API Error 0005: You have (accidentally?) specified too many addresses to make. Maximum 999. This check only exists to prevent mischief; if you really want to create more addresses than this, contact the Bitmessage developers and we can modify the check or you can do it yourself by searching the source code for this message.' shared.apiAddressGeneratorReturnQueue.queue.clear() - print 'Requesting that the addressGenerator create', numberOfAddresses, 'addresses.' + logger.debug('Requesting that the addressGenerator create', numberOfAddresses, 'addresses.') shared.addressGeneratorQueue.put( ('createDeterministicAddresses', addressVersionNumber, streamNumber, 'unused API address', numberOfAddresses, passphrase, eighteenByteRipe, nonceTrialsPerByte, payloadLengthExtraBytes)) @@ -302,7 +304,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): if streamNumber != 1: return 'API Error 0003: The stream number must be 1. Others aren\'t supported.' shared.apiAddressGeneratorReturnQueue.queue.clear() - print 'Requesting that the addressGenerator create', numberOfAddresses, 'addresses.' + logger.debug('Requesting that the addressGenerator create', numberOfAddresses, 'addresses.') shared.addressGeneratorQueue.put( ('getDeterministicAddress', addressVersionNumber, streamNumber, 'unused API address', numberOfAddresses, passphrase, eighteenByteRipe)) @@ -515,8 +517,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, toRipe = decodeAddress( toAddress) if status != 'success': - with shared.printLock: - print 'API Error 0007: Could not decode address:', toAddress, ':', status + logger.warn('API Error 0007: Could not decode address:', toAddress, ':', status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + toAddress @@ -532,8 +533,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, fromRipe = decodeAddress( fromAddress) if status != 'success': - with shared.printLock: - print 'API Error 0007: Could not decode address:', fromAddress, ':', status + logger.warn('API Error 0007: Could not decode address:', fromAddress, ':', status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + fromAddress @@ -597,8 +597,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, fromRipe = decodeAddress( fromAddress) if status != 'success': - with shared.printLock: - print 'API Error 0007: Could not decode address:', fromAddress, ':', status + logger.warn('API Error 0007: Could not decode address:', fromAddress, ':', status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + fromAddress @@ -668,8 +667,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, toRipe = decodeAddress( address) if status != 'success': - with shared.printLock: - print 'API Error 0007: Could not decode address:', address, ':', status + logger.warn('API Error 0007: Could not decode address:', address, ':', status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + address @@ -808,8 +806,7 @@ if __name__ == "__main__": except: apiNotifyPath = '' if apiNotifyPath != '': - with shared.printLock: - print 'Trying to call', apiNotifyPath + logger.debug('Trying to call', apiNotifyPath) call([apiNotifyPath, "startingUp"]) singleAPIThread = singleAPI() @@ -827,16 +824,15 @@ if __name__ == "__main__": try: from PyQt4 import QtCore, QtGui except Exception as err: - print 'PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download PyQt from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\'. If you want to run in daemon mode, see https://bitmessage.org/wiki/Daemon' - print 'Error message:', err + logger.error('PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download PyQt from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\'. If you want to run in daemon mode, see https://bitmessage.org/wiki/Daemon') + logger.error('Error message: '+ err) os._exit(0) import bitmessageqt bitmessageqt.run() else: shared.config.remove_option('bitmessagesettings', 'dontconnect') - with shared.printLock: - print 'Running as a daemon. You can use Ctrl+C to exit.' + logger.info('Running as a daemon. You can use Ctrl+C to exit.') while True: time.sleep(20) From 26b82984a2098a75178eac9e34d3ff98ee6a2b3c Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Wed, 7 Aug 2013 21:12:32 +0100 Subject: [PATCH 2/8] Fixes to logger function calls --- src/bitmessagemain.py | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 126c502b..3a99fc19 100644 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -40,7 +40,7 @@ from debug import logger import sys if sys.platform == 'darwin': if float("{1}.{2}".format(*sys.version_info)) < 7.5: - logger.critical("You should use python 2.7.5 or greater. Your version: {0}.{1}.{2}".format(*sys.version_info)) + logger.critical("You should use python 2.7.5 or greater. Your version: %s", format(*sys.version_info)) sys.exit(0) def connectToStream(streamNumber): @@ -278,7 +278,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): if numberOfAddresses > 999: return 'API Error 0005: You have (accidentally?) specified too many addresses to make. Maximum 999. This check only exists to prevent mischief; if you really want to create more addresses than this, contact the Bitmessage developers and we can modify the check or you can do it yourself by searching the source code for this message.' shared.apiAddressGeneratorReturnQueue.queue.clear() - logger.debug('Requesting that the addressGenerator create', numberOfAddresses, 'addresses.') + logger.debug('Requesting that the addressGenerator create %s addresses.', numberOfAddresses) shared.addressGeneratorQueue.put( ('createDeterministicAddresses', addressVersionNumber, streamNumber, 'unused API address', numberOfAddresses, passphrase, eighteenByteRipe, nonceTrialsPerByte, payloadLengthExtraBytes)) @@ -304,7 +304,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): if streamNumber != 1: return 'API Error 0003: The stream number must be 1. Others aren\'t supported.' shared.apiAddressGeneratorReturnQueue.queue.clear() - logger.debug('Requesting that the addressGenerator create', numberOfAddresses, 'addresses.') + logger.debug('Requesting that the addressGenerator create %s addresses.', numberOfAddresses) shared.addressGeneratorQueue.put( ('getDeterministicAddress', addressVersionNumber, streamNumber, 'unused API address', numberOfAddresses, passphrase, eighteenByteRipe)) @@ -517,7 +517,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, toRipe = decodeAddress( toAddress) if status != 'success': - logger.warn('API Error 0007: Could not decode address:', toAddress, ':', status) + logger.warn('API Error 0007: Could not decode address: %s : %s', toAddress, status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + toAddress @@ -533,7 +533,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, fromRipe = decodeAddress( fromAddress) if status != 'success': - logger.warn('API Error 0007: Could not decode address:', fromAddress, ':', status) + logger.warn('API Error 0007: Could not decode address: %s : %s', fromAddress, status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + fromAddress @@ -597,7 +597,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, fromRipe = decodeAddress( fromAddress) if status != 'success': - logger.warn('API Error 0007: Could not decode address:', fromAddress, ':', status) + logger.warn('API Error 0007: Could not decode address: %s : %s', fromAddress, status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + fromAddress @@ -667,7 +667,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, toRipe = decodeAddress( address) if status != 'success': - logger.warn('API Error 0007: Could not decode address:', address, ':', status) + logger.warn('API Error 0007: Could not decode address: %s : %s', address, status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + address @@ -806,7 +806,7 @@ if __name__ == "__main__": except: apiNotifyPath = '' if apiNotifyPath != '': - logger.debug('Trying to call', apiNotifyPath) + logger.debug('Trying to call %s', apiNotifyPath) call([apiNotifyPath, "startingUp"]) singleAPIThread = singleAPI() @@ -825,7 +825,7 @@ if __name__ == "__main__": from PyQt4 import QtCore, QtGui except Exception as err: logger.error('PyBitmessage requires PyQt unless you want to run it as a daemon and interact with it using the API. You can download PyQt from http://www.riverbankcomputing.com/software/pyqt/download or by searching Google for \'PyQt Download\'. If you want to run in daemon mode, see https://bitmessage.org/wiki/Daemon') - logger.error('Error message: '+ err) + logger.error('Error message: %s', err) os._exit(0) import bitmessageqt From b529280160680d73056e4141231d04e4232dae23 Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Wed, 7 Aug 2013 21:22:23 +0100 Subject: [PATCH 3/8] Further fixes --- src/bitmessagemain.py | 8 ++++---- 1 file changed, 4 insertions(+), 4 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 3a99fc19..87fd5934 100644 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -517,7 +517,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, toRipe = decodeAddress( toAddress) if status != 'success': - logger.warn('API Error 0007: Could not decode address: %s : %s', toAddress, status) + logger.warn('API Error 0007: Could not decode address: %s', toAddress + ' : ' + status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + toAddress @@ -533,7 +533,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, fromRipe = decodeAddress( fromAddress) if status != 'success': - logger.warn('API Error 0007: Could not decode address: %s : %s', fromAddress, status) + logger.warn('API Error 0007: Could not decode address: %s', fromAddress + ' : ' + status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + fromAddress @@ -597,7 +597,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, fromRipe = decodeAddress( fromAddress) if status != 'success': - logger.warn('API Error 0007: Could not decode address: %s : %s', fromAddress, status) + logger.warn('API Error 0007: Could not decode address: %s', fromAddress + ' : ' + status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + fromAddress @@ -667,7 +667,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, toRipe = decodeAddress( address) if status != 'success': - logger.warn('API Error 0007: Could not decode address: %s : %s', address, status) + logger.warn('API Error 0007: Could not decode address: %s', address + ' : ' + status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + address From ab4d53593b76be8aa1a646a17bc86ab3d38c7614 Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Wed, 7 Aug 2013 21:34:46 +0100 Subject: [PATCH 4/8] Fix to python version critical log message --- src/bitmessagemain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 87fd5934..b3cf2df3 100644 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -40,7 +40,7 @@ from debug import logger import sys if sys.platform == 'darwin': if float("{1}.{2}".format(*sys.version_info)) < 7.5: - logger.critical("You should use python 2.7.5 or greater. Your version: %s", format(*sys.version_info)) + logger.critical("You should use python 2.7.5 or greater. Your version: %s", "{0}.{1}.{2}".format(*sys.version_info)) sys.exit(0) def connectToStream(streamNumber): From a69a00d186596b8b32ad8753a5a68846d87860b3 Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Fri, 9 Aug 2013 23:26:16 +0100 Subject: [PATCH 5/8] Improved logger function calls and import shared here instead of debug --- src/bitmessagemain.py | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index fffdafb7..44ed50b0 100644 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -34,8 +34,7 @@ from class_addressGenerator import * # Helper Functions import helper_bootstrap -# Debug logger -from debug import logger +import shared import sys if sys.platform == 'darwin': @@ -517,7 +516,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, toRipe = decodeAddress( toAddress) if status != 'success': - logger.warn('API Error 0007: Could not decode address: %s', toAddress + ' : ' + status) + logger.warn('API Error 0007: Could not decode address: %s:%s.', toAddress, status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + toAddress @@ -533,7 +532,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, fromRipe = decodeAddress( fromAddress) if status != 'success': - logger.warn('API Error 0007: Could not decode address: %s', fromAddress + ' : ' + status) + logger.warn('API Error 0007: Could not decode address: %s:%s.', fromAddress, status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + fromAddress @@ -597,7 +596,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, fromRipe = decodeAddress( fromAddress) if status != 'success': - logger.warn('API Error 0007: Could not decode address: %s', fromAddress + ' : ' + status) + logger.warn('API Error 0007: Could not decode address: %s:%s.', fromAddress, status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + fromAddress @@ -667,7 +666,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, toRipe = decodeAddress( address) if status != 'success': - logger.warn('API Error 0007: Could not decode address: %s', address + ' : ' + status) + logger.warn('API Error 0007: Could not decode address: %s:%s.', address, status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + address From 326e294932763d98eb8a77f1068458f0d634803c Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Fri, 9 Aug 2013 23:32:49 +0100 Subject: [PATCH 6/8] Reverted back to importing only logger instead of all of shared --- src/bitmessagemain.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 44ed50b0..383d82da 100644 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -34,7 +34,7 @@ from class_addressGenerator import * # Helper Functions import helper_bootstrap -import shared +from debug import logger import sys if sys.platform == 'darwin': From 2c09326c378865fe1229a6eb5f92fb4b4be3b9dd Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Sat, 10 Aug 2013 23:10:21 +0100 Subject: [PATCH 7/8] Changing text for API Error 0007 log warning --- src/bitmessagemain.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index 383d82da..a81767f9 100644 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -532,7 +532,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, fromRipe = decodeAddress( fromAddress) if status != 'success': - logger.warn('API Error 0007: Could not decode address: %s:%s.', fromAddress, status) + logger.warn('API Error 0007: Could not decode address %s. Status: %s.', fromAddress, status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + fromAddress @@ -596,7 +596,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, fromRipe = decodeAddress( fromAddress) if status != 'success': - logger.warn('API Error 0007: Could not decode address: %s:%s.', fromAddress, status) + logger.warn('API Error 0007: Could not decode address %s. Status: %s.', fromAddress, status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + fromAddress From 53ca5b03ffb6b35ac03588107dc4a1d5cde7aad4 Mon Sep 17 00:00:00 2001 From: Jordan Hall Date: Sat, 10 Aug 2013 23:13:15 +0100 Subject: [PATCH 8/8] Changing text for API Error 0007 log warning (cont.) --- src/bitmessagemain.py | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/bitmessagemain.py b/src/bitmessagemain.py index a81767f9..537b73eb 100644 --- a/src/bitmessagemain.py +++ b/src/bitmessagemain.py @@ -516,7 +516,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, toRipe = decodeAddress( toAddress) if status != 'success': - logger.warn('API Error 0007: Could not decode address: %s:%s.', toAddress, status) + logger.warn('API Error 0007: Could not decode address %s. Status: %s.', toAddress, status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + toAddress @@ -666,7 +666,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler): status, addressVersionNumber, streamNumber, toRipe = decodeAddress( address) if status != 'success': - logger.warn('API Error 0007: Could not decode address: %s:%s.', address, status) + logger.warn('API Error 0007: Could not decode address %s. Status: %s.', address, status) if status == 'checksumfailed': return 'API Error 0008: Checksum failed for address: ' + address