blob: 61888972073ffb6adef5ef8a1bfb28242aeaacbf [file] [log] [blame]
#!/usr/bin/env {{ python }}
import os
import subprocess
import sys
LOCATION = '{{ location }}'
SPACING = 8
SCRIPTS = os.path.dirname(os.path.dirname(LOCATION))
def message(source=None, sha=None):
dirname = None
commit_message = []
try:
for line in subprocess.check_output(
[os.path.join(SCRIPTS, 'prepare-ChangeLog'), '--no-write', '--only-files', '--delimiters'],
**(dict(encoding='utf-8') if sys.version_info > (3, 0) else dict())
).splitlines():
if line == '~':
dirname = None
continue
if line.startswith(' ' * SPACING):
if dirname:
line = line.replace('* ', '* {}/'.format(dirname))
commit_message.append(line[SPACING:])
continue
if line.endswith(':'):
dirname = line.split(':')[0]
continue
return '''Need a short description (OOPS!).
Need the bug URL (OOPS!).
Reviewed by NOBODY (OOPS!).
{}
'''.format('\n'.join(commit_message))
except subprocess.CalledProcessError:
return ''
def main(file_name=None, source=None, sha=None):
if source and source != 'commit':
return 0
with open(file_name, 'w') as commit_message_file:
if sha:
commit_message_file.write(subprocess.check_output(
['{{ git }}', 'log', 'HEAD', '-1', '--pretty=format:%B'],
**(dict(encoding='utf-8') if sys.version_info > (3, 5) else dict())
))
else:
commit_message_file.write(message(source=source, sha=sha))
commit_message_file.write('''
# Please populate the above commit message. Lines starting
# with '#' will be ignored
''')
if sha:
for line in message(source=source, sha=sha).splitlines():
commit_message_file.write('# {}\n'.format(line))
commit_message_file.write('\n')
for line in subprocess.check_output(
['{{ git }}', 'status'],
**(dict(encoding='utf-8') if sys.version_info > (3, 5) else dict())
).splitlines():
commit_message_file.write('# {}\n'.format(line))
return 0
if __name__ == '__main__':
sys.exit(main(*sys.argv[1:]))