Commit a9452e06 authored by Guillaume Binet's avatar Guillaume Binet

Moved default configs to bootstrap.

bootstrap is about setup & config
core (where it was) is about commands and bot features.
parent da55591e
......@@ -19,12 +19,53 @@ CORE_STORAGE = path.join(HERE, 'storage')
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:
......
......@@ -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
......
......@@ -6,7 +6,7 @@ from tempfile import mkdtemp
import mock
from errbot.core import bot_config_defaults
from errbot.bootstrap import bot_config_defaults
log = logging.getLogger(__name__)
......
......@@ -5,9 +5,6 @@ from tempfile import mkdtemp
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.core import ErrBot
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
......
......@@ -3,8 +3,7 @@ from datetime import timedelta
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 *
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment