Skip to content

Commit

Permalink
Moved default configs to bootstrap.
Browse files Browse the repository at this point in the history
bootstrap is about setup & config
core (where it was) is about commands and bot features.
  • Loading branch information
gbin committed Jun 7, 2016
1 parent da55591 commit a9452e0
Show file tree
Hide file tree
Showing 5 changed files with 51 additions and 56 deletions.
45 changes: 43 additions & 2 deletions errbot/bootstrap.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
52 changes: 5 additions & 47 deletions errbot/core.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion tests/backend_tests/slack_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@

import mock

from errbot.core import bot_config_defaults
from errbot.bootstrap import bot_config_defaults

log = logging.getLogger(__name__)

Expand Down
5 changes: 1 addition & 4 deletions tests/base_backend_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand Down
3 changes: 1 addition & 2 deletions tests/utils_tests.py
Original file line number Diff line number Diff line change
Expand Up @@ -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 *
Expand Down

0 comments on commit a9452e0

Please sign in to comment.