get_docstring has changed output, rework code to get exception raised by get_docstring

reviewable/pr18001/r3
Matt Martz 9 years ago committed by John Barker
parent 4d24f3ba61
commit cbe7052ebe

@ -8,6 +8,7 @@ import abc
import ast import ast
import sys import sys
import argparse import argparse
import traceback
from fnmatch import fnmatch from fnmatch import fnmatch
from utils import find_globals from utils import find_globals
@ -16,10 +17,8 @@ from ansible.executor.module_common import REPLACER_WINDOWS
from ansible.utils.module_docs import get_docstring, BLACKLIST_MODULES from ansible.utils.module_docs import get_docstring, BLACKLIST_MODULES
from ansible.module_utils import basic as module_utils_basic from ansible.module_utils import basic as module_utils_basic
try: # We only use StringIO, since we cannot setattr on cStringIO
from cStringIO import StringIO from StringIO import StringIO
except ImportError:
from StringIO import StringIO
BLACKLIST_DIRS = frozenset(('.git',)) BLACKLIST_DIRS = frozenset(('.git',))
@ -68,7 +67,6 @@ class Validator(object):
ret = [] ret = []
for trace in self.traces: for trace in self.traces:
#print(trace.replace(self._root, '').lstrip('/'))
print(trace) print(trace)
for error in self.errors: for error in self.errors:
print('ERROR: %s' % error) print('ERROR: %s' % error)
@ -326,10 +324,17 @@ class ModuleValidator(Validator):
sys_stdout = sys.stdout sys_stdout = sys.stdout
sys_stderr = sys.stderr sys_stderr = sys.stderr
sys.stdout = sys.stderr = StringIO() sys.stdout = sys.stderr = StringIO()
doc, examples, ret = get_docstring(self.path) setattr(sys.stdout, 'encoding', sys_stdout.encoding)
trace = sys.stdout.getvalue() setattr(sys.stderr, 'encoding', sys_stderr.encoding)
sys.stdout = sys_stdout try:
sys.stderr = sys_stderr doc, examples, ret = get_docstring(self.path, verbose=True)
trace = None
except:
doc, examples, ret = get_docstring(self.path)
trace = traceback.format_exc()
finally:
sys.stdout = sys_stdout
sys.stderr = sys_stderr
if trace: if trace:
self.traces.append(trace) self.traces.append(trace)
if not bool(doc): if not bool(doc):

Loading…
Cancel
Save