Moved start_proxyconfig to helper_startup;
no more prints in helper_startup
This commit is contained in:
parent
44cb975a61
commit
5160a68c28
|
@ -39,7 +39,8 @@ import shutdown
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
from debug import logger # this should go before any threads
|
from debug import logger # this should go before any threads
|
||||||
from helper_startup import (
|
from helper_startup import (
|
||||||
isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections
|
isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections,
|
||||||
|
start_proxyconfig
|
||||||
)
|
)
|
||||||
from inventory import Inventory
|
from inventory import Inventory
|
||||||
from knownnodes import readKnownNodes
|
from knownnodes import readKnownNodes
|
||||||
|
@ -168,30 +169,9 @@ def signal_handler(signum, frame):
|
||||||
|
|
||||||
class Main(object):
|
class Main(object):
|
||||||
"""Main PyBitmessage class"""
|
"""Main PyBitmessage class"""
|
||||||
@staticmethod
|
def start(self):
|
||||||
def start_proxyconfig(config):
|
|
||||||
"""Check socksproxytype and start any proxy configuration plugin"""
|
|
||||||
proxy_type = config.safeGet('bitmessagesettings', 'socksproxytype')
|
|
||||||
if proxy_type not in ('none', 'SOCKS4a', 'SOCKS5'):
|
|
||||||
# pylint: disable=relative-import
|
|
||||||
from plugins.plugin import get_plugin
|
|
||||||
try:
|
|
||||||
proxyconfig_start = time.time()
|
|
||||||
if not get_plugin('proxyconfig', name=proxy_type)(config):
|
|
||||||
raise TypeError
|
|
||||||
except TypeError:
|
|
||||||
logger.error(
|
|
||||||
'Failed to run proxy config plugin %s',
|
|
||||||
proxy_type, exc_info=True)
|
|
||||||
shutdown.doCleanShutdown()
|
|
||||||
sys.exit(2)
|
|
||||||
else:
|
|
||||||
logger.info(
|
|
||||||
'Started proxy config plugin %s in %s sec',
|
|
||||||
proxy_type, time.time() - proxyconfig_start)
|
|
||||||
|
|
||||||
def start(self): # pylint: disable=too-many-statements, too-many-branches, too-many-locals
|
|
||||||
"""Start main application"""
|
"""Start main application"""
|
||||||
|
# pylint: disable=too-many-statements,too-many-branches,too-many-locals
|
||||||
_fixSocket()
|
_fixSocket()
|
||||||
|
|
||||||
config = BMConfigParser()
|
config = BMConfigParser()
|
||||||
|
@ -350,7 +330,7 @@ class Main(object):
|
||||||
|
|
||||||
# start network components if networking is enabled
|
# start network components if networking is enabled
|
||||||
if state.enableNetwork:
|
if state.enableNetwork:
|
||||||
self.start_proxyconfig(config)
|
start_proxyconfig()
|
||||||
BMConnectionPool()
|
BMConnectionPool()
|
||||||
asyncoreThread = BMNetworkThread()
|
asyncoreThread = BMNetworkThread()
|
||||||
asyncoreThread.daemon = True
|
asyncoreThread.daemon = True
|
||||||
|
@ -410,7 +390,7 @@ class Main(object):
|
||||||
self.stop()
|
self.stop()
|
||||||
elif not state.enableGUI:
|
elif not state.enableGUI:
|
||||||
from tests import core as test_core # pylint: disable=relative-import
|
from tests import core as test_core # pylint: disable=relative-import
|
||||||
test_core_result = test_core.run(self)
|
test_core_result = test_core.run()
|
||||||
state.enableGUI = True
|
state.enableGUI = True
|
||||||
self.stop()
|
self.stop()
|
||||||
test_core.cleanup()
|
test_core.cleanup()
|
||||||
|
|
|
@ -2,11 +2,12 @@
|
||||||
Startup operations.
|
Startup operations.
|
||||||
"""
|
"""
|
||||||
# pylint: disable=too-many-branches,too-many-statements
|
# pylint: disable=too-many-branches,too-many-statements
|
||||||
from __future__ import print_function
|
|
||||||
|
|
||||||
|
import logging
|
||||||
import os
|
import os
|
||||||
import platform
|
import platform
|
||||||
import sys
|
import sys
|
||||||
|
import time
|
||||||
from distutils.version import StrictVersion
|
from distutils.version import StrictVersion
|
||||||
|
|
||||||
import defaults
|
import defaults
|
||||||
|
@ -15,6 +16,13 @@ import paths
|
||||||
import state
|
import state
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
|
|
||||||
|
try:
|
||||||
|
from plugins.plugin import get_plugin
|
||||||
|
except ImportError:
|
||||||
|
get_plugin = None
|
||||||
|
|
||||||
|
|
||||||
|
logger = logging.getLogger('default')
|
||||||
|
|
||||||
# The user may de-select Portable Mode in the settings if they want
|
# The user may de-select Portable Mode in the settings if they want
|
||||||
# the config files to stay in the application data folder.
|
# the config files to stay in the application data folder.
|
||||||
|
@ -30,14 +38,14 @@ def loadConfig():
|
||||||
needToCreateKeysFile = config.safeGet(
|
needToCreateKeysFile = config.safeGet(
|
||||||
'bitmessagesettings', 'settingsversion') is None
|
'bitmessagesettings', 'settingsversion') is None
|
||||||
if not needToCreateKeysFile:
|
if not needToCreateKeysFile:
|
||||||
print(
|
logger.info(
|
||||||
'Loading config files from directory specified'
|
'Loading config files from directory specified'
|
||||||
' on startup: %s' % state.appdata)
|
' on startup: %s', state.appdata)
|
||||||
else:
|
else:
|
||||||
config.read(paths.lookupExeFolder() + 'keys.dat')
|
config.read(paths.lookupExeFolder() + 'keys.dat')
|
||||||
try:
|
try:
|
||||||
config.get('bitmessagesettings', 'settingsversion')
|
config.get('bitmessagesettings', 'settingsversion')
|
||||||
print('Loading config files from same directory as program.')
|
logger.info('Loading config files from same directory as program.')
|
||||||
needToCreateKeysFile = False
|
needToCreateKeysFile = False
|
||||||
state.appdata = paths.lookupExeFolder()
|
state.appdata = paths.lookupExeFolder()
|
||||||
except:
|
except:
|
||||||
|
@ -48,7 +56,8 @@ def loadConfig():
|
||||||
needToCreateKeysFile = config.safeGet(
|
needToCreateKeysFile = config.safeGet(
|
||||||
'bitmessagesettings', 'settingsversion') is None
|
'bitmessagesettings', 'settingsversion') is None
|
||||||
if not needToCreateKeysFile:
|
if not needToCreateKeysFile:
|
||||||
print('Loading existing config files from', state.appdata)
|
logger.info(
|
||||||
|
'Loading existing config files from %s', state.appdata)
|
||||||
|
|
||||||
if needToCreateKeysFile:
|
if needToCreateKeysFile:
|
||||||
|
|
||||||
|
@ -103,9 +112,10 @@ def loadConfig():
|
||||||
# Just use the same directory as the program and forget about
|
# Just use the same directory as the program and forget about
|
||||||
# the appdata folder
|
# the appdata folder
|
||||||
state.appdata = ''
|
state.appdata = ''
|
||||||
print('Creating new config files in same directory as program.')
|
logger.info(
|
||||||
|
'Creating new config files in same directory as program.')
|
||||||
else:
|
else:
|
||||||
print('Creating new config files in', state.appdata)
|
logger.info('Creating new config files in %s', state.appdata)
|
||||||
if not os.path.exists(state.appdata):
|
if not os.path.exists(state.appdata):
|
||||||
os.makedirs(state.appdata)
|
os.makedirs(state.appdata)
|
||||||
if not sys.platform.startswith('win'):
|
if not sys.platform.startswith('win'):
|
||||||
|
@ -255,7 +265,7 @@ def updateConfig():
|
||||||
'bitmessagesettings', 'hidetrayconnectionnotifications', 'false')
|
'bitmessagesettings', 'hidetrayconnectionnotifications', 'false')
|
||||||
if config.safeGetInt('bitmessagesettings', 'maxoutboundconnections') < 1:
|
if config.safeGetInt('bitmessagesettings', 'maxoutboundconnections') < 1:
|
||||||
config.set('bitmessagesettings', 'maxoutboundconnections', '8')
|
config.set('bitmessagesettings', 'maxoutboundconnections', '8')
|
||||||
print('WARNING: your maximum outbound connections must be a number.')
|
logger.warning('Your maximum outbound connections must be a number.')
|
||||||
|
|
||||||
# TTL is now user-specifiable. Let's add an option to save
|
# TTL is now user-specifiable. Let's add an option to save
|
||||||
# whatever the user selects.
|
# whatever the user selects.
|
||||||
|
@ -278,3 +288,26 @@ def isOurOperatingSystemLimitedToHavingVeryFewHalfOpenConnections():
|
||||||
return False
|
return False
|
||||||
except Exception:
|
except Exception:
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
def start_proxyconfig():
|
||||||
|
"""Check socksproxytype and start any proxy configuration plugin"""
|
||||||
|
if not get_plugin:
|
||||||
|
return
|
||||||
|
config = BMConfigParser()
|
||||||
|
proxy_type = config.safeGet('bitmessagesettings', 'socksproxytype')
|
||||||
|
if proxy_type and proxy_type not in ('none', 'SOCKS4a', 'SOCKS5'):
|
||||||
|
try:
|
||||||
|
proxyconfig_start = time.time()
|
||||||
|
if not get_plugin('proxyconfig', name=proxy_type)(config):
|
||||||
|
raise TypeError()
|
||||||
|
except TypeError:
|
||||||
|
# cannot import shutdown here ):
|
||||||
|
logger.error(
|
||||||
|
'Failed to run proxy config plugin %s',
|
||||||
|
proxy_type, exc_info=True)
|
||||||
|
os._exit(0) # pylint: disable=protected-access
|
||||||
|
else:
|
||||||
|
logger.info(
|
||||||
|
'Started proxy config plugin %s in %s sec',
|
||||||
|
proxy_type, time.time() - proxyconfig_start)
|
||||||
|
|
|
@ -14,6 +14,7 @@ import unittest
|
||||||
import knownnodes
|
import knownnodes
|
||||||
import state
|
import state
|
||||||
from bmconfigparser import BMConfigParser
|
from bmconfigparser import BMConfigParser
|
||||||
|
from helper_startup import start_proxyconfig
|
||||||
from helper_msgcoding import MsgEncode, MsgDecode
|
from helper_msgcoding import MsgEncode, MsgDecode
|
||||||
from network import asyncore_pollchoose as asyncore
|
from network import asyncore_pollchoose as asyncore
|
||||||
from network.connectionpool import BMConnectionPool
|
from network.connectionpool import BMConnectionPool
|
||||||
|
@ -21,8 +22,8 @@ from network.node import Peer
|
||||||
from network.tcp import Socks4aBMConnection, Socks5BMConnection, TCPConnection
|
from network.tcp import Socks4aBMConnection, Socks5BMConnection, TCPConnection
|
||||||
from queues import excQueue
|
from queues import excQueue
|
||||||
|
|
||||||
|
|
||||||
knownnodes_file = os.path.join(state.appdata, 'knownnodes.dat')
|
knownnodes_file = os.path.join(state.appdata, 'knownnodes.dat')
|
||||||
program = None
|
|
||||||
|
|
||||||
|
|
||||||
def pickle_knownnodes():
|
def pickle_knownnodes():
|
||||||
|
@ -196,14 +197,12 @@ class TestCore(unittest.TestCase):
|
||||||
self._check_bootstrap()
|
self._check_bootstrap()
|
||||||
self._initiate_bootstrap()
|
self._initiate_bootstrap()
|
||||||
BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'stem')
|
BMConfigParser().set('bitmessagesettings', 'socksproxytype', 'stem')
|
||||||
program.start_proxyconfig(BMConfigParser())
|
start_proxyconfig()
|
||||||
self._check_bootstrap()
|
self._check_bootstrap()
|
||||||
|
|
||||||
|
|
||||||
def run(prog):
|
def run():
|
||||||
"""Starts all tests defined in this module"""
|
"""Starts all tests defined in this module"""
|
||||||
global program # pylint: disable=global-statement
|
|
||||||
program = prog
|
|
||||||
loader = unittest.TestLoader()
|
loader = unittest.TestLoader()
|
||||||
loader.sortTestMethodsUsing = None
|
loader.sortTestMethodsUsing = None
|
||||||
suite = loader.loadTestsFromTestCase(TestCore)
|
suite = loader.loadTestsFromTestCase(TestCore)
|
||||||
|
|
Loading…
Reference in New Issue
Block a user