Migrate cli and dependencies to use global display

This commit is contained in:
Toshio Kuratomi 2015-11-10 11:40:55 -08:00
parent 1b7d3f2898
commit 318bfbb207
12 changed files with 167 additions and 131 deletions

View file

@ -21,7 +21,6 @@ __metaclass__ = type
import multiprocessing
import os
import socket
import tempfile
from ansible import constants as C
@ -34,8 +33,16 @@ from ansible.playbook.play_context import PlayContext
from ansible.plugins import callback_loader, strategy_loader, module_loader
from ansible.template import Templar
try:
from __main__ import display
display = display
except ImportError:
from ansible.utils.display import Display
display = Display()
__all__ = ['TaskQueueManager']
class TaskQueueManager:
'''
@ -48,12 +55,11 @@ class TaskQueueManager:
which dispatches the Play's tasks to hosts.
'''
def __init__(self, inventory, variable_manager, loader, display, options, passwords, stdout_callback=None):
def __init__(self, inventory, variable_manager, loader, options, passwords, stdout_callback=None):
self._inventory = inventory
self._variable_manager = variable_manager
self._loader = loader
self._display = display
self._options = options
self._stats = AggregateStats()
self.passwords = passwords
@ -155,7 +161,9 @@ class TaskQueueManager:
elif callback_needs_whitelist and (C.DEFAULT_CALLBACK_WHITELIST is None or callback_name not in C.DEFAULT_CALLBACK_WHITELIST):
continue
self._callback_plugins.append(callback_plugin(self._display))
# is it too late to change the API for v2 callback plugins?
# display is not necessary.
self._callback_plugins.append(callback_plugin(display))
else:
self._callback_plugins.append(callback_plugin())
@ -221,7 +229,7 @@ class TaskQueueManager:
return play_return
def cleanup(self):
self._display.debug("RUNNING CLEANUP")
display.debug("RUNNING CLEANUP")
self.terminate()
self._final_q.close()
self._cleanup_processes()
@ -275,4 +283,4 @@ class TaskQueueManager:
v1_method = method.replace('v2_','')
v1_method(*args, **kwargs)
except Exception:
self._display.warning('Error when using %s: %s' % (method, str(e)))
display.warning('Error when using %s: %s' % (method, str(e)))