mirror of
https://github.com/ansible-collections/community.general.git
synced 2024-09-14 20:13:21 +02:00
Adding delimiter fixes to action_plugin + fixing local assembling with a delimiter
Also added a new integration test for assemble using local assembly with a delimiter.
This commit is contained in:
parent
dc93b31d22
commit
82b24c162e
3 changed files with 41 additions and 11 deletions
|
@ -115,6 +115,7 @@ FILE_COMMON_ARGUMENTS=dict(
|
||||||
backup = dict(),
|
backup = dict(),
|
||||||
force = dict(),
|
force = dict(),
|
||||||
remote_src = dict(), # used by assemble
|
remote_src = dict(), # used by assemble
|
||||||
|
delimiter = dict(), # used by assemble
|
||||||
directory_mode = dict(), # used by copy
|
directory_mode = dict(), # used by copy
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
|
@ -31,24 +31,43 @@ class ActionModule(object):
|
||||||
def __init__(self, runner):
|
def __init__(self, runner):
|
||||||
self.runner = runner
|
self.runner = runner
|
||||||
|
|
||||||
def _assemble_from_fragments(self, src_path, delimiter=None):
|
def _assemble_from_fragments(self, src_path, delimiter=None, compiled_regexp=None):
|
||||||
''' assemble a file from a directory of fragments '''
|
''' assemble a file from a directory of fragments '''
|
||||||
tmpfd, temp_path = tempfile.mkstemp()
|
tmpfd, temp_path = tempfile.mkstemp()
|
||||||
tmp = os.fdopen(tmpfd,'w')
|
tmp = os.fdopen(tmpfd,'w')
|
||||||
delimit_me = False
|
delimit_me = False
|
||||||
|
add_newline = False
|
||||||
|
|
||||||
for f in sorted(os.listdir(src_path)):
|
for f in sorted(os.listdir(src_path)):
|
||||||
|
if compiled_regexp and not compiled_regexp.search(f):
|
||||||
|
continue
|
||||||
fragment = "%s/%s" % (src_path, f)
|
fragment = "%s/%s" % (src_path, f)
|
||||||
if delimit_me and delimiter:
|
if not os.path.isfile(fragment):
|
||||||
# en-escape things like new-lines
|
continue
|
||||||
delimiter = delimiter.decode('unicode-escape')
|
fragment_content = file(fragment).read()
|
||||||
tmp.write(delimiter)
|
|
||||||
# always make sure there's a newline after the
|
# always put a newline between fragments if the previous fragment didn't end with a newline.
|
||||||
# delimiter, so lines don't run together
|
if add_newline:
|
||||||
if delimiter[-1] != '\n':
|
tmp.write('\n')
|
||||||
tmp.write('\n')
|
|
||||||
if os.path.isfile(fragment):
|
# delimiters should only appear between fragments
|
||||||
tmp.write(file(fragment).read())
|
if delimit_me:
|
||||||
|
if delimiter:
|
||||||
|
# un-escape anything like newlines
|
||||||
|
delimiter = delimiter.decode('unicode-escape')
|
||||||
|
tmp.write(delimiter)
|
||||||
|
# always make sure there's a newline after the
|
||||||
|
# delimiter, so lines don't run together
|
||||||
|
if delimiter[-1] != '\n':
|
||||||
|
tmp.write('\n')
|
||||||
|
|
||||||
|
tmp.write(fragment_content)
|
||||||
delimit_me = True
|
delimit_me = True
|
||||||
|
if fragment_content.endswith('\n'):
|
||||||
|
add_newline = False
|
||||||
|
else:
|
||||||
|
add_newline = True
|
||||||
|
|
||||||
tmp.close()
|
tmp.close()
|
||||||
return temp_path
|
return temp_path
|
||||||
|
|
||||||
|
|
|
@ -69,3 +69,13 @@
|
||||||
- "result.state == 'file'"
|
- "result.state == 'file'"
|
||||||
- "result.md5sum == '96905702a2ece40de6bf3a94b5062513'"
|
- "result.md5sum == '96905702a2ece40de6bf3a94b5062513'"
|
||||||
|
|
||||||
|
- name: test assemble with remote_src=False and a delimiter
|
||||||
|
assemble: src="./" dest="{{output_dir}}/assembled5" remote_src=no delimiter="#--- delimiter ---#"
|
||||||
|
register: result
|
||||||
|
|
||||||
|
- name: assert the fragments were assembled without remote
|
||||||
|
assert:
|
||||||
|
that:
|
||||||
|
- "result.state == 'file'"
|
||||||
|
- "result.md5sum == '4773eac67aba3f0be745876331c8a450'"
|
||||||
|
|
||||||
|
|
Loading…
Add table
Reference in a new issue