public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Fabian Groffen" <grobian@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: pym/repoman/, bin/
Date: Thu, 20 Oct 2011 20:40:21 +0000 (UTC)	[thread overview]
Message-ID: <ef99ccb7710f090ab7166f95587ccdd19e2cc740.grobian@gentoo> (raw)

commit:     ef99ccb7710f090ab7166f95587ccdd19e2cc740
Author:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
AuthorDate: Thu Oct 20 20:35:41 2011 +0000
Commit:     Fabian Groffen <grobian <AT> gentoo <DOT> org>
CommitDate: Thu Oct 20 20:35:41 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=ef99ccb7

repoman: get ChangeLog header from skel.ChangeLog

Use skel.ChangeLog from the repo to create the header of a new ChangeLog
file.  Else, we just retain the original header of the ChangeLog.  When
no skel.ChangeLog file exists, and this is a new ChangeLog, no header is
used.

---
 bin/repoman              |    2 +-
 pym/repoman/utilities.py |   79 +++++++++++++++++++++++++---------------------
 2 files changed, 44 insertions(+), 37 deletions(-)

diff --git a/bin/repoman b/bin/repoman
index bec3b1e..5b01825 100755
--- a/bin/repoman
+++ b/bin/repoman
@@ -2471,7 +2471,7 @@ else:
 			new_changelog = utilities.UpdateChangeLog(checkdir_relative, \
 				catdir, pkgdir, \
 				clnew, clremoved, clchanged, \
-				changelog_msg, options.pretend)
+				changelog_msg, options.pretend, repodir)
 			if new_changelog is None:
 				writemsg_level("!!! Updating the ChangeLog failed\n", \
 					level=logging.ERROR, noiselevel=-1)

diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py
index c8cbba7..0eeea8b 100644
--- a/pym/repoman/utilities.py
+++ b/pym/repoman/utilities.py
@@ -523,7 +523,8 @@ def FindVCS():
 
 	return outvcs
 
-def UpdateChangeLog(pkgdir, category, package, new, removed, changed, msg, pretend):
+def UpdateChangeLog(pkgdir, category, package, new, removed, changed, \
+		msg, pretend, repodir):
 	""" Write an entry to an existing ChangeLog, or create a new one. """
 
 	# figure out who to write as
@@ -550,7 +551,6 @@ def UpdateChangeLog(pkgdir, category, package, new, removed, changed, msg, prete
 	cl_path = os.path.join(pkgdir, 'ChangeLog')
 	clold_lines = []
 	clnew_lines = []
-	old_header_lines = []
 	header_lines = []
 
 	try:
@@ -560,42 +560,51 @@ def UpdateChangeLog(pkgdir, category, package, new, removed, changed, msg, prete
 	except EnvironmentError:
 		clold_file = None
 
+	clskel_file = None
+	if clold_file is None:
+		# we will only need the ChangeLog skeleton if there is no
+		# ChangeLog yet
+		try:
+			clskel_path = os.path.join(repodir, 'skel.ChangeLog')
+			clskel_file = io.open(_unicode_encode(clskel_path,
+				encoding=_encodings['fs'], errors='strict'),
+				mode='r', encoding=_encodings['repo.content'],
+				errors='replace')
+		except EnvironmentError:
+			pass
+
 	# ChangeLog times are in UTC
 	gmtime = time.gmtime()
 	f, clnew_path = mkstemp()
 
-	# create an empty ChangeLog.new with correct header first
+	# construct correct header first
 	try:
-		f = io.open(f, mode='w', encoding=_encodings['repo.content'],
-			errors='backslashreplace')
-
-		if clold_file is None:
-			header_lines.append(_unicode_decode('# ChangeLog for %s/%s\n' %
-				(category, package)))
-			year = time.strftime('%Y', gmtime)
-			header_lines.append(_unicode_decode('# Copyright 1999-'
-				'%s Gentoo Foundation; Distributed under the GPL v2\n' % year))
-			header_lines.append(_unicode_decode('# $Header: $\n'))
-			header_lines.append(_unicode_decode('\n'))
-		else:
+		if clold_file is not None:
+			# retain header from old ChangeLog
 			for line in clold_file:
-				line_strip =  line.strip()
-				if line_strip and line[:1] != "#":
-					clold_lines.append(line)
+				line_strip = line.strip()
+				clold_lines.append(line)
+				if line_strip[:1] != '#':
 					break
-				header_lines.append(line)
+				if clskel_file is None:
+					clnew_lines.append(line)
 				if not line_strip:
 					break
-
-			# update the copyright year
-			old_header_lines = header_lines[:]
-			if len(header_lines) >= 2:
-				header_lines[1] = re.sub(r'^(# Copyright \d\d\d\d)-\d\d\d\d ',
-					r'\1-%s ' % time.strftime('%Y', gmtime), header_lines[1])
+		elif clskel_file is not None:
+			# read skel.ChangeLog up to first empty line
+			for line in clskel_file:
+				line_strip = line.strip()
+				if not line_strip:
+					break
+				line = line.replace('<CATEGORY>', category)
+				line = line.replace('<PACKAGE_NAME>', package)
+				line = re.sub(r'^(# Copyright \d\d\d\d)-\d\d\d\d ',
+					r'\1-%s ' % time.strftime('%Y', gmtime), line)
+				clnew_lines.append(line)
+			clnew_lines.append(_unicode_decode('\n'))
+			clskel_file.close()
 
 		# write new ChangeLog entry
-		clnew_lines.extend(header_lines)
-		date = time.strftime('%d %b %Y', gmtime)
 		newebuild = False
 		for fn in new:
 			if not fn.endswith('.ebuild'):
@@ -634,20 +643,18 @@ def UpdateChangeLog(pkgdir, category, package, new, removed, changed, msg, prete
 			clnew_lines.append(_unicode_decode('%s\n' % line))
 		clnew_lines.append(_unicode_decode('\n'))
 
+		f = io.open(f, mode='w', encoding=_encodings['repo.content'],
+			errors='backslashreplace')
+
 		for line in clnew_lines:
 			f.write(line)
 
 		# append stuff from old ChangeLog
 		if clold_file is not None:
-			# If the old ChangeLog didn't have a header, then
 			# clold_lines may contain a saved non-header line
 			# that we want to write first.
-			for line in clold_lines:
-				f.write(line)
-
-			# Now prepend old_header_lines to clold_lines, for use
-			# in the unified_diff call below.
-			clold_lines = old_header_lines + clold_lines
+			if clold_lines and clold_lines[-1].strip():
+				f.write(clold_lines[-1])
 
 			for line in clold_file:
 				f.write(line)
@@ -657,7 +664,7 @@ def UpdateChangeLog(pkgdir, category, package, new, removed, changed, msg, prete
 		# show diff (do we want to keep on doing this, or only when
 		# pretend?)
 		for line in difflib.unified_diff(clold_lines, clnew_lines,
-			fromfile=cl_path, tofile=cl_path + '.new', n=0):
+			fromfile=cl_path, tofile=cl_path, n=0):
 			util.writemsg_stdout(line, noiselevel=-1)
 		util.writemsg_stdout("\n", noiselevel=-1)
 
@@ -665,7 +672,7 @@ def UpdateChangeLog(pkgdir, category, package, new, removed, changed, msg, prete
 			# remove what we've done
 			os.remove(clnew_path)
 		else:
-			# rename ChangeLog.new to ChangeLog, and set permissions
+			# rename to ChangeLog, and set permissions
 			try:
 				clold_stat = os.stat(cl_path)
 			except OSError:



             reply	other threads:[~2011-10-20 20:40 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-20 20:40 Fabian Groffen [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-02-12  0:53 [gentoo-commits] proj/portage:master commit in: pym/repoman/, bin/ Chris Reffett
2012-05-25 16:18 Mike Frysinger
2011-11-21 17:12 Zac Medico
2011-10-21  4:08 Zac Medico
2011-10-17  0:14 Zac Medico

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=ef99ccb7710f090ab7166f95587ccdd19e2cc740.grobian@gentoo \
    --to=grobian@gentoo.org \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox