diff --git a/errbot/bootstrap.py b/errbot/bootstrap.py index d37986dfa..cd4116055 100644 --- a/errbot/bootstrap.py +++ b/errbot/bootstrap.py @@ -19,12 +19,53 @@ PLUGIN_DEFAULT_INDEX = 'https://repos.errbot.io/repos.json' +def bot_config_defaults(config): + if not hasattr(config, 'ACCESS_CONTROLS_DEFAULT'): + config.ACCESS_CONTROLS_DEFAULT = {} + if not hasattr(config, 'ACCESS_CONTROLS'): + config.ACCESS_CONTROLS = {} + if not hasattr(config, 'HIDE_RESTRICTED_COMMANDS'): + config.HIDE_RESTRICTED_COMMANDS = False + if not hasattr(config, 'HIDE_RESTRICTED_ACCESS'): + config.HIDE_RESTRICTED_ACCESS = False + if not hasattr(config, 'BOT_PREFIX_OPTIONAL_ON_CHAT'): + config.BOT_PREFIX_OPTIONAL_ON_CHAT = False + if not hasattr(config, 'BOT_PREFIX'): + config.BOT_PREFIX = '!' + if not hasattr(config, 'BOT_ALT_PREFIXES'): + config.BOT_ALT_PREFIXES = () + if not hasattr(config, 'BOT_ALT_PREFIX_SEPARATORS'): + config.BOT_ALT_PREFIX_SEPARATORS = () + if not hasattr(config, 'BOT_ALT_PREFIX_CASEINSENSITIVE'): + config.BOT_ALT_PREFIX_CASEINSENSITIVE = False + if not hasattr(config, 'DIVERT_TO_PRIVATE'): + config.DIVERT_TO_PRIVATE = () + if not hasattr(config, 'MESSAGE_SIZE_LIMIT'): + config.MESSAGE_SIZE_LIMIT = 10000 # Corresponds with what HipChat accepts + if not hasattr(config, 'GROUPCHAT_NICK_PREFIXED'): + config.GROUPCHAT_NICK_PREFIXED = False + if not hasattr(config, 'AUTOINSTALL_DEPS'): + config.AUTOINSTALL_DEPS = True + if not hasattr(config, 'SUPPRESS_CMD_NOT_FOUND'): + config.SUPPRESS_CMD_NOT_FOUND = False + if not hasattr(config, 'BOT_ASYNC'): + config.BOT_ASYNC = True + if not hasattr(config, 'CHATROOM_PRESENCE'): + config.CHATROOM_PRESENCE = () + if not hasattr(config, 'CHATROOM_RELAY'): + config.CHATROOM_RELAY = () + if not hasattr(config, 'CHATROOM_FN'): + config.CHATROOM_FN = 'Errbot' + if not hasattr(config, 'TEXT_DEMO_MODE'): + config.TEXT_DEMO_MODE = True + if not hasattr(config, 'BOT_ADMINS'): + raise ValueError('BOT_ADMINS missing from config.py.') + + def setup_bot(backend_name, logger, config, restore=None): # from here the environment is supposed to be set (daemon / non daemon, # config.py in the python path ) - from .core import bot_config_defaults - bot_config_defaults(config) if config.BOT_LOG_FILE: diff --git a/errbot/core.py b/errbot/core.py index 88474cd07..0e15a2c26 100644 --- a/errbot/core.py +++ b/errbot/core.py @@ -13,69 +13,27 @@ # You should have received a copy of the GNU General Public License # along with this program; if not, write to the Free Software # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA -from datetime import datetime import difflib import inspect import logging import re import traceback +from datetime import datetime +from threading import RLock + +from threadpool import ThreadPool, WorkRequest from errbot import CommandError from errbot.flow import FlowExecutor, FlowRoot from .backends.base import Backend, Room, Identifier, Message -from threadpool import ThreadPool, WorkRequest -from threading import RLock +from .storage import StoreMixin from .streaming import Tee from .templating import tenv from .utils import split_string_after, get_class_that_defined_method -from .storage import StoreMixin log = logging.getLogger(__name__) -def bot_config_defaults(config): - if not hasattr(config, 'ACCESS_CONTROLS_DEFAULT'): - config.ACCESS_CONTROLS_DEFAULT = {} - if not hasattr(config, 'ACCESS_CONTROLS'): - config.ACCESS_CONTROLS = {} - if not hasattr(config, 'HIDE_RESTRICTED_COMMANDS'): - config.HIDE_RESTRICTED_COMMANDS = False - if not hasattr(config, 'HIDE_RESTRICTED_ACCESS'): - config.HIDE_RESTRICTED_ACCESS = False - if not hasattr(config, 'BOT_PREFIX_OPTIONAL_ON_CHAT'): - config.BOT_PREFIX_OPTIONAL_ON_CHAT = False - if not hasattr(config, 'BOT_PREFIX'): - config.BOT_PREFIX = '!' - if not hasattr(config, 'BOT_ALT_PREFIXES'): - config.BOT_ALT_PREFIXES = () - if not hasattr(config, 'BOT_ALT_PREFIX_SEPARATORS'): - config.BOT_ALT_PREFIX_SEPARATORS = () - if not hasattr(config, 'BOT_ALT_PREFIX_CASEINSENSITIVE'): - config.BOT_ALT_PREFIX_CASEINSENSITIVE = False - if not hasattr(config, 'DIVERT_TO_PRIVATE'): - config.DIVERT_TO_PRIVATE = () - if not hasattr(config, 'MESSAGE_SIZE_LIMIT'): - config.MESSAGE_SIZE_LIMIT = 10000 # Corresponds with what HipChat accepts - if not hasattr(config, 'GROUPCHAT_NICK_PREFIXED'): - config.GROUPCHAT_NICK_PREFIXED = False - if not hasattr(config, 'AUTOINSTALL_DEPS'): - config.AUTOINSTALL_DEPS = True - if not hasattr(config, 'SUPPRESS_CMD_NOT_FOUND'): - config.SUPPRESS_CMD_NOT_FOUND = False - if not hasattr(config, 'BOT_ASYNC'): - config.BOT_ASYNC = True - if not hasattr(config, 'CHATROOM_PRESENCE'): - config.CHATROOM_PRESENCE = () - if not hasattr(config, 'CHATROOM_RELAY'): - config.CHATROOM_RELAY = () - if not hasattr(config, 'CHATROOM_FN'): - config.CHATROOM_FN = 'Errbot' - if not hasattr(config, 'TEXT_DEMO_MODE'): - config.TEXT_DEMO_MODE = True - if not hasattr(config, 'BOT_ADMINS'): - raise ValueError('BOT_ADMINS missing from config.py.') - - # noinspection PyAbstractClass class ErrBot(Backend, StoreMixin): """ ErrBot is the layer of Err that takes care of the plugin management and dispatching diff --git a/tests/backend_tests/slack_tests.py b/tests/backend_tests/slack_tests.py index 4b4e7fee7..b5e91fbd0 100644 --- a/tests/backend_tests/slack_tests.py +++ b/tests/backend_tests/slack_tests.py @@ -6,7 +6,7 @@ import mock -from errbot.core import bot_config_defaults +from errbot.bootstrap import bot_config_defaults log = logging.getLogger(__name__) diff --git a/tests/base_backend_tests.py b/tests/base_backend_tests.py index 577f03191..396fd47f3 100644 --- a/tests/base_backend_tests.py +++ b/tests/base_backend_tests.py @@ -5,9 +5,6 @@ from os.path import sep import pytest - -from errbot.core import bot_config_defaults - import os # noqa import re # noqa from collections import OrderedDict @@ -16,7 +13,7 @@ from errbot.backends.base import Message, Room, Identifier, ONLINE from errbot.backends.test import TestPerson, TestOccupant, TestRoom, ShallowConfig from errbot import botcmd, re_botcmd, arg_botcmd, templating # noqa -from errbot.bootstrap import CORE_STORAGE +from errbot.bootstrap import CORE_STORAGE, bot_config_defaults from errbot.plugin_manager import BotPluginManager from errbot.rendering import text from errbot.core_plugins.acls import ACLS diff --git a/tests/utils_tests.py b/tests/utils_tests.py index cb9ae913d..21be2b2a3 100644 --- a/tests/utils_tests.py +++ b/tests/utils_tests.py @@ -3,8 +3,7 @@ import pytest from errbot.backends.test import ShallowConfig -from errbot.core import bot_config_defaults -from errbot.bootstrap import CORE_STORAGE +from errbot.bootstrap import CORE_STORAGE, bot_config_defaults from errbot.specific_plugin_manager import SpecificPluginManager from errbot.storage.base import StoragePluginBase from errbot.utils import *