#!/usr/bin/env python import os.path import sys import pybaz import shutil import datetime import subprocess if not os.path.exists("./{arch}"): print "This is not a working tree" sys.exit(1) tree = pybaz.WorkingTree("./") if not tree.has_changes(): print "There are no changes to comment" sys.exit(0) tmpdir = ".update-ChangeLog.tmp" if os.path.exists(tmpdir): shutil.rmtree(tmpdir) changes = tree.changes (None, tmpdir) changed_files = [] for change in changes.iter_created_files(): changed_files += [("created", change[2])] for change in changes.iter_removed_files(): changed_files += [("removed", change[2])] for change in changes.iter_patched_files(): changed_files += [("modified", change[2])] entry = "" today = datetime.datetime.now() entry += "%04d-%02d-%02d %s <%s>\n" % (today.year, today.month, today.day, os.environ["REAL_NAME"], os.environ["EMAIL_ADDRESS"]) for cf in changed_files: if cf[1] == "ChangeLog": continue if cf[0] == "created": entry += "\t* Added %s\n" % cf[1] elif cf[0] == "removed": entry += "\t* Removed %s\n" % cf[1] else: entry += "\t* %s: \n" % cf[1] oldclf = open("ChangeLog", "r") oldcl = oldclf.read() oldclf.close() shutil.move("ChangeLog", "ChangeLog.old") cfl = open("ChangeLog", "w") cfl.write(entry) cfl.write("\n") cfl.write(oldcl) cfl.close() subprocess.call([os.environ["EDITOR"], "ChangeLog"]) if os.path.exists(tmpdir): shutil.rmtree(tmpdir)