mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-25 14:20:22 -07:00
Revert templating enhancements from 73dbab70
e6c28658
d409352c
9858b1f2
4587528b
9b1fe455
214b0b05
8d3db803
7f9504d1
5031104c
35cb9dc2
2bd8cb57
1e85c754
This commit is contained in:
parent
e0fbaea566
commit
d154bf8781
11 changed files with 1244 additions and 1397 deletions
|
@ -77,32 +77,39 @@ def write_argsfile(argstring, json=False):
|
|||
def boilerplate_module(modfile, args):
|
||||
""" simulate what ansible does with new style modules """
|
||||
|
||||
#module_fh = open(modfile)
|
||||
#module_data = module_fh.read()
|
||||
#module_fh.close()
|
||||
module_fh = open(modfile)
|
||||
module_data = module_fh.read()
|
||||
included_boilerplate = module_data.find(module_common.REPLACER) != -1
|
||||
module_fh.close()
|
||||
|
||||
replacer = module_common.ModuleReplacer()
|
||||
if included_boilerplate:
|
||||
|
||||
#included_boilerplate = module_data.find(module_common.REPLACER) != -1 or module_data.find("import ansible.module_utils") != -1
|
||||
module_data = module_data.replace(module_common.REPLACER, module_common.MODULE_COMMON)
|
||||
encoded_args = repr(str(args))
|
||||
module_data = module_data.replace(module_common.REPLACER_ARGS, encoded_args)
|
||||
encoded_lang = repr(C.DEFAULT_MODULE_LANG)
|
||||
empty_complex = repr("{}")
|
||||
module_data = module_data.replace(module_common.REPLACER_LANG, encoded_lang)
|
||||
module_data = module_data.replace('syslog.LOG_USER', "syslog.%s" % C.DEFAULT_SYSLOG_FACILITY)
|
||||
module_data = module_data.replace(module_common.REPLACER_COMPLEX, empty_complex)
|
||||
|
||||
complex_args = {}
|
||||
inject = {}
|
||||
(module_data, module_style, shebang) = replacer.modify_module(
|
||||
modfile,
|
||||
complex_args,
|
||||
args,
|
||||
inject
|
||||
)
|
||||
modfile2_path = os.path.expanduser("~/.ansible_module_generated")
|
||||
print "* including generated source, if any, saving to: %s" % modfile2_path
|
||||
print "* this will offset any line numbers in tracebacks/debuggers!"
|
||||
modfile2 = open(modfile2_path, 'w')
|
||||
modfile2.write(module_data)
|
||||
modfile2.close()
|
||||
modfile = modfile2_path
|
||||
|
||||
modfile2_path = os.path.expanduser("~/.ansible_module_generated")
|
||||
print "* including generated source, if any, saving to: %s" % modfile2_path
|
||||
print "* this may offset any line numbers in tracebacks/debuggers!"
|
||||
modfile2 = open(modfile2_path, 'w')
|
||||
modfile2.write(module_data)
|
||||
modfile2.close()
|
||||
modfile = modfile2_path
|
||||
return (modfile2_path, included_boilerplate, False)
|
||||
else:
|
||||
|
||||
return (modfile2_path, module_style)
|
||||
old_style_but_json = False
|
||||
if 'WANT_JSON' in module_data:
|
||||
old_style_but_json = True
|
||||
|
||||
print "* module boilerplate substitution not requested in module, line numbers will be unaltered"
|
||||
return (modfile, included_boilerplate, old_style_but_json)
|
||||
|
||||
def runtest( modfile, argspath):
|
||||
"""Test run a module, piping it's output for reporting."""
|
||||
|
@ -144,16 +151,14 @@ def rundebug(debugger, modfile, argspath):
|
|||
def main():
|
||||
|
||||
options, args = parse()
|
||||
(modfile, module_style) = boilerplate_module(options.module_path, options.module_args)
|
||||
(modfile, is_new_style, old_style_but_json) = boilerplate_module(options.module_path, options.module_args)
|
||||
|
||||
argspath=None
|
||||
if module_style != 'new':
|
||||
if module_style == 'non_native_want_json':
|
||||
if not is_new_style:
|
||||
if old_style_but_json:
|
||||
argspath = write_argsfile(options.module_args, json=True)
|
||||
elif module_style == 'old':
|
||||
argspath = write_argsfile(options.module_args, json=False)
|
||||
else:
|
||||
raise Exception("internal error, unexpected module style: %s" % module_style)
|
||||
argspath = write_argsfile(options.module_args, json=False)
|
||||
if options.debugger:
|
||||
rundebug(options.debugger, modfile, argspath)
|
||||
else:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue