mirror of
https://github.com/ansible-collections/community.general.git
synced 2026-05-06 21:32:49 +00:00
Merge pull request #13771 from sivel/binary-modules
First pass at allowing binary modules
This commit is contained in:
@@ -490,6 +490,11 @@ def recursive_finder(name, data, py_module_names, py_module_cache, zf):
|
||||
# Save memory; the file won't have to be read again for this ansible module.
|
||||
del py_module_cache[py_module_file]
|
||||
|
||||
def _is_binary(module_data):
|
||||
textchars = bytearray(set([7, 8, 9, 10, 12, 13, 27]) | set(range(0x20, 0x100)) - set([0x7f]))
|
||||
start = module_data[:1024]
|
||||
return bool(start.translate(None, textchars))
|
||||
|
||||
def _find_snippet_imports(module_name, module_data, module_path, module_args, task_vars, module_compression):
|
||||
"""
|
||||
Given the source of the module, convert it to a Jinja2 template to insert
|
||||
@@ -504,7 +509,9 @@ def _find_snippet_imports(module_name, module_data, module_path, module_args, ta
|
||||
# module_substyle is extra information that's useful internally. It tells
|
||||
# us what we have to look to substitute in the module files and whether
|
||||
# we're using module replacer or ziploader to format the module itself.
|
||||
if REPLACER in module_data:
|
||||
if _is_binary(module_data):
|
||||
module_substyle = module_style = 'binary'
|
||||
elif REPLACER in module_data:
|
||||
# Do REPLACER before from ansible.module_utils because we need make sure
|
||||
# we substitute "from ansible.module_utils basic" for REPLACER
|
||||
module_style = 'new'
|
||||
@@ -523,9 +530,9 @@ def _find_snippet_imports(module_name, module_data, module_path, module_args, ta
|
||||
module_substyle = module_style = 'non_native_want_json'
|
||||
|
||||
shebang = None
|
||||
# Neither old-style nor non_native_want_json modules should be modified
|
||||
# Neither old-style, non_native_want_json nor binary modules should be modified
|
||||
# except for the shebang line (Done by modify_module)
|
||||
if module_style in ('old', 'non_native_want_json'):
|
||||
if module_style in ('old', 'non_native_want_json', 'binary'):
|
||||
return module_data, module_style, shebang
|
||||
|
||||
output = BytesIO()
|
||||
@@ -731,7 +738,9 @@ def modify_module(module_name, module_path, module_args, task_vars=dict(), modul
|
||||
|
||||
(module_data, module_style, shebang) = _find_snippet_imports(module_name, module_data, module_path, module_args, task_vars, module_compression)
|
||||
|
||||
if shebang is None:
|
||||
if module_style == 'binary':
|
||||
return (module_data, module_style, shebang)
|
||||
elif shebang is None:
|
||||
lines = module_data.split(b"\n", 1)
|
||||
if lines[0].startswith(b"#!"):
|
||||
shebang = lines[0].strip()
|
||||
|
||||
Reference in New Issue
Block a user