diff options
Diffstat (limited to 'openstack/common')
| -rw-r--r-- | openstack/common/setup.py | 48 |
1 files changed, 44 insertions, 4 deletions
diff --git a/openstack/common/setup.py b/openstack/common/setup.py index 28f5e6f..9eabfcc 100644 --- a/openstack/common/setup.py +++ b/openstack/common/setup.py @@ -36,10 +36,13 @@ def parse_mailmap(mailmap='.mailmap'): return mapping -def str_dict_replace(s, mapping): - for s1, s2 in mapping.iteritems(): - s = s.replace(s1, s2) - return s +def canonicalize_emails(changelog, mapping): + """ Takes in a string and an email alias mapping and replaces all + instances of the aliases in the string with their real email + """ + for alias, email in mapping.iteritems(): + changelog = changelog.replace(alias, email) + return changelog # Get requirements from the first file that exists @@ -85,3 +88,40 @@ def write_requirements(): stdout=subprocess.PIPE) requirements = output.communicate()[0].strip() req_file.write(requirements) + + +def _run_shell_command(cmd): + output = subprocess.Popen(["/bin/sh", "-c", cmd], + stdout=subprocess.PIPE) + return output.communicate()[0].strip() + + +def write_vcsversion(location): + """ Produce a vcsversion dict that mimics the old one produced by bzr + """ + if os.path.isdir('.git'): + branch_nick_cmd = 'git branch | grep -Ei "\* (.*)" | cut -f2 -d" "' + branch_nick = _run_shell_command(branch_nick_cmd) + revid_cmd = "git rev-parse HEAD" + revid = _run_shell_command(revid_cmd).split()[0] + revno_cmd = "git log --oneline | wc -l" + revno = _run_shell_command(revno_cmd) + with open(location, 'w') as version_file: + version_file.write(""" +# This file is automatically generated by setup.py, So don't edit it. :) +version_info = { + 'branch_nick': '%s', + 'revision_id': '%s', + 'revno': %s +} +""" % (branch_nick, revid, revno)) + + +def write_git_changelog(): + """ Write a changelog based on the git changelog """ + if os.path.isdir('.git'): + git_log_cmd = 'git log --stat' + changelog = _run_shell_command(git_log_cmd) + mailmap = parse_mailmap() + with open("ChangeLog", "w") as changelog_file: + changelog_file.write(canonicalize_emails(changelog, mailmap)) |
