Refactoring of config parser and shared.py
- got rid of shared config parser and made it into a singleton - refactored safeConfigGetBoolean as a method of the config singleton - refactored safeConfigGet as a method of the config singleton - moved softwareVersion from shared.py into version.py - moved some global variables from shared.py into state.py - moved some protocol-specific functions from shared.py into protocol.py
This commit is contained in:
parent
2654b61bd7
commit
8bcfe80ad0
66
src/api.py
66
src/api.py
|
@ -19,6 +19,7 @@ from binascii import hexlify
|
|||
import shared
|
||||
import time
|
||||
from addresses import decodeAddress,addBMIfNotPresent,decodeVarint,calculateInventoryHash,varintDecodeError
|
||||
from configparser import BMConfigParser
|
||||
import helper_inbox
|
||||
import helper_sent
|
||||
import hashlib
|
||||
|
@ -30,6 +31,7 @@ from struct import pack
|
|||
from helper_sql import sqlQuery,sqlExecute,SqlBulkExecute,sqlStoredProcedure
|
||||
from debug import logger
|
||||
from inventory import Inventory
|
||||
from version import softwareVersion
|
||||
|
||||
# Helper Functions
|
||||
import proofofwork
|
||||
|
@ -120,7 +122,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
# handle Basic authentication
|
||||
(enctype, encstr) = self.headers.get('Authorization').split()
|
||||
(emailid, password) = encstr.decode('base64').split(':')
|
||||
if emailid == shared.config.get('bitmessagesettings', 'apiusername') and password == shared.config.get('bitmessagesettings', 'apipassword'):
|
||||
if emailid == BMConfigParser().get('bitmessagesettings', 'apiusername') and password == BMConfigParser().get('bitmessagesettings', 'apipassword'):
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
@ -163,22 +165,22 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
|
||||
def HandleListAddresses(self, method):
|
||||
data = '{"addresses":['
|
||||
configSections = shared.config.sections()
|
||||
configSections = BMConfigParser().sections()
|
||||
for addressInKeysFile in configSections:
|
||||
if addressInKeysFile != 'bitmessagesettings':
|
||||
status, addressVersionNumber, streamNumber, hash01 = decodeAddress(
|
||||
addressInKeysFile)
|
||||
if len(data) > 20:
|
||||
data += ','
|
||||
if shared.config.has_option(addressInKeysFile, 'chan'):
|
||||
chan = shared.config.getboolean(addressInKeysFile, 'chan')
|
||||
if BMConfigParser().has_option(addressInKeysFile, 'chan'):
|
||||
chan = BMConfigParser().getboolean(addressInKeysFile, 'chan')
|
||||
else:
|
||||
chan = False
|
||||
label = shared.config.get(addressInKeysFile, 'label')
|
||||
label = BMConfigParser().get(addressInKeysFile, 'label')
|
||||
if method == 'listAddresses2':
|
||||
label = label.encode('base64')
|
||||
data += json.dumps({'label': label, 'address': addressInKeysFile, 'stream':
|
||||
streamNumber, 'enabled': shared.config.getboolean(addressInKeysFile, 'enabled'), 'chan': chan}, indent=4, separators=(',', ': '))
|
||||
streamNumber, 'enabled': BMConfigParser().getboolean(addressInKeysFile, 'enabled'), 'chan': chan}, indent=4, separators=(',', ': '))
|
||||
data += ']}'
|
||||
return data
|
||||
|
||||
|
@ -236,21 +238,21 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
elif len(params) == 1:
|
||||
label, = params
|
||||
eighteenByteRipe = False
|
||||
nonceTrialsPerByte = shared.config.get(
|
||||
nonceTrialsPerByte = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
payloadLengthExtraBytes = shared.config.get(
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
elif len(params) == 2:
|
||||
label, eighteenByteRipe = params
|
||||
nonceTrialsPerByte = shared.config.get(
|
||||
nonceTrialsPerByte = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
payloadLengthExtraBytes = shared.config.get(
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
elif len(params) == 3:
|
||||
label, eighteenByteRipe, totalDifficulty = params
|
||||
nonceTrialsPerByte = int(
|
||||
shared.networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty)
|
||||
payloadLengthExtraBytes = shared.config.get(
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
elif len(params) == 4:
|
||||
label, eighteenByteRipe, totalDifficulty, smallMessageDifficulty = params
|
||||
|
@ -280,45 +282,45 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
addressVersionNumber = 0
|
||||
streamNumber = 0
|
||||
eighteenByteRipe = False
|
||||
nonceTrialsPerByte = shared.config.get(
|
||||
nonceTrialsPerByte = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
payloadLengthExtraBytes = shared.config.get(
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
elif len(params) == 2:
|
||||
passphrase, numberOfAddresses = params
|
||||
addressVersionNumber = 0
|
||||
streamNumber = 0
|
||||
eighteenByteRipe = False
|
||||
nonceTrialsPerByte = shared.config.get(
|
||||
nonceTrialsPerByte = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
payloadLengthExtraBytes = shared.config.get(
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
elif len(params) == 3:
|
||||
passphrase, numberOfAddresses, addressVersionNumber = params
|
||||
streamNumber = 0
|
||||
eighteenByteRipe = False
|
||||
nonceTrialsPerByte = shared.config.get(
|
||||
nonceTrialsPerByte = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
payloadLengthExtraBytes = shared.config.get(
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
elif len(params) == 4:
|
||||
passphrase, numberOfAddresses, addressVersionNumber, streamNumber = params
|
||||
eighteenByteRipe = False
|
||||
nonceTrialsPerByte = shared.config.get(
|
||||
nonceTrialsPerByte = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
payloadLengthExtraBytes = shared.config.get(
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
elif len(params) == 5:
|
||||
passphrase, numberOfAddresses, addressVersionNumber, streamNumber, eighteenByteRipe = params
|
||||
nonceTrialsPerByte = shared.config.get(
|
||||
nonceTrialsPerByte = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
payloadLengthExtraBytes = shared.config.get(
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
elif len(params) == 6:
|
||||
passphrase, numberOfAddresses, addressVersionNumber, streamNumber, eighteenByteRipe, totalDifficulty = params
|
||||
nonceTrialsPerByte = int(
|
||||
shared.networkDefaultProofOfWorkNonceTrialsPerByte * totalDifficulty)
|
||||
payloadLengthExtraBytes = shared.config.get(
|
||||
payloadLengthExtraBytes = BMConfigParser().get(
|
||||
'bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
elif len(params) == 7:
|
||||
passphrase, numberOfAddresses, addressVersionNumber, streamNumber, eighteenByteRipe, totalDifficulty, smallMessageDifficulty = params
|
||||
|
@ -443,13 +445,13 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
address, = params
|
||||
status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(address)
|
||||
address = addBMIfNotPresent(address)
|
||||
if not shared.config.has_section(address):
|
||||
if not BMConfigParser().has_section(address):
|
||||
raise APIError(13, 'Could not find this address in your keys.dat file.')
|
||||
if not shared.safeConfigGetBoolean(address, 'chan'):
|
||||
if not BMConfigParser().safeGetBoolean(address, 'chan'):
|
||||
raise APIError(25, 'Specified address is not a chan address. Use deleteAddress API call instead.')
|
||||
shared.config.remove_section(address)
|
||||
BMConfigParser().remove_section(address)
|
||||
with open(shared.appdata + 'keys.dat', 'wb') as configfile:
|
||||
shared.config.write(configfile)
|
||||
BMConfigParser().write(configfile)
|
||||
return 'success'
|
||||
|
||||
def HandleDeleteAddress(self, params):
|
||||
|
@ -459,11 +461,11 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
address, = params
|
||||
status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(address)
|
||||
address = addBMIfNotPresent(address)
|
||||
if not shared.config.has_section(address):
|
||||
if not BMConfigParser().has_section(address):
|
||||
raise APIError(13, 'Could not find this address in your keys.dat file.')
|
||||
shared.config.remove_section(address)
|
||||
BMConfigParser().remove_section(address)
|
||||
with open(shared.appdata + 'keys.dat', 'wb') as configfile:
|
||||
shared.config.write(configfile)
|
||||
BMConfigParser().write(configfile)
|
||||
shared.UISignalQueue.put(('rerenderMessagelistFromLabels',''))
|
||||
shared.UISignalQueue.put(('rerenderMessagelistToLabels',''))
|
||||
shared.reloadMyAddressHashes()
|
||||
|
@ -659,7 +661,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
status, addressVersionNumber, streamNumber, toRipe = self._verifyAddress(toAddress)
|
||||
self._verifyAddress(fromAddress)
|
||||
try:
|
||||
fromAddressEnabled = shared.config.getboolean(
|
||||
fromAddressEnabled = BMConfigParser().getboolean(
|
||||
fromAddress, 'enabled')
|
||||
except:
|
||||
raise APIError(13, 'Could not find your fromAddress in the keys.dat file.')
|
||||
|
@ -723,7 +725,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
fromAddress = addBMIfNotPresent(fromAddress)
|
||||
self._verifyAddress(fromAddress)
|
||||
try:
|
||||
fromAddressEnabled = shared.config.getboolean(
|
||||
fromAddressEnabled = BMConfigParser().getboolean(
|
||||
fromAddress, 'enabled')
|
||||
except:
|
||||
raise APIError(13, 'could not find your fromAddress in the keys.dat file.')
|
||||
|
@ -946,7 +948,7 @@ class MySimpleXMLRPCRequestHandler(SimpleXMLRPCRequestHandler):
|
|||
networkStatus = 'connectedButHaveNotReceivedIncomingConnections'
|
||||
else:
|
||||
networkStatus = 'connectedAndReceivingIncomingConnections'
|
||||
return json.dumps({'networkConnections':len(shared.connectedHostsList),'numberOfMessagesProcessed':shared.numberOfMessagesProcessed, 'numberOfBroadcastsProcessed':shared.numberOfBroadcastsProcessed, 'numberOfPubkeysProcessed':shared.numberOfPubkeysProcessed, 'networkStatus':networkStatus, 'softwareName':'PyBitmessage','softwareVersion':shared.softwareVersion}, indent=4, separators=(',', ': '))
|
||||
return json.dumps({'networkConnections':len(shared.connectedHostsList),'numberOfMessagesProcessed':shared.numberOfMessagesProcessed, 'numberOfBroadcastsProcessed':shared.numberOfBroadcastsProcessed, 'numberOfPubkeysProcessed':shared.numberOfPubkeysProcessed, 'networkStatus':networkStatus, 'softwareName':'PyBitmessage','softwareVersion':softwareVersion}, indent=4, separators=(',', ': '))
|
||||
|
||||
def HandleDecodeAddress(self, params):
|
||||
# Return a meaningful decoding of an address.
|
||||
|
|
|
@ -45,16 +45,6 @@ def restartBmNotify(): #Prompts the user to restart Bitmessage.
|
|||
print ' WARNING: If Bitmessage is running locally, you must restart it now.'
|
||||
print ' *******************************************************************\n'
|
||||
|
||||
def safeConfigGetBoolean(section,field):
|
||||
global keysPath
|
||||
config = BMConfigParser()
|
||||
config.read(keysPath)
|
||||
|
||||
try:
|
||||
return config.getboolean(section,field)
|
||||
except:
|
||||
return False
|
||||
|
||||
#Begin keys.dat interactions
|
||||
def lookupAppdataFolder(): #gets the appropriate folders for the .dat files depending on the OS. Taken from bitmessagemain.py
|
||||
APPNAME = "PyBitmessage"
|
||||
|
@ -74,14 +64,13 @@ def lookupAppdataFolder(): #gets the appropriate folders for the .dat files depe
|
|||
|
||||
def configInit():
|
||||
global keysName
|
||||
config = BMConfigParser()
|
||||
|
||||
config.add_section('bitmessagesettings')
|
||||
config.set('bitmessagesettings', 'port', '8444') #Sets the bitmessage port to stop the warning about the api not properly being setup. This is in the event that the keys.dat is in a different directory or is created locally to connect to a machine remotely.
|
||||
config.set('bitmessagesettings','apienabled','true') #Sets apienabled to true in keys.dat
|
||||
BMConfigParser().add_section('bitmessagesettings')
|
||||
BMConfigParser().set('bitmessagesettings', 'port', '8444') #Sets the bitmessage port to stop the warning about the api not properly being setup. This is in the event that the keys.dat is in a different directory or is created locally to connect to a machine remotely.
|
||||
BMConfigParser().set('bitmessagesettings','apienabled','true') #Sets apienabled to true in keys.dat
|
||||
|
||||
with open(keysName, 'wb') as configfile:
|
||||
config.write(configfile)
|
||||
BMConfigParser().write(configfile)
|
||||
|
||||
print '\n ' + str(keysName) + ' Initalized in the same directory as daemon.py'
|
||||
print ' You will now need to configure the ' + str(keysName) + ' file.\n'
|
||||
|
@ -89,8 +78,7 @@ def configInit():
|
|||
def apiInit(apiEnabled):
|
||||
global keysPath
|
||||
global usrPrompt
|
||||
config = BMConfigParser()
|
||||
config.read(keysPath)
|
||||
BMConfigParser().read(keysPath)
|
||||
|
||||
|
||||
|
||||
|
@ -98,9 +86,9 @@ def apiInit(apiEnabled):
|
|||
uInput = userInput("The API is not enabled. Would you like to do that now, (Y)es or (N)o?").lower()
|
||||
|
||||
if uInput == "y": #
|
||||
config.set('bitmessagesettings','apienabled','true') #Sets apienabled to true in keys.dat
|
||||
BMConfigParser().set('bitmessagesettings','apienabled','true') #Sets apienabled to true in keys.dat
|
||||
with open(keysPath, 'wb') as configfile:
|
||||
config.write(configfile)
|
||||
BMConfigParser().write(configfile)
|
||||
|
||||
print 'Done'
|
||||
restartBmNotify()
|
||||
|
@ -143,15 +131,15 @@ def apiInit(apiEnabled):
|
|||
|
||||
print ' -----------------------------------\n'
|
||||
|
||||
config.set('bitmessagesettings', 'port', '8444') #sets the bitmessage port to stop the warning about the api not properly being setup. This is in the event that the keys.dat is in a different directory or is created locally to connect to a machine remotely.
|
||||
config.set('bitmessagesettings','apienabled','true')
|
||||
config.set('bitmessagesettings', 'apiport', apiPort)
|
||||
config.set('bitmessagesettings', 'apiinterface', '127.0.0.1')
|
||||
config.set('bitmessagesettings', 'apiusername', apiUsr)
|
||||
config.set('bitmessagesettings', 'apipassword', apiPwd)
|
||||
config.set('bitmessagesettings', 'daemon', daemon)
|
||||
BMConfigParser().set('bitmessagesettings', 'port', '8444') #sets the bitmessage port to stop the warning about the api not properly being setup. This is in the event that the keys.dat is in a different directory or is created locally to connect to a machine remotely.
|
||||
BMConfigParser().set('bitmessagesettings','apienabled','true')
|
||||
BMConfigParser().set('bitmessagesettings', 'apiport', apiPort)
|
||||
BMConfigParser().set('bitmessagesettings', 'apiinterface', '127.0.0.1')
|
||||
BMConfigParser().set('bitmessagesettings', 'apiusername', apiUsr)
|
||||
BMConfigParser().set('bitmessagesettings', 'apipassword', apiPwd)
|
||||
BMConfigParser().set('bitmessagesettings', 'daemon', daemon)
|
||||
with open(keysPath, 'wb') as configfile:
|
||||
config.write(configfile)
|
||||
BMConfigParser().write(configfile)
|
||||
|
||||
print '\n Finished configuring the keys.dat file with API information.\n'
|
||||
restartBmNotify()
|
||||
|
@ -174,21 +162,19 @@ def apiData():
|
|||
global keysPath
|
||||
global usrPrompt
|
||||
|
||||
config = BMConfigParser()
|
||||
config.read(keysPath) #First try to load the config file (the keys.dat file) from the program directory
|
||||
BMConfigParser().read(keysPath) #First try to load the config file (the keys.dat file) from the program directory
|
||||
|
||||
try:
|
||||
config.get('bitmessagesettings','port')
|
||||
BMConfigParser().get('bitmessagesettings','port')
|
||||
appDataFolder = ''
|
||||
except:
|
||||
#Could not load the keys.dat file in the program directory. Perhaps it is in the appdata directory.
|
||||
appDataFolder = lookupAppdataFolder()
|
||||
keysPath = appDataFolder + keysPath
|
||||
config = BMConfigParser()
|
||||
config.read(keysPath)
|
||||
BMConfigParser().read(keysPath)
|
||||
|
||||
try:
|
||||
config.get('bitmessagesettings','port')
|
||||
BMConfigParser().get('bitmessagesettings','port')
|
||||
except:
|
||||
#keys.dat was not there either, something is wrong.
|
||||
print '\n ******************************************************************'
|
||||
|
@ -215,21 +201,21 @@ def apiData():
|
|||
main()
|
||||
|
||||
try: #checks to make sure that everyting is configured correctly. Excluding apiEnabled, it is checked after
|
||||
config.get('bitmessagesettings', 'apiport')
|
||||
config.get('bitmessagesettings', 'apiinterface')
|
||||
config.get('bitmessagesettings', 'apiusername')
|
||||
config.get('bitmessagesettings', 'apipassword')
|
||||
BMConfigParser().get('bitmessagesettings', 'apiport')
|
||||
BMConfigParser().get('bitmessagesettings', 'apiinterface')
|
||||
BMConfigParser().get('bitmessagesettings', 'apiusername')
|
||||
BMConfigParser().get('bitmessagesettings', 'apipassword')
|
||||
except:
|
||||
apiInit("") #Initalize the keys.dat file with API information
|
||||
|
||||
#keys.dat file was found or appropriately configured, allow information retrieval
|
||||
apiEnabled = apiInit(safeConfigGetBoolean('bitmessagesettings','apienabled')) #if false it will prompt the user, if true it will return true
|
||||
apiEnabled = apiInit(BMConfigParser().safeGetBoolean('bitmessagesettings','apienabled')) #if false it will prompt the user, if true it will return true
|
||||
|
||||
config.read(keysPath)#read again since changes have been made
|
||||
apiPort = int(config.get('bitmessagesettings', 'apiport'))
|
||||
apiInterface = config.get('bitmessagesettings', 'apiinterface')
|
||||
apiUsername = config.get('bitmessagesettings', 'apiusername')
|
||||
apiPassword = config.get('bitmessagesettings', 'apipassword')
|
||||
BMConfigParser().read(keysPath)#read again since changes have been made
|
||||
apiPort = int(BMConfigParser().get('bitmessagesettings', 'apiport'))
|
||||
apiInterface = BMConfigParser().get('bitmessagesettings', 'apiinterface')
|
||||
apiUsername = BMConfigParser().get('bitmessagesettings', 'apiusername')
|
||||
apiPassword = BMConfigParser().get('bitmessagesettings', 'apipassword')
|
||||
|
||||
print '\n API data successfully imported.\n'
|
||||
|
||||
|
@ -253,31 +239,30 @@ def apiTest(): #Tests the API connection to bitmessage. Returns true if it is co
|
|||
def bmSettings(): #Allows the viewing and modification of keys.dat settings.
|
||||
global keysPath
|
||||
global usrPrompt
|
||||
config = BMConfigParser()
|
||||
keysPath = 'keys.dat'
|
||||
|
||||
config.read(keysPath)#Read the keys.dat
|
||||
BMConfigParser().read(keysPath)#Read the keys.dat
|
||||
try:
|
||||
port = config.get('bitmessagesettings', 'port')
|
||||
port = BMConfigParser().get('bitmessagesettings', 'port')
|
||||
except:
|
||||
print '\n File not found.\n'
|
||||
usrPrompt = 0
|
||||
main()
|
||||
|
||||
startonlogon = safeConfigGetBoolean('bitmessagesettings', 'startonlogon')
|
||||
minimizetotray = safeConfigGetBoolean('bitmessagesettings', 'minimizetotray')
|
||||
showtraynotifications = safeConfigGetBoolean('bitmessagesettings', 'showtraynotifications')
|
||||
startintray = safeConfigGetBoolean('bitmessagesettings', 'startintray')
|
||||
defaultnoncetrialsperbyte = config.get('bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
defaultpayloadlengthextrabytes = config.get('bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
daemon = safeConfigGetBoolean('bitmessagesettings', 'daemon')
|
||||
startonlogon = BMConfigParser().safeGetBoolean('bitmessagesettings', 'startonlogon')
|
||||
minimizetotray = BMConfigParser().safeGetBoolean('bitmessagesettings', 'minimizetotray')
|
||||
showtraynotifications = BMConfigParser().safeGetBoolean('bitmessagesettings', 'showtraynotifications')
|
||||
startintray = BMConfigParser().safeGetBoolean('bitmessagesettings', 'startintray')
|
||||
defaultnoncetrialsperbyte = BMConfigParser().get('bitmessagesettings', 'defaultnoncetrialsperbyte')
|
||||
defaultpayloadlengthextrabytes = BMConfigParser().get('bitmessagesettings', 'defaultpayloadlengthextrabytes')
|
||||
daemon = BMConfigParser().safeGetBoolean('bitmessagesettings', 'daemon')
|
||||
|
||||
socksproxytype = config.get('bitmessagesettings', 'socksproxytype')
|
||||
sockshostname = config.get('bitmessagesettings', 'sockshostname')
|
||||
socksport = config.get('bitmessagesettings', 'socksport')
|
||||
socksauthentication = safeConfigGetBoolean('bitmessagesettings', 'socksauthentication')
|
||||
socksusername = config.get('bitmessagesettings', 'socksusername')
|
||||
sockspassword = config.get('bitmessagesettings', 'sockspassword')
|
||||
socksproxytype = BMConfigParser().get('bitmessagesettings', 'socksproxytype')
|
||||
sockshostname = BMConfigParser().get('bitmessagesettings', 'sockshostname')
|
||||
socksport = BMConfigParser().get('bitmessagesettings', 'socksport')
|
||||
socksauthentication = BMConfigParser().safeGetBoolean('bitmessagesettings', 'socksauthentication')
|
||||
socksusername = BMConfigParser().get('bitmessagesettings', 'socksusername')
|
||||
sockspassword = BMConfigParser().get('bitmessagesettings', 'sockspassword')
|
||||
|
||||
|
||||
print '\n -----------------------------------'
|
||||
|
@ -313,60 +298,60 @@ def bmSettings(): #Allows the viewing and modification of keys.dat settings.
|
|||
if uInput == "port":
|
||||
print ' Current port number: ' + port
|
||||
uInput = userInput("Enter the new port number.")
|
||||
config.set('bitmessagesettings', 'port', str(uInput))
|
||||
BMConfigParser().set('bitmessagesettings', 'port', str(uInput))
|
||||
elif uInput == "startonlogon":
|
||||
print ' Current status: ' + str(startonlogon)
|
||||
uInput = userInput("Enter the new status.")
|
||||
config.set('bitmessagesettings', 'startonlogon', str(uInput))
|
||||
BMConfigParser().set('bitmessagesettings', 'startonlogon', str(uInput))
|
||||
elif uInput == "minimizetotray":
|
||||
print ' Current status: ' + str(minimizetotray)
|
||||
uInput = userInput("Enter the new status.")
|
||||
config.set('bitmessagesettings', 'minimizetotray', str(uInput))
|
||||
BMConfigParser().set('bitmessagesettings', 'minimizetotray', str(uInput))
|
||||
elif uInput == "showtraynotifications":
|
||||
print ' Current status: ' + str(showtraynotifications)
|
||||
uInput = userInput("Enter the new status.")
|
||||
config.set('bitmessagesettings', 'showtraynotifications', str(uInput))
|
||||
BMConfigParser().set('bitmessagesettings', 'showtraynotifications', str(uInput))
|
||||
elif uInput == "startintray":
|
||||
print ' Current status: ' + str(startintray)
|
||||
uInput = userInput("Enter the new status.")
|
||||
config.set('bitmessagesettings', 'startintray', str(uInput))
|
||||
BMConfigParser().set('bitmessagesettings', 'startintray', str(uInput))
|
||||
elif uInput == "defaultnoncetrialsperbyte":
|
||||
print ' Current default nonce trials per byte: ' + defaultnoncetrialsperbyte
|
||||
uInput = userInput("Enter the new defaultnoncetrialsperbyte.")
|
||||
config.set('bitmessagesettings', 'defaultnoncetrialsperbyte', str(uInput))
|
||||
BMConfigParser().set('bitmessagesettings', 'defaultnoncetrialsperbyte', str(uInput))
|
||||
elif uInput == "defaultpayloadlengthextrabytes":
|
||||
print ' Current default payload length extra bytes: ' + defaultpayloadlengthextrabytes
|
||||
uInput = userInput("Enter the new defaultpayloadlengthextrabytes.")
|
||||
config.set('bitmessagesettings', 'defaultpayloadlengthextrabytes', str(uInput))
|
||||
BMConfigParser().set('bitmessagesettings', 'defaultpayloadlengthextrabytes', str(uInput))
|
||||
elif uInput == "daemon":
|
||||
print ' Current status: ' + str(daemon)
|
||||
uInput = userInput("Enter the new status.").lower()
|
||||
config.set('bitmessagesettings', 'daemon', str(uInput))
|
||||
BMConfigParser().set('bitmessagesettings', 'daemon', str(uInput))
|
||||
elif uInput == "socksproxytype":
|
||||
print ' Current socks proxy type: ' + socksproxytype
|
||||
print "Possibilities: 'none', 'SOCKS4a', 'SOCKS5'."
|
||||
uInput = userInput("Enter the new socksproxytype.")
|
||||
config.set('bitmessagesettings', 'socksproxytype', str(uInput))
|
||||
BMConfigParser().set('bitmessagesettings', 'socksproxytype', str(uInput))
|
||||
elif uInput == "sockshostname":
|
||||
print ' Current socks host name: ' + sockshostname
|
||||
uInput = userInput("Enter the new sockshostname.")
|
||||
config.set('bitmessagesettings', 'sockshostname', str(uInput))
|
||||
BMConfigParser().set('bitmessagesettings', 'sockshostname', str(uInput))
|
||||
elif uInput == "socksport":
|
||||
print ' Current socks port number: ' + socksport
|
||||
uInput = userInput("Enter the new socksport.")
|
||||
config.set('bitmessagesettings', 'socksport', str(uInput))
|
||||
BMConfigParser().set('bitmessagesettings', 'socksport', str(uInput))
|
||||
elif uInput == "socksauthentication":
|
||||
print ' Current status: ' + str(socksauthentication)
|
||||
uInput = userInput("Enter the new status.")
|
||||
config.set('bitmessagesettings', 'socksauthentication', str(uInput))
|
||||
BMConfigParser().set('bitmessagesettings', 'socksauthentication', str(uInput))
|
||||
elif uInput == "socksusername":
|
||||
print ' Current socks username: ' + socksusername
|
||||
uInput = userInput("Enter the new socksusername.")
|
||||
config.set('bitmessagesettings', 'socksusername', str(uInput))
|
||||
BMConfigParser().set('bitmessagesettings', 'socksusername', str(uInput))
|
||||
elif uInput == "sockspassword":
|
||||
print ' Current socks password: ' + sockspassword
|
||||
uInput = userInput("Enter the new password.")
|
||||
config.set('bitmessagesettings', 'sockspassword', str(uInput))
|
||||
BMConfigParser().set('bitmessagesettings', 'sockspassword', str(uInput))
|
||||
else:
|
||||
print "\n Invalid input. Please try again.\n"
|
||||
invalidInput = True
|
||||
|
@ -377,7 +362,7 @@ def bmSettings(): #Allows the viewing and modification of keys.dat settings.
|
|||
if uInput != "y":
|
||||
print '\n Changes Made.\n'
|
||||
with open(keysPath, 'wb') as configfile:
|
||||
config.write(configfile)
|
||||
BMConfigParser().write(configfile)
|
||||
restartBmNotify()
|
||||
break
|
||||
|
||||
|
|
|
@ -22,7 +22,7 @@ from dialog import Dialog
|
|||
from helper_sql import *
|
||||
|
||||
import shared
|
||||
import ConfigParser
|
||||
from configparser import BMConfigParser
|
||||
from addresses import *
|
||||
from pyelliptic.openssl import OpenSSL
|
||||
import l10n
|
||||
|
@ -482,19 +482,19 @@ def handlech(c, stdscr):
|
|||
r, t = d.inputbox("New address label", init=label)
|
||||
if r == d.DIALOG_OK:
|
||||
label = t
|
||||
shared.config.set(a, "label", label)
|
||||
BMConfigParser().set(a, "label", label)
|
||||
# Write config
|
||||
shared.writeKeysFile()
|
||||
addresses[addrcur][0] = label
|
||||
elif t == "4": # Enable address
|
||||
a = addresses[addrcur][2]
|
||||
shared.config.set(a, "enabled", "true") # Set config
|
||||
BMConfigParser().set(a, "enabled", "true") # Set config
|
||||
# Write config
|
||||
shared.writeKeysFile()
|
||||
# Change color
|
||||
if shared.safeConfigGetBoolean(a, 'chan'):
|
||||
if BMConfigParser().safeGetBoolean(a, 'chan'):
|
||||
addresses[addrcur][3] = 9 # orange
|
||||
elif shared.safeConfigGetBoolean(a, 'mailinglist'):
|
||||
elif BMConfigParser().safeGetBoolean(a, 'mailinglist'):
|
||||
addresses[addrcur][3] = 5 # magenta
|
||||
else:
|
||||
addresses[addrcur][3] = 0 # black
|
||||
|
@ -502,7 +502,7 @@ def handlech(c, stdscr):
|
|||
shared.reloadMyAddressHashes() # Reload address hashes
|
||||
elif t == "5": # Disable address
|
||||
a = addresses[addrcur][2]
|
||||
shared.config.set(a, "enabled", "false") # Set config
|
||||
BMConfigParser().set(a, "enabled", "false") # Set config
|
||||
addresses[addrcur][3] = 8 # Set color to gray
|
||||
# Write config
|
||||
shared.writeKeysFile()
|
||||
|
@ -511,36 +511,36 @@ def handlech(c, stdscr):
|
|||
elif t == "6": # Delete address
|
||||
r, t = d.inputbox("Type in \"I want to delete this address\"", width=50)
|
||||
if r == d.DIALOG_OK and t == "I want to delete this address":
|
||||
shared.config.remove_section(addresses[addrcur][2])
|
||||
BMConfigParser().remove_section(addresses[addrcur][2])
|
||||
shared.writeKeysFile()
|
||||
del addresses[addrcur]
|
||||
elif t == "7": # Special address behavior
|
||||
a = addresses[addrcur][2]
|
||||
set_background_title(d, "Special address behavior")
|
||||
if shared.safeConfigGetBoolean(a, "chan"):
|
||||
if BMConfigParser().safeGetBoolean(a, "chan"):
|
||||
scrollbox(d, unicode("This is a chan address. You cannot use it as a pseudo-mailing list."))
|
||||
else:
|
||||
m = shared.safeConfigGetBoolean(a, "mailinglist")
|
||||
m = BMConfigParser().safeGetBoolean(a, "mailinglist")
|
||||
r, t = d.radiolist("Select address behavior",
|
||||
choices=[("1", "Behave as a normal address", not m),
|
||||
("2", "Behave as a pseudo-mailing-list address", m)])
|
||||
if r == d.DIALOG_OK:
|
||||
if t == "1" and m == True:
|
||||
shared.config.set(a, "mailinglist", "false")
|
||||
BMConfigParser().set(a, "mailinglist", "false")
|
||||
if addresses[addrcur][1]:
|
||||
addresses[addrcur][3] = 0 # Set color to black
|
||||
else:
|
||||
addresses[addrcur][3] = 8 # Set color to gray
|
||||
elif t == "2" and m == False:
|
||||
try:
|
||||
mn = shared.config.get(a, "mailinglistname")
|
||||
mn = BMConfigParser().get(a, "mailinglistname")
|
||||
except ConfigParser.NoOptionError:
|
||||
mn = ""
|
||||
r, t = d.inputbox("Mailing list name", init=mn)
|
||||
if r == d.DIALOG_OK:
|
||||
mn = t
|
||||
shared.config.set(a, "mailinglist", "true")
|
||||
shared.config.set(a, "mailinglistname", mn)
|
||||
BMConfigParser().set(a, "mailinglist", "true")
|
||||
BMConfigParser().set(a, "mailinglistname", mn)
|
||||
addresses[addrcur][3] = 6 # Set color to magenta
|
||||
# Write config
|
||||
shared.writeKeysFile()
|
||||
|
@ -793,7 +793,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
|||
0, # retryNumber
|
||||
"sent",
|
||||
2, # encodingType
|
||||
shared.config.getint('bitmessagesettings', 'ttl'))
|
||||
BMConfigParser().getint('bitmessagesettings', 'ttl'))
|
||||
shared.workerQueue.put(("sendmessage", addr))
|
||||
else: # Broadcast
|
||||
if recv == "":
|
||||
|
@ -819,7 +819,7 @@ def sendMessage(sender="", recv="", broadcast=None, subject="", body="", reply=F
|
|||
0, # retryNumber
|
||||
"sent", # folder
|
||||
2, # encodingType
|
||||
shared.config.getint('bitmessagesettings', 'ttl'))
|
||||
BMConfigParser().getint('bitmessagesettings', 'ttl'))
|
||||
shared.workerQueue.put(('sendbroadcast', ''))
|
||||
|
||||
def loadInbox():
|
||||
|
@ -843,7 +843,7 @@ def loadInbox():
|
|||
if toaddr == BROADCAST_STR:
|
||||
tolabel = BROADCAST_STR
|
||||
else:
|
||||
tolabel = shared.config.get(toaddr, "label")
|
||||
tolabel = BMConfigParser().get(toaddr, "label")
|
||||
except:
|
||||
tolabel = ""
|
||||
if tolabel == "":
|
||||
|
@ -852,8 +852,8 @@ def loadInbox():
|
|||
|
||||
# Set label for from address
|
||||
fromlabel = ""
|
||||
if shared.config.has_section(fromaddr):
|
||||
fromlabel = shared.config.get(fromaddr, "label")
|
||||
if BMConfigParser().has_section(fromaddr):
|
||||
fromlabel = BMConfigParser().get(fromaddr, "label")
|
||||
if fromlabel == "": # Check Address Book
|
||||
qr = sqlQuery("SELECT label FROM addressbook WHERE address=?", fromaddr)
|
||||
if qr != []:
|
||||
|
@ -900,15 +900,15 @@ def loadSent():
|
|||
for r in qr:
|
||||
tolabel, = r
|
||||
if tolabel == "":
|
||||
if shared.config.has_section(toaddr):
|
||||
tolabel = shared.config.get(toaddr, "label")
|
||||
if BMConfigParser().has_section(toaddr):
|
||||
tolabel = BMConfigParser().get(toaddr, "label")
|
||||
if tolabel == "":
|
||||
tolabel = toaddr
|
||||
|
||||
# Set label for from address
|
||||
fromlabel = ""
|
||||
if shared.config.has_section(fromaddr):
|
||||
fromlabel = shared.config.get(fromaddr, "label")
|
||||
if BMConfigParser().has_section(fromaddr):
|
||||
fromlabel = BMConfigParser().get(fromaddr, "label")
|
||||
if fromlabel == "":
|
||||
fromlabel = fromaddr
|
||||
|
||||
|
@ -969,7 +969,7 @@ def loadSubscriptions():
|
|||
subscriptions.reverse()
|
||||
def loadBlackWhiteList():
|
||||
global bwtype
|
||||
bwtype = shared.config.get("bitmessagesettings", "blackwhitelist")
|
||||
bwtype = BMConfigParser().get("bitmessagesettings", "blackwhitelist")
|
||||
if bwtype == "black":
|
||||
ret = sqlQuery("SELECT label, address, enabled FROM blacklist")
|
||||
else:
|
||||
|
@ -1025,17 +1025,17 @@ def run(stdscr):
|
|||
curses.init_pair(9, curses.COLOR_YELLOW, curses.COLOR_BLACK) # orangish
|
||||
|
||||
# Init list of address in 'Your Identities' tab
|
||||
configSections = shared.config.sections()
|
||||
configSections = BMConfigParser().sections()
|
||||
for addressInKeysFile in configSections:
|
||||
if addressInKeysFile != "bitmessagesettings":
|
||||
isEnabled = shared.config.getboolean(addressInKeysFile, "enabled")
|
||||
addresses.append([shared.config.get(addressInKeysFile, "label"), isEnabled, addressInKeysFile])
|
||||
isEnabled = BMConfigParser().getboolean(addressInKeysFile, "enabled")
|
||||
addresses.append([BMConfigParser().get(addressInKeysFile, "label"), isEnabled, addressInKeysFile])
|
||||
# Set address color
|
||||
if not isEnabled:
|
||||
addresses[len(addresses)-1].append(8) # gray
|
||||
elif shared.safeConfigGetBoolean(addressInKeysFile, 'chan'):
|
||||
elif BMConfigParser().safeGetBoolean(addressInKeysFile, 'chan'):
|
||||
addresses[len(addresses)-1].append(9) # orange
|
||||
elif shared.safeConfigGetBoolean(addressInKeysFile, 'mailinglist'):
|
||||
elif BMConfigParser().safeGetBoolean(addressInKeysFile, 'mailinglist'):
|
||||
addresses[len(addresses)-1].append(5) # magenta
|
||||
else:
|
||||
addresses[len(addresses)-1].append(0) # black
|
||||
|
|
|
@ -40,6 +40,7 @@ from class_singleWorker import singleWorker
|
|||
from class_addressGenerator import addressGenerator
|
||||
from class_smtpDeliver import smtpDeliver
|
||||
from class_smtpServer import smtpServer
|
||||
from configparser import BMConfigParser
|
||||
from debug import logger
|
||||
|
||||
# Helper Functions
|
||||
|
@ -58,7 +59,7 @@ def connectToStream(streamNumber):
|
|||
maximumNumberOfHalfOpenConnections = 64
|
||||
try:
|
||||
# don't overload Tor
|
||||
if shared.config.get('bitmessagesettings', 'socksproxytype') != 'none':
|
||||
if BMConfigParser().get('bitmessagesettings', 'socksproxytype') != 'none':
|
||||
maximumNumberOfHalfOpenConnections = 4
|
||||
except:
|
||||
pass
|
||||
|
@ -128,7 +129,7 @@ class singleAPI(threading.Thread, StoppableThread):
|
|||
super(singleAPI, self).stopThread()
|
||||
s = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
|
||||
try:
|
||||
s.connect((shared.config.get('bitmessagesettings', 'apiinterface'), shared.config.getint(
|
||||
s.connect((BMConfigParser().get('bitmessagesettings', 'apiinterface'), BMConfigParser().getint(
|
||||
'bitmessagesettings', 'apiport')))
|
||||
s.shutdown(socket.SHUT_RDWR)
|
||||
s.close()
|
||||
|
@ -136,7 +137,7 @@ class singleAPI(threading.Thread, StoppableThread):
|
|||
pass
|
||||
|
||||
def run(self):
|
||||
se = StoppableXMLRPCServer((shared.config.get('bitmessagesettings', 'apiinterface'), shared.config.getint(
|
||||
se = StoppableXMLRPCServer((BMConfigParser().get('bitmessagesettings', 'apiinterface'), BMConfigParser().getint(
|
||||
'bitmessagesettings', 'apiport')), MySimpleXMLRPCRequestHandler, True, True)
|
||||
se.register_introspection_functions()
|
||||
se.serve_forever()
|
||||
|
@ -188,12 +189,12 @@ class Main:
|
|||
sqlLookup.start()
|
||||
|
||||
# SMTP delivery thread
|
||||
if daemon and shared.safeConfigGet("bitmessagesettings", "smtpdeliver", '') != '':
|
||||
if daemon and BMConfigParser().safeGet("bitmessagesettings", "smtpdeliver", '') != '':
|
||||
smtpDeliveryThread = smtpDeliver()
|
||||
smtpDeliveryThread.start()
|
||||
|
||||
# SMTP daemon thread
|
||||
if daemon and shared.safeConfigGetBoolean("bitmessagesettings", "smtpd"):
|
||||
if daemon and BMConfigParser().safeGetBoolean("bitmessagesettings", "smtpd"):
|
||||
smtpServerThread = smtpServer()
|
||||
smtpServerThread.start()
|
||||
|
||||
|
@ -210,9 +211,9 @@ class Main:
|
|||
shared.reloadMyAddressHashes()
|
||||
shared.reloadBroadcastSendersForWhichImWatching()
|
||||
|
||||
if shared.safeConfigGetBoolean('bitmessagesettings', 'apienabled'):
|
||||
if BMConfigParser().safeGetBoolean('bitmessagesettings', 'apienabled'):
|
||||
try:
|
||||
apiNotifyPath = shared.config.get(
|
||||
apiNotifyPath = BMConfigParser().get(
|
||||
'bitmessagesettings', 'apinotifypath')
|
||||
except:
|
||||
apiNotifyPath = ''
|
||||
|
@ -232,12 +233,12 @@ class Main:
|
|||
singleListenerThread.daemon = True # close the main program even if there are threads left
|
||||
singleListenerThread.start()
|
||||
|
||||
if shared.safeConfigGetBoolean('bitmessagesettings','upnp'):
|
||||
if BMConfigParser().safeGetBoolean('bitmessagesettings','upnp'):
|
||||
import upnp
|
||||
upnpThread = upnp.uPnPThread()
|
||||
upnpThread.start()
|
||||
|
||||
if daemon == False and shared.safeConfigGetBoolean('bitmessagesettings', 'daemon') == False:
|
||||
if daemon == False and BMConfigParser().safeGetBoolean('bitmessagesettings', 'daemon') == False:
|
||||
if shared.curses == False:
|
||||
if not depends.check_pyqt():
|
||||
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')
|
||||
|
@ -253,7 +254,7 @@ class Main:
|
|||
import bitmessagecurses
|
||||
bitmessagecurses.runwrapper()
|
||||
else:
|
||||
shared.config.remove_option('bitmessagesettings', 'dontconnect')
|
||||
BMConfigParser().remove_option('bitmessagesettings', 'dontconnect')
|
||||
|
||||
while True:
|
||||
time.sleep(20)
|
||||
|
@ -290,15 +291,15 @@ class Main:
|
|||
|
||||
#TODO: nice function but no one is using this
|
||||
def getApiAddress(self):
|
||||
if not shared.safeConfigGetBoolean('bitmessagesettings', 'apienabled'):
|
||||
if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'apienabled'):
|
||||
return None
|
||||
address = shared.config.get('bitmessagesettings', 'apiinterface')
|
||||
port = shared.config.getint('bitmessagesettings', 'apiport')
|
||||
address = BMConfigParser().get('bitmessagesettings', 'apiinterface')
|
||||
port = BMConfigParser().getint('bitmessagesettings', 'apiport')
|
||||
return {'address':address,'port':port}
|
||||
|
||||
if __name__ == "__main__":
|
||||
mainprogram = Main()
|
||||
mainprogram.start(shared.safeConfigGetBoolean('bitmessagesettings', 'daemon'))
|
||||
mainprogram.start(BMConfigParser().safeGetBoolean('bitmessagesettings', 'daemon'))
|
||||
|
||||
|
||||
# So far, the creation of and management of the Bitmessage protocol and this
|
||||
|
|
|
@ -29,6 +29,7 @@ except AttributeError:
|
|||
from addresses import *
|
||||
import shared
|
||||
from bitmessageui import *
|
||||
from configparser import BMConfigParser
|
||||
from namecoin import namecoinConnection, ensureNamecoinOptions
|
||||
from newaddressdialog import *
|
||||
from newaddresswizard import *
|
||||
|
@ -77,6 +78,7 @@ from class_singleWorker import singleWorker
|
|||
from helper_generic import powQueueSize, invQueueSize
|
||||
from proofofwork import getPowType
|
||||
from statusbar import BMStatusBar
|
||||
from version import softwareVersion
|
||||
|
||||
def _translate(context, text, disambiguation = None, encoding = None, number = None):
|
||||
if number is None:
|
||||
|
@ -490,11 +492,11 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
enabled = {}
|
||||
|
||||
for toAddress in getSortedAccounts():
|
||||
isEnabled = shared.config.getboolean(
|
||||
isEnabled = BMConfigParser().getboolean(
|
||||
toAddress, 'enabled')
|
||||
isChan = shared.safeConfigGetBoolean(
|
||||
isChan = BMConfigParser().safeGetBoolean(
|
||||
toAddress, 'chan')
|
||||
isMaillinglist = shared.safeConfigGetBoolean(
|
||||
isMaillinglist = BMConfigParser().safeGetBoolean(
|
||||
toAddress, 'mailinglist')
|
||||
|
||||
if treeWidget == self.ui.treeWidgetYourIdentities:
|
||||
|
@ -603,7 +605,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
reply = QtGui.QMessageBox.question(
|
||||
self, 'Message', displayMsg, QtGui.QMessageBox.Yes, QtGui.QMessageBox.No)
|
||||
if reply == QtGui.QMessageBox.Yes:
|
||||
shared.config.remove_section(addressInKeysFile)
|
||||
BMConfigParser().remove_section(addressInKeysFile)
|
||||
shared.writeKeysFile()
|
||||
|
||||
# Configure Bitmessage to start on startup (or remove the
|
||||
|
@ -614,7 +616,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
self.settings = QSettings(RUN_PATH, QSettings.NativeFormat)
|
||||
self.settings.remove(
|
||||
"PyBitmessage") # In case the user moves the program and the registry entry is no longer valid, this will delete the old registry entry.
|
||||
if shared.config.getboolean('bitmessagesettings', 'startonlogon'):
|
||||
if BMConfigParser().getboolean('bitmessagesettings', 'startonlogon'):
|
||||
self.settings.setValue("PyBitmessage", sys.argv[0])
|
||||
elif 'darwin' in sys.platform:
|
||||
# startup for mac
|
||||
|
@ -783,7 +785,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
self.rerenderComboBoxSendFromBroadcast()
|
||||
|
||||
# Put the TTL slider in the correct spot
|
||||
TTL = shared.config.getint('bitmessagesettings', 'ttl')
|
||||
TTL = BMConfigParser().getint('bitmessagesettings', 'ttl')
|
||||
if TTL < 3600: # an hour
|
||||
TTL = 3600
|
||||
elif TTL > 28*24*60*60: # 28 days
|
||||
|
@ -799,11 +801,11 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
# Check to see whether we can connect to namecoin. Hide the 'Fetch Namecoin ID' button if we can't.
|
||||
try:
|
||||
options = {}
|
||||
options["type"] = shared.config.get('bitmessagesettings', 'namecoinrpctype')
|
||||
options["host"] = shared.config.get('bitmessagesettings', 'namecoinrpchost')
|
||||
options["port"] = shared.config.get('bitmessagesettings', 'namecoinrpcport')
|
||||
options["user"] = shared.config.get('bitmessagesettings', 'namecoinrpcuser')
|
||||
options["password"] = shared.config.get('bitmessagesettings', 'namecoinrpcpassword')
|
||||
options["type"] = BMConfigParser().get('bitmessagesettings', 'namecoinrpctype')
|
||||
options["host"] = BMConfigParser().get('bitmessagesettings', 'namecoinrpchost')
|
||||
options["port"] = BMConfigParser().get('bitmessagesettings', 'namecoinrpcport')
|
||||
options["user"] = BMConfigParser().get('bitmessagesettings', 'namecoinrpcuser')
|
||||
options["password"] = BMConfigParser().get('bitmessagesettings', 'namecoinrpcpassword')
|
||||
nc = namecoinConnection(options)
|
||||
if nc.test()[0] == 'failed':
|
||||
self.ui.pushButtonFetchNamecoinID.hide()
|
||||
|
@ -814,7 +816,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
def updateTTL(self, sliderPosition):
|
||||
TTL = int(sliderPosition ** 3.199 + 3600)
|
||||
self.updateHumanFriendlyTTLDescription(TTL)
|
||||
shared.config.set('bitmessagesettings', 'ttl', str(TTL))
|
||||
BMConfigParser().set('bitmessagesettings', 'ttl', str(TTL))
|
||||
shared.writeKeysFile()
|
||||
|
||||
def updateHumanFriendlyTTLDescription(self, TTL):
|
||||
|
@ -1161,7 +1163,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
# show bitmessage
|
||||
self.actionShow = QtGui.QAction(_translate(
|
||||
"MainWindow", "Show Bitmessage"), m, checkable=True)
|
||||
self.actionShow.setChecked(not shared.config.getboolean(
|
||||
self.actionShow.setChecked(not BMConfigParser().getboolean(
|
||||
'bitmessagesettings', 'startintray'))
|
||||
self.actionShow.triggered.connect(self.appIndicatorShowOrHideWindow)
|
||||
if not sys.platform[0:3] == 'win':
|
||||
|
@ -1250,7 +1252,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
if toAddress == str_broadcast_subscribers:
|
||||
toLabel = str_broadcast_subscribers
|
||||
else:
|
||||
toLabel = shared.config.get(toAddress, 'label')
|
||||
toLabel = BMConfigParser().get(toAddress, 'label')
|
||||
except:
|
||||
toLabel = ''
|
||||
if toLabel == '':
|
||||
|
@ -1595,7 +1597,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
self.connectDialogInstance = connectDialog(self)
|
||||
if self.connectDialogInstance.exec_():
|
||||
if self.connectDialogInstance.ui.radioButtonConnectNow.isChecked():
|
||||
shared.config.remove_option('bitmessagesettings', 'dontconnect')
|
||||
BMConfigParser().remove_option('bitmessagesettings', 'dontconnect')
|
||||
shared.writeKeysFile()
|
||||
else:
|
||||
self.click_actionSettings()
|
||||
|
@ -1619,7 +1621,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
self.ui.blackwhitelist.init_blacklist_popup_menu(False)
|
||||
if event.type() == QtCore.QEvent.WindowStateChange:
|
||||
if self.windowState() & QtCore.Qt.WindowMinimized:
|
||||
if shared.config.getboolean('bitmessagesettings', 'minimizetotray') and not 'darwin' in sys.platform:
|
||||
if BMConfigParser().getboolean('bitmessagesettings', 'minimizetotray') and not 'darwin' in sys.platform:
|
||||
QTimer.singleShot(0, self.appIndicatorHide)
|
||||
elif event.oldState() & QtCore.Qt.WindowMinimized:
|
||||
# The window state has just been changed to
|
||||
|
@ -1644,7 +1646,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
QIcon(":/newPrefix/images/redicon.png"))
|
||||
shared.statusIconColor = 'red'
|
||||
# if the connection is lost then show a notification
|
||||
if self.connected and not shared.config.getboolean('bitmessagesettings', 'hidetrayconnectionnotifications'):
|
||||
if self.connected and not BMConfigParser().getboolean('bitmessagesettings', 'hidetrayconnectionnotifications'):
|
||||
self.notifierShow('Bitmessage', unicode(_translate(
|
||||
"MainWindow", "Connection lost").toUtf8(),'utf-8'),
|
||||
self.SOUND_DISCONNECTED, None)
|
||||
|
@ -1661,7 +1663,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
":/newPrefix/images/yellowicon.png"))
|
||||
shared.statusIconColor = 'yellow'
|
||||
# if a new connection has been established then show a notification
|
||||
if not self.connected and not shared.config.getboolean('bitmessagesettings', 'hidetrayconnectionnotifications'):
|
||||
if not self.connected and not BMConfigParser().getboolean('bitmessagesettings', 'hidetrayconnectionnotifications'):
|
||||
self.notifierShow('Bitmessage', unicode(_translate(
|
||||
"MainWindow", "Connected").toUtf8(),'utf-8'),
|
||||
self.SOUND_CONNECTED, None)
|
||||
|
@ -1677,7 +1679,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
self.pushButtonStatusIcon.setIcon(
|
||||
QIcon(":/newPrefix/images/greenicon.png"))
|
||||
shared.statusIconColor = 'green'
|
||||
if not self.connected and not shared.config.getboolean('bitmessagesettings', 'hidetrayconnectionnotifications'):
|
||||
if not self.connected and not BMConfigParser().getboolean('bitmessagesettings', 'hidetrayconnectionnotifications'):
|
||||
self.notifierShow('Bitmessage', unicode(_translate(
|
||||
"MainWindow", "Connected").toUtf8(),'utf-8'),
|
||||
self.SOUND_CONNECTION_GREEN, None)
|
||||
|
@ -1856,7 +1858,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
addresses = getSortedAccounts()
|
||||
for address in addresses:
|
||||
account = accountClass(address)
|
||||
if (account.type == AccountMixin.CHAN and shared.safeConfigGetBoolean(address, 'enabled')):
|
||||
if (account.type == AccountMixin.CHAN and BMConfigParser().safeGetBoolean(address, 'enabled')):
|
||||
newRows[address] = [account.getLabel(), AccountMixin.CHAN]
|
||||
# normal accounts
|
||||
queryreturn = sqlQuery('SELECT * FROM addressbook')
|
||||
|
@ -1952,8 +1954,8 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
email = ''.join(random.SystemRandom().choice(string.ascii_lowercase) for _ in range(12)) + "@mailchuck.com"
|
||||
acct = MailchuckAccount(fromAddress)
|
||||
acct.register(email)
|
||||
shared.config.set(fromAddress, 'label', email)
|
||||
shared.config.set(fromAddress, 'gateway', 'mailchuck')
|
||||
BMConfigParser().set(fromAddress, 'label', email)
|
||||
BMConfigParser().set(fromAddress, 'gateway', 'mailchuck')
|
||||
shared.writeKeysFile()
|
||||
self.statusBar().showMessage(_translate(
|
||||
"MainWindow", "Error: Your account wasn't registered at an email gateway. Sending registration now as %1, please wait for the registration to be processed before retrying sending.").arg(email), 10000)
|
||||
|
@ -2027,7 +2029,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
0, # retryNumber
|
||||
'sent', # folder
|
||||
encoding, # encodingtype
|
||||
shared.config.getint('bitmessagesettings', 'ttl')
|
||||
BMConfigParser().getint('bitmessagesettings', 'ttl')
|
||||
)
|
||||
|
||||
toLabel = ''
|
||||
|
@ -2080,7 +2082,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
0, # retryNumber
|
||||
'sent', # folder
|
||||
encoding, # encoding type
|
||||
shared.config.getint('bitmessagesettings', 'ttl')
|
||||
BMConfigParser().getint('bitmessagesettings', 'ttl')
|
||||
)
|
||||
sqlExecute(
|
||||
'''INSERT INTO sent VALUES (?,?,?,?,?,?,?,?,?,?,?,?,?,?,?)''', *t)
|
||||
|
@ -2125,7 +2127,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
def setBroadcastEnablementDependingOnWhetherThisIsAMailingListAddress(self, address):
|
||||
# If this is a chan then don't let people broadcast because no one
|
||||
# should subscribe to chan addresses.
|
||||
if shared.safeConfigGetBoolean(str(address), 'mailinglist'):
|
||||
if BMConfigParser().safeGetBoolean(str(address), 'mailinglist'):
|
||||
self.ui.tabWidgetSend.setCurrentIndex(1)
|
||||
else:
|
||||
self.ui.tabWidgetSend.setCurrentIndex(0)
|
||||
|
@ -2133,11 +2135,11 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
def rerenderComboBoxSendFrom(self):
|
||||
self.ui.comboBoxSendFrom.clear()
|
||||
for addressInKeysFile in getSortedAccounts():
|
||||
isEnabled = shared.config.getboolean(
|
||||
isEnabled = BMConfigParser().getboolean(
|
||||
addressInKeysFile, 'enabled') # I realize that this is poor programming practice but I don't care. It's easier for others to read.
|
||||
isMaillinglist = shared.safeConfigGetBoolean(addressInKeysFile, 'mailinglist')
|
||||
isMaillinglist = BMConfigParser().safeGetBoolean(addressInKeysFile, 'mailinglist')
|
||||
if isEnabled and not isMaillinglist:
|
||||
label = unicode(shared.config.get(addressInKeysFile, 'label'), 'utf-8', 'ignore').strip()
|
||||
label = unicode(BMConfigParser().get(addressInKeysFile, 'label'), 'utf-8', 'ignore').strip()
|
||||
if label == "":
|
||||
label = addressInKeysFile
|
||||
self.ui.comboBoxSendFrom.addItem(avatarize(addressInKeysFile), label, addressInKeysFile)
|
||||
|
@ -2154,11 +2156,11 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
def rerenderComboBoxSendFromBroadcast(self):
|
||||
self.ui.comboBoxSendFromBroadcast.clear()
|
||||
for addressInKeysFile in getSortedAccounts():
|
||||
isEnabled = shared.config.getboolean(
|
||||
isEnabled = BMConfigParser().getboolean(
|
||||
addressInKeysFile, 'enabled') # I realize that this is poor programming practice but I don't care. It's easier for others to read.
|
||||
isChan = shared.safeConfigGetBoolean(addressInKeysFile, 'chan')
|
||||
isChan = BMConfigParser().safeGetBoolean(addressInKeysFile, 'chan')
|
||||
if isEnabled and not isChan:
|
||||
label = unicode(shared.config.get(addressInKeysFile, 'label'), 'utf-8', 'ignore').strip()
|
||||
label = unicode(BMConfigParser().get(addressInKeysFile, 'label'), 'utf-8', 'ignore').strip()
|
||||
if label == "":
|
||||
label = addressInKeysFile
|
||||
self.ui.comboBoxSendFromBroadcast.addItem(avatarize(addressInKeysFile), label, addressInKeysFile)
|
||||
|
@ -2221,7 +2223,7 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
else:
|
||||
acct = ret
|
||||
self.propagateUnreadCount(acct.address)
|
||||
if shared.config.getboolean('bitmessagesettings', 'showtraynotifications'):
|
||||
if BMConfigParser().getboolean('bitmessagesettings', 'showtraynotifications'):
|
||||
self.notifierShow(unicode(_translate("MainWindow",'New Message').toUtf8(),'utf-8'), unicode(_translate("MainWindow",'From ').toUtf8(),'utf-8') + unicode(acct.fromLabel, 'utf-8'), self.SOUND_UNKNOWN, None)
|
||||
if self.getCurrentAccount() is not None and ((self.getCurrentFolder(treeWidget) != "inbox" and self.getCurrentFolder(treeWidget) is not None) or self.getCurrentAccount(treeWidget) != acct.address):
|
||||
# Ubuntu should notify of new message irespective of whether it's in current message list or not
|
||||
|
@ -2235,8 +2237,8 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
email = str(self.dialog.ui.lineEditEmail.text().toUtf8())
|
||||
# register resets address variables
|
||||
acct.register(email)
|
||||
shared.config.set(acct.fromAddress, 'label', email)
|
||||
shared.config.set(acct.fromAddress, 'gateway', 'mailchuck')
|
||||
BMConfigParser().set(acct.fromAddress, 'label', email)
|
||||
BMConfigParser().set(acct.fromAddress, 'gateway', 'mailchuck')
|
||||
shared.writeKeysFile()
|
||||
self.statusBar().showMessage(_translate(
|
||||
"MainWindow", "Sending email gateway registration request"), 10000)
|
||||
|
@ -2323,113 +2325,113 @@ class MyForm(settingsmixin.SMainWindow):
|
|||
def click_actionSettings(self):
|
||||
self.settingsDialogInstance = settingsDialog(self)
|
||||
if self.settingsDialogInstance.exec_():
|
||||
shared.config.set('bitmessagesettings', 'startonlogon', str(
|
||||
BMConfigParser().set('bitmessagesettings', 'startonlogon', str(
|
||||
self.settingsDialogInstance.ui.checkBoxStartOnLogon.isChecked()))
|
||||
shared.config.set('bitmessagesettings', 'minimizetotray', str(
|
||||
BMConfigParser().set('bitmessagesettings', 'minimizetotray', str(
|
||||
self.settingsDialogInstance.ui.checkBoxMinimizeToTray.isChecked()))
|
||||
shared.config.set('bitmessagesettings', 'trayonclose', str(
|
||||
BMConfigParser().set('bitmessagesettings', 'trayonclose', str(
|
||||
self.settingsDialogInstance.ui.checkBoxTrayOnClose.isChecked()))
|
||||
shared.config.set('bitmessagesettings', 'hidetrayconnectionnotifications', str(
|
||||
BMConfigParser().set('bitmessagesettings', 'hidetrayconnectionnotifications', str(
|
||||
self.settingsDialogInstance.ui.checkBoxHideTrayConnectionNotifications.isChecked()))
|
||||
shared.config.set('bitmessagesettings', 'showtraynotifications', str(
|
||||
BMConfigParser().set('bitmessagesettings', 'showtraynotifications', str(
|
||||
self.settingsDialogInstance.ui.checkBoxShowTrayNotifications.isChecked()))
|
||||
shared.config.set('bitmessagesettings', 'startintray', str(
|
||||
BMConfigParser().set('bitmessagesettings', 'startintray', str(
|
||||
self.settingsDialogInstance.ui.checkBoxStartInTray.isChecked()))
|
||||
shared.config.set('bitmessagesettings', 'willinglysendtomobile', str(
|
||||
BMConfigParser().set('bitmessagesettings', 'willinglysendtomobile', str(
|
||||
self.settingsDialogInstance.ui.checkBoxWillinglySendToMobile.isChecked()))
|
||||
shared.config.set('bitmessagesettings', 'useidenticons', str(
|
||||
BMConfigParser().set('bitmessagesettings', 'useidenticons', str(
|
||||
self.settingsDialogInstance.ui.checkBoxUseIdenticons.isChecked()))
|
||||
shared.config.set('bitmessagesettings', 'replybelow', str(
|
||||
BMConfigParser().set('bitmessagesettings', 'replybelow', str(
|
||||
self.settingsDialogInstance.ui.checkBoxReplyBelow.isChecked()))
|
||||
|
||||
lang = str(self.settingsDialogInstance.ui.languageComboBox.itemData(self.settingsDialogInstance.ui.languageComboBox.currentIndex()).toString())
|
||||
shared.config.set('bitmessagesettings', 'userlocale', lang)
|
||||
BMConfigParser().set('bitmessagesettings', 'userlocale', lang)
|
||||
change_translation(l10n.getTranslationLanguage())
|
||||
|
||||
if int(shared.config.get('bitmessagesettings', 'port')) != int(self.settingsDialogInstance.ui.lineEditTCPPort.text()):
|
||||
if not shared.safeConfigGetBoolean('bitmessagesettings', 'dontconnect'):
|
||||
if int(BMConfigParser().get('bitmessagesettings', 'port')) != int(self.settingsDialogInstance.ui.lineEditTCPPort.text()):
|
||||
if not BMConfigParser().safeGetBoolean('bitmessagesettings', 'dontconnect'):
|
||||
QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate(
|
||||
"MainWindow", "You must restart Bitmessage for the port number change to take effect."))
|
||||
shared.config.set('bitmessagesettings', 'port', str(
|
||||
BMConfigParser().set('bitmessagesettings', 'port', str(
|
||||
self.settingsDialogInstance.ui.lineEditTCPPort.text()))
|
||||
if self.settingsDialogInstance.ui.checkBoxUPnP.isChecked() != shared.safeConfigGetBoolean('bitmessagesettings', 'upnp'):
|
||||
shared.config.set('bitmessagesettings', 'upnp', str(self.settingsDialogInstance.ui.checkBoxUPnP.isChecked()))
|
||||
if self.settingsDialogInstance.ui.checkBoxUPnP.isChecked() != BMConfigParser().safeGetBoolean('bitmessagesettings', 'upnp'):
|
||||
BMConfigParser().set('bitmessagesettings', 'upnp', str(self.settingsDialogInstance.ui.checkBoxUPnP.isChecked()))
|
||||
if self.settingsDialogInstance.ui.checkBoxUPnP.isChecked():
|
||||
import upnp
|
||||
upnpThread = upnp.uPnPThread()
|
||||
upnpThread.start()
|
||||
#print 'self.settingsDialogInstance.ui.comboBoxProxyType.currentText()', self.settingsDialogInstance.ui.comboBoxProxyType.currentText()
|
||||
#print 'self.settingsDialogInstance.ui.comboBoxProxyType.currentText())[0:5]', self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5]
|
||||
if shared.config.get('bitmessagesettings', 'socksproxytype') == 'none' and self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] == 'SOCKS':
|
||||
if BMConfigParser().get('bitmessagesettings', 'socksproxytype') == 'none' and self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] == 'SOCKS':
|
||||
if shared.statusIconColor != 'red':
|
||||
QMessageBox.about(self, _translate("MainWindow", "Restart"), _translate(
|
||||
"MainWindow", "Bitmessage will use your proxy from now on but you may want to manually restart Bitmessage now to close existing connections (if any)."))
|
||||
if shared.config.get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS' and self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] != 'SOCKS':
|
||||
if BMConfigParser().get('bitmessagesettings', 'socksproxytype')[0:5] == 'SOCKS' and self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] != 'SOCKS':
|
||||
self.statusBar().clearMessage()
|
||||
if self.settingsDialogInstance.ui.comboBoxProxyType.currentText()[0:5] == 'SOCKS':
|
||||
shared.config.set('bitmessagesettings', 'socksproxytype', str(
|
||||
BMConfigParser().set('bitmessagesettings', 'socksproxytype', str(
|
||||
self.settingsDialogInstance.ui.comboBoxProxyType.currentText()))
|
||||
else:
|
||||
shared.config. |