mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-04-24 19:31:26 -07:00
use faster method to get short_description from DOCUMENTATION (#42705)
* use faster method to get short_description from DOCUMENTATION * fixed pep8 whitespace * fixed blank line
This commit is contained in:
parent
350dbaf457
commit
551501f326
3 changed files with 58 additions and 5 deletions
|
@ -80,3 +80,43 @@ def read_docstring(filename, verbose=True, ignore_errors=True):
|
|||
raise
|
||||
|
||||
return data
|
||||
|
||||
|
||||
def read_docstub(filename, verbose=True, ignore_errors=True):
|
||||
"""
|
||||
Quickly find short_description using string methods instead of node parsing.
|
||||
This does not return a full set of documentation strings and is intended for
|
||||
operations like ansible-doc -l.
|
||||
"""
|
||||
|
||||
data = {
|
||||
'doc': None,
|
||||
'plainexamples': None,
|
||||
'returndocs': None,
|
||||
'metadata': None
|
||||
}
|
||||
|
||||
try:
|
||||
t_module_data = open(filename, 'r')
|
||||
capturing = False
|
||||
doc_stub = []
|
||||
|
||||
for line in t_module_data:
|
||||
# start capturing the stub until indentation returns
|
||||
if capturing and line[0] == ' ':
|
||||
doc_stub.append(line)
|
||||
elif capturing and line[0] != ' ':
|
||||
break
|
||||
if 'short_description:' in line:
|
||||
capturing = True
|
||||
doc_stub.append(line)
|
||||
|
||||
data['doc'] = AnsibleLoader(r"".join(doc_stub), file_name=filename).get_single_data()
|
||||
|
||||
except:
|
||||
if verbose:
|
||||
display.error("unable to parse %s" % filename)
|
||||
if not ignore_errors:
|
||||
raise
|
||||
|
||||
return data
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue