Created
October 27, 2014 17:46
-
-
Save harlowja/0233e4506aee1b16ac59 to your computer and use it in GitHub Desktop.
project_release.py
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
import pwd | |
import subprocess | |
import sys | |
from oslo.concurrency import processutils | |
from Cheetah.Template import Template | |
def get_changes(from_version): | |
cmd = [ | |
'git', 'log', "%s..HEAD" % from_version, | |
'--format=%s', '--no-merges', | |
] | |
stdout, stderr = processutils.execute(*cmd, check_exit_code=True) | |
changes = [] | |
for line in stdout.splitlines(): | |
line = line.strip() | |
if not line: | |
continue | |
changes.append(line) | |
return (changes, " ".join(cmd)) | |
def render(content, params): | |
return Template(content, searchList=[params]).respond() | |
TPL = """ | |
#if $series_name | |
The $team_name team is pleased to announce the release of $project $version, the first release in the $series_name series for $project. | |
#else | |
The $team_name team is pleased to announce the release of $project $version, | |
#end if | |
Documentation for the library is available at $doc_url | |
#if $changes | |
This release includes the following changes: | |
\$ $change_cmd | |
#for $c in $changes | |
$c | |
#end for | |
$prior_version... | |
#end if | |
Please report issues via launchpad: $bug_url | |
Thanks, | |
$me | |
""" | |
team_name = os.path.basename(os.getcwd()) | |
project_name = team_name | |
prior_version = sys.argv[1] | |
version = sys.argv[2] | |
try: | |
series_name = sys.argv[3] | |
except IndexError: | |
series_name = None | |
me = pwd.getpwuid(os.getuid())[4] | |
changes, change_cmd = get_changes(prior_version) | |
params = { | |
'team_name': team_name, | |
'project': project_name, | |
'series_name': series_name, | |
'version': version, | |
'doc_url': 'http://pypi.python.org/pypi/%s' % project_name, | |
'bug_url': 'https://bugs.launchpad.net/%s' % project_name, | |
'me': me, | |
'changes': changes, | |
'change_cmd': change_cmd, | |
'prior_version': prior_version, | |
} | |
print(render(TPL, params=params).strip()) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment