Commit 0965bde5 by David Baumgold

Hipchat plugin: ignore import errors until we care about them

parent 99c0fe5e
import os import os
import prettytable
import hipchat
import time import time
import random
from ansible import utils from ansible import utils
try:
import prettytable
except ImportError:
prettytable = None
try:
import hipchat
except ImportError:
hipchat = None
class CallbackModule(object): class CallbackModule(object):
...@@ -24,8 +29,21 @@ class CallbackModule(object): ...@@ -24,8 +29,21 @@ class CallbackModule(object):
""" """
def __init__(self): def __init__(self):
self.enabled = "HIPCHAT_TOKEN" in os.environ
if 'HIPCHAT_TOKEN' in os.environ: if not self.enabled:
return
# make sure we got our imports
if not hipchat:
raise ImportError(
"The hipchat plugin requires the hipchat Python module, "
"which is not installed or was not found."
)
if not prettytable:
raise ImportError(
"The hipchat plugin requires the prettytable Python module, "
"which is not installed or was not found."
)
self.start_time = time.time() self.start_time = time.time()
self.task_report = [] self.task_report = []
self.last_task = None self.last_task = None
...@@ -45,9 +63,6 @@ class CallbackModule(object): ...@@ -45,9 +63,6 @@ class CallbackModule(object):
self.hipchat_msg_color = os.getenv('HIPCHAT_MSG_COLOR', '') self.hipchat_msg_color = os.getenv('HIPCHAT_MSG_COLOR', '')
self.printed_playbook = False self.printed_playbook = False
self.playbook_name = None self.playbook_name = None
self.enabled = True
else:
self.enabled = False
def _send_hipchat(self, message, room=None, from_name=None, color=None, message_format='text'): def _send_hipchat(self, message, room=None, from_name=None, color=None, message_format='text'):
......
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