helper_startup formating

This commit is contained in:
Mahendra 2018-04-07 13:35:31 +05:30
parent 498557a6d6
commit a012d4a707
No known key found for this signature in database
GPG Key ID: A672D8FAAEE398B3

View File

@ -1,11 +1,10 @@
"""Helper Start performs all the startup operations."""
import ConfigParser import ConfigParser
from bmconfigparser import BMConfigParser from bmconfigparser import BMConfigParser
import defaults import defaults
import sys import sys
import os import os
import locale
import random
import string
import platform import platform
from distutils.version import StrictVersion from distutils.version import StrictVersion
@ -14,7 +13,10 @@ import paths
import state import state
import helper_random import helper_random
storeConfigFilesInSameDirectoryAsProgramByDefault = False # The user may de-select Portable Mode in the settings if they want the config files to stay in the application data folder. storeConfigFilesInSameDirectoryAsProgramByDefault = False # The user may
# de-select Portable Mode in the settings if they want the config files to
# stay in the application data folder.
def _loadTrustedPeer(): def _loadTrustedPeer():
try: try:
@ -27,15 +29,16 @@ def _loadTrustedPeer():
host, port = trustedPeer.split(':') host, port = trustedPeer.split(':')
state.trustedPeer = state.Peer(host, int(port)) state.trustedPeer = state.Peer(host, int(port))
def loadConfig(): def loadConfig():
if state.appdata: if state.appdata:
BMConfigParser().read(state.appdata + 'keys.dat') BMConfigParser().read(state.appdata + 'keys.dat')
#state.appdata must have been specified as a startup option. # state.appdata must have been specified as a startup option.
try: try:
BMConfigParser().get('bitmessagesettings', 'settingsversion') BMConfigParser().get('bitmessagesettings', 'settingsversion')
print 'Loading config files from directory specified on startup: ' + state.appdata print 'Loading config files from directory specified on startup: ' + state.appdata
needToCreateKeysFile = False needToCreateKeysFile = False
except: except Exception:
needToCreateKeysFile = True needToCreateKeysFile = True
else: else:
@ -45,16 +48,16 @@ def loadConfig():
print 'Loading config files from same directory as program.' print 'Loading config files from same directory as program.'
needToCreateKeysFile = False needToCreateKeysFile = False
state.appdata = paths.lookupExeFolder() state.appdata = paths.lookupExeFolder()
except: except Exception:
# Could not load the keys.dat file in the program directory. Perhaps it # Could not load the keys.dat file in the program directory.
# is in the appdata directory. # Perhaps it is in the appdata directory.
state.appdata = paths.lookupAppdataFolder() state.appdata = paths.lookupAppdataFolder()
BMConfigParser().read(state.appdata + 'keys.dat') BMConfigParser().read(state.appdata + 'keys.dat')
try: try:
BMConfigParser().get('bitmessagesettings', 'settingsversion') BMConfigParser().get('bitmessagesettings', 'settingsversion')
print 'Loading existing config files from', state.appdata print 'Loading existing config files from', state.appdata
needToCreateKeysFile = False needToCreateKeysFile = False
except: except Exception:
needToCreateKeysFile = True needToCreateKeysFile = True
if needToCreateKeysFile: if needToCreateKeysFile:
@ -110,7 +113,6 @@ def loadConfig():
BMConfigParser().set('bitmessagesettings', 'maxuploadrate', '0') BMConfigParser().set('bitmessagesettings', 'maxuploadrate', '0')
BMConfigParser().set('bitmessagesettings', 'maxoutboundconnections', '8') BMConfigParser().set('bitmessagesettings', 'maxoutboundconnections', '8')
BMConfigParser().set('bitmessagesettings', 'ttl', '367200') BMConfigParser().set('bitmessagesettings', 'ttl', '367200')
#start:UI setting to stop trying to send messages after X days/months #start:UI setting to stop trying to send messages after X days/months
BMConfigParser().set( BMConfigParser().set(
'bitmessagesettings', 'stopresendingafterxdays', '') 'bitmessagesettings', 'stopresendingafterxdays', '')
@ -145,9 +147,9 @@ def loadConfig():
def isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections(): def isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections():
try: try:
if sys.platform[0:3]=="win": if sys.platform[0:3] == "win":
VER_THIS=StrictVersion(platform.version()) VER_THIS = StrictVersion(platform.version())
return StrictVersion("5.1.2600")<=VER_THIS and StrictVersion("6.0.6000")>=VER_THIS return StrictVersion("5.1.2600")<=VER_THIS and StrictVersion("6.0.6000")>=VER_THIS
return False return False
except Exception as err: except Exception:
return False return False