From f757cd2a4dd2d3634743c207a4aadb3f217bfce1 Mon Sep 17 00:00:00 2001 From: Fabian Groffen Date: Sun, 16 Oct 2011 15:31:07 -0700 Subject: repoman: implemented echangelog functionality Instead of calling echangelog, which on its turn has to query the VCS again, use the existing information on changes made to the current directory, and update the ChangeLog from Python itself. This avoids a call to echangelog, and avoids again retrieving the same VCS information as repoman already did. It makes repoman independent from external tools it didn't install itself, and should be faster in general. --- pym/repoman/utilities.py | 122 ++++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 120 insertions(+), 2 deletions(-) (limited to 'pym/repoman/utilities.py') diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py index 79137036c..8f7d5d54c 100644 --- a/pym/repoman/utilities.py +++ b/pym/repoman/utilities.py @@ -5,6 +5,8 @@ """This module contains utility functions to help repoman find ebuilds to scan""" +from __future__ import print_function + __all__ = [ "detect_vcs_conflicts", "editor_is_executable", @@ -17,13 +19,22 @@ __all__ = [ "have_profile_dir", "parse_metadata_use", "UnknownHerdsError", - "check_metadata" + "check_metadata", + "UpdateChangeLog" ] import errno import io +from itertools import chain import logging +import pwd import sys +import time +import textwrap +import difflib +import shutil +from tempfile import mkstemp + from portage import os from portage import subprocess_getstatusoutput from portage import _encodings @@ -308,7 +319,6 @@ def get_commit_message_with_editor(editor, message=None): @rtype: string or None @returns: A string on success or None if an error occurs. """ - from tempfile import mkstemp fd, filename = mkstemp() try: os.write(fd, _unicode_encode(_( @@ -511,3 +521,111 @@ def FindVCS(): outvcs = seek() return outvcs + +def UpdateChangeLog(pkgdir, category, package, new, removed, changed, msg, pretend): + """ Write an entry to an existing ChangeLog, or create a new one. """ + + # figure out who to write as + if 'GENTOO_COMMITTER_NAME' in os.environ and \ + 'GENTOO_COMMITTER_EMAIL' in os.environ: + user = '%s <%s>' % (os.environ['GENTOO_COMMITTER_NAME'], \ + os.environ['GENTOO_COMMITTER_EMAIL']) + elif 'GENTOO_AUTHOR_NAME' in os.environ and \ + 'GENTOO_AUTHOR_EMAIL' in os.environ: + user = '%s <%s>' % (os.environ['GENTOO_AUTHOR_NAME'], \ + os.environ['GENTOO_AUTHOR_EMAIL']) + elif 'ECHANGELOG_USER' in os.environ: + user = os.environ['ECHANGELOG_USER'] + else: + (login, _, _, _, gecos, _, _) = pwd.getpwuid(os.getuid()) + gecos = gecos.split(',')[0] # bug #80011 + user = '%s <%s@gentoo.org>' % (gecos, login) + + if '