mirror of
https://github.com/ansible-collections/community.general.git
synced 2025-07-28 07:31:23 -07:00
This commit is contained in:
parent
f7d79d4789
commit
e224039586
3 changed files with 21 additions and 16 deletions
|
@ -23,6 +23,7 @@ import os
|
|||
import shutil
|
||||
import subprocess
|
||||
import tempfile
|
||||
import tarfile
|
||||
|
||||
from ansible.errors import AnsibleError
|
||||
from ansible.module_utils.six import string_types
|
||||
|
@ -182,7 +183,7 @@ class RoleRequirement(RoleDefinition):
|
|||
return role
|
||||
|
||||
@staticmethod
|
||||
def scm_archive_role(src, scm='git', name=None, version='HEAD'):
|
||||
def scm_archive_role(src, scm='git', name=None, version='HEAD', keep_scm_meta=False):
|
||||
if scm not in ['hg', 'git']:
|
||||
raise AnsibleError("- scm %s is not currently supported" % scm)
|
||||
tempdir = tempfile.mkdtemp()
|
||||
|
@ -208,24 +209,31 @@ class RoleRequirement(RoleDefinition):
|
|||
raise AnsibleError("- command %s failed in directory %s (rc=%s)" % (' '.join(checkout_cmd), tempdir, rc))
|
||||
|
||||
temp_file = tempfile.NamedTemporaryFile(delete=False, suffix='.tar')
|
||||
if scm == 'hg':
|
||||
archive_cmd = None
|
||||
if keep_scm_meta:
|
||||
display.vvv('tarring %s from %s to %s' % (name, tempdir, temp_file.name))
|
||||
with tarfile.open(temp_file.name, "w") as tar:
|
||||
tar.add(os.path.join(tempdir, name), arcname=name)
|
||||
elif scm == 'hg':
|
||||
archive_cmd = ['hg', 'archive', '--prefix', "%s/" % name]
|
||||
if version:
|
||||
archive_cmd.extend(['-r', version])
|
||||
archive_cmd.append(temp_file.name)
|
||||
if scm == 'git':
|
||||
elif scm == 'git':
|
||||
archive_cmd = ['git', 'archive', '--prefix=%s/' % name, '--output=%s' % temp_file.name]
|
||||
if version:
|
||||
archive_cmd.append(version)
|
||||
else:
|
||||
archive_cmd.append('HEAD')
|
||||
|
||||
with open('/dev/null', 'w') as devnull:
|
||||
popen = subprocess.Popen(archive_cmd, cwd=os.path.join(tempdir, name),
|
||||
stderr=devnull, stdout=devnull)
|
||||
rc = popen.wait()
|
||||
if rc != 0:
|
||||
raise AnsibleError("- command %s failed in directory %s (rc=%s)" % (' '.join(archive_cmd), tempdir, rc))
|
||||
if archive_cmd is not None:
|
||||
display.vvv('archiving %s' % archive_cmd)
|
||||
with open('/dev/null', 'w') as devnull:
|
||||
popen = subprocess.Popen(archive_cmd, cwd=os.path.join(tempdir, name),
|
||||
stderr=devnull, stdout=devnull)
|
||||
rc = popen.wait()
|
||||
if rc != 0:
|
||||
raise AnsibleError("- command %s failed in directory %s (rc=%s)" % (' '.join(archive_cmd), tempdir, rc))
|
||||
|
||||
shutil.rmtree(tempdir, ignore_errors=True)
|
||||
return temp_file.name
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue