2017-01-05 18:20:58 +00:00
|
|
|
#!/usr/bin/env python3
|
2017-01-05 18:00:48 +00:00
|
|
|
|
|
|
|
import os
|
2017-05-16 17:52:07 +00:00
|
|
|
import sh
|
2017-01-05 18:00:48 +00:00
|
|
|
import sys
|
|
|
|
import tempfile
|
|
|
|
|
2017-05-16 17:52:07 +00:00
|
|
|
REPO_PATH = {
|
|
|
|
'extras': '/srv/ansible/stable-2.2/lib/ansible/modules/extras',
|
|
|
|
'core': '/srv/ansible/stable-2.2/lib/ansible/modules/core'
|
|
|
|
}
|
2017-01-05 18:00:48 +00:00
|
|
|
|
|
|
|
|
|
|
|
if __name__ == '__main__':
|
|
|
|
commit_hash = sys.argv[1]
|
|
|
|
which_modules = sys.argv[2]
|
|
|
|
git = sh.git.bake('--no-pager', _tty_out=False)
|
|
|
|
try:
|
|
|
|
# Get the change
|
|
|
|
git('checkout', 'devel')
|
|
|
|
patch = git('format-patch', '-1', '--stdout', commit_hash).stdout
|
|
|
|
finally:
|
|
|
|
git('checkout', '-')
|
|
|
|
|
|
|
|
# Transform the change for the new repo
|
|
|
|
patch = patch.replace(b'lib/ansible/modules/', b'')
|
|
|
|
new_patch = []
|
|
|
|
patch_stream = (l for l in patch.split(b'\n'))
|
|
|
|
for line in patch_stream:
|
|
|
|
if line.strip() == b'---':
|
|
|
|
new_patch.append(b'(cherry picked from %s)' % commit_hash.encode('utf-8'))
|
|
|
|
new_patch.append(line)
|
|
|
|
break
|
|
|
|
new_patch.append(line)
|
|
|
|
new_patch.extend(list(patch_stream))
|
|
|
|
|
|
|
|
# Save the patch
|
|
|
|
try:
|
|
|
|
fh, patchfilename = tempfile.mkstemp()
|
|
|
|
os.write(fh, b'\n'.join(new_patch))
|
|
|
|
os.close(fh)
|
|
|
|
|
|
|
|
# Apply the patch
|
|
|
|
try:
|
|
|
|
orig_dir = os.getcwd()
|
|
|
|
os.chdir(REPO_PATH[which_modules])
|
|
|
|
git('am', patchfilename)
|
|
|
|
finally:
|
|
|
|
os.chdir(orig_dir)
|
|
|
|
except:
|
2018-01-10 20:03:25 +00:00
|
|
|
print("Problem occurred. Patch saved in: {0}".format(patchfilename))
|
2017-01-05 18:00:48 +00:00
|
|
|
else:
|
|
|
|
os.remove(patchfilename)
|