Skip to content
This repository has been archived by the owner on Mar 12, 2019. It is now read-only.

Commit

Permalink
Refactor the plugin loading system to accept full module paths
Browse files Browse the repository at this point in the history
This allows a person to load plugins into charlesbot, that are outside
the charlesbot namespace.
  • Loading branch information
marvinpinto committed Aug 23, 2015
1 parent 74138ce commit dc86348
Show file tree
Hide file tree
Showing 7 changed files with 18 additions and 76 deletions.
1 change: 1 addition & 0 deletions .coveragerc
Expand Up @@ -7,3 +7,4 @@ exclude_lines =
if __name__ == .__main__.:
pass
rtm_send_message
def main(args=None):
16 changes: 13 additions & 3 deletions charlesbot/robot.py
@@ -1,11 +1,11 @@
from charlesbot.util.plugins import initialize_plugins
from slackclient import SlackClient
import logging
import asyncio
import sys
import signal
import traceback
import functools
import importlib
from charlesbot.config import configuration


Expand Down Expand Up @@ -43,7 +43,6 @@ def route_message_to_plugin(self):
yield from asyncio.sleep(0.5)

def get_message_type(self, msg):
import importlib
obj_list = [
"charlesbot.slack.slack_channel_joined.SlackChannelJoined",
"charlesbot.slack.slack_channel_left.SlackChannelLeft",
Expand All @@ -60,6 +59,17 @@ def get_message_type(self, msg):
return_obj.load(msg)
return return_obj

def initialize_plugins(self):
return_list = []
if not self.enabled_plugins:
return return_list
for x in self.enabled_plugins:
module_name, class_name = x.rsplit(".", 1)
obj_class = getattr(importlib.import_module(module_name), class_name) # NOQA
return_obj = obj_class(self.sc)
return_list.append(return_obj)
return return_list

@asyncio.coroutine
def queue_message(self, message, plugin):
if message:
Expand All @@ -86,7 +96,7 @@ def start(self):
self.log.error("Error conecting to Slack - possible token issue?")
sys.exit(1)
loop = asyncio.get_event_loop()
self.plugin_list = initialize_plugins(self.sc, self.enabled_plugins)
self.plugin_list = self.initialize_plugins()
loop.create_task(self.produce())
loop.add_signal_handler(
signal.SIGINT,
Expand Down
16 changes: 0 additions & 16 deletions charlesbot/util/plugins.py

This file was deleted.

10 changes: 0 additions & 10 deletions config.ini.example

This file was deleted.

6 changes: 4 additions & 2 deletions config.yaml.example
@@ -1,8 +1,10 @@
main:
slackbot_token: 'xoxb-...'
enabled_plugins:
- 'BroadcastMessage'
- 'Help'
- 'charlesbot.plugins.broadcast_message.BroadcastMessage'
- 'charlesbot.plugins.help_plugin.Help'
- 'charlesbot.plugins.pagerduty.pagerduty.Pagerduty'
- 'charlesbot.plugins.jira.jira.Jira'

pagerduty:
token: 'E7px6VVr3PVHZPJq51oa'
Expand Down
Empty file removed tests/util/plugins/__init__.py
Empty file.
45 changes: 0 additions & 45 deletions tests/util/plugins/test_robot_utils.py

This file was deleted.

0 comments on commit dc86348

Please sign in to comment.