public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "Zac Medico" <zmedico@gentoo.org>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/portage:master commit in: pym/repoman/
Date: Mon, 17 Oct 2011 00:14:14 +0000 (UTC)	[thread overview]
Message-ID: <b655137b7b5f87c11a7e742b7ef0e028a1139677.zmedico@gentoo> (raw)

commit:     b655137b7b5f87c11a7e742b7ef0e028a1139677
Author:     Zac Medico <zmedico <AT> gentoo <DOT> org>
AuthorDate: Mon Oct 17 00:11:08 2011 +0000
Commit:     Zac Medico <zmedico <AT> gentoo <DOT> org>
CommitDate: Mon Oct 17 00:11:08 2011 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=b655137b

UpdateChangeLog: optimize and add unicode support

Also:
* copy the old header from the old ChangeLog if it exists, in case it
  contains a non-gentoo header
* don't add a header if the old ChangeLog exists and doesn't contain
  a header

---
 pym/repoman/utilities.py |  102 +++++++++++++++++++++++++++++++--------------
 1 files changed, 70 insertions(+), 32 deletions(-)

diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py
index 8f7d5d5..5b9eaf7 100644
--- a/pym/repoman/utilities.py
+++ b/pym/repoman/utilities.py
@@ -547,28 +547,54 @@ def UpdateChangeLog(pkgdir, category, package, new, removed, changed, msg, prete
 		return None
 
 	cl_path = os.path.join(pkgdir, 'ChangeLog')
+	clold_lines = []
+	clnew_lines = []
+	header_lines = []
+
+	try:
+		clold_file = io.open(_unicode_encode(cl_path,
+			encoding=_encodings['fs'], errors='strict'),
+			mode='r', encoding=_encodings['repo.content'], errors='replace')
+	except EnvironmentError:
+		clold_file = None
+
 	f, clnew_path = mkstemp()
 
 	# create an empty ChangeLog.new with correct header first
 	try:
-		f = os.fdopen(f, 'w+')
-		f.write('# ChangeLog for %s/%s\n' % (category, package))
-		year = time.strftime('%Y')
-		f.write('# Copyright 1999-%s Gentoo Foundation; Distributed under the GPL v2\n' % year)
-		f.write('# $Header: $\n')
-		f.write('\n')
+		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')
+			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:
+			for line in clold_file:
+				line_strip =  line.strip()
+				if line_strip and line[:1] != "#":
+					clold_lines.append(line)
+					break
+				header_lines.append(line)
+				if not line_strip:
+					break
 
 		# write new ChangeLog entry
+		clnew_lines.extend(header_lines)
 		date = time.strftime('%d %b %Y')
 		newebuild = False
 		for fn in new:
 			if not fn.endswith('.ebuild'):
 				continue
 			ebuild = fn.split(os.sep)[-1][0:-7] 
-			f.write('*%s (%s)\n' % (ebuild, date))
+			clnew_lines.append(_unicode_decode('*%s (%s)\n' % (ebuild, date)))
 			newebuild = True
 		if newebuild:
-			f.write('\n')
+			clnew_lines.append(_unicode_decode('\n'))
 		new = ['+' + elem for elem in new if elem not in ['ChangeLog', 'Manifest']]
 		removed = ['-' + elem for elem in removed]
 		changed = [elem for elem in changed if elem not in ['ChangeLog', 'Manifest']]
@@ -577,45 +603,57 @@ def UpdateChangeLog(pkgdir, category, package, new, removed, changed, msg, prete
 		for line in textwrap.wrap(mesg, 80, \
 				initial_indent='  ', subsequent_indent='  ', \
 				break_on_hyphens=False):
-			f.write('%s\n' % line)
+			clnew_lines.append(_unicode_decode('%s\n' % line))
 		for line in textwrap.wrap(msg, 80, \
 				initial_indent='  ', subsequent_indent='  '):
-			f.write('%s\n' % line)
+			clnew_lines.append(_unicode_decode('%s\n' % line))
+		clnew_lines.append(_unicode_decode('\n'))
+
+		for line in clnew_lines:
+			f.write(line)
 
 		# append stuff from old ChangeLog
-		cl_lines = []
-		if os.path.exists(cl_path):
-			c = open(cl_path, 'r')
-			cl_lines = c.readlines()
-			for index, line in enumerate(cl_lines):
-				# skip the headers
-				if line.startswith('#'):
-					# normalise to $Header: $ to avoid pointless diff line
-					if line.startswith('# $Header:'):
-						cl_lines[index] = '# $Header: $\n'
-					continue
+		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)
-			c.close()
 
-		# show diff (do we want to keep on doing this, or only when
-		# pretend?)
-		f.seek(0)
-		clnew_lines = f.readlines()
-		for line in difflib.unified_diff(cl_lines, clnew_lines, \
-				fromfile=cl_path, tofile=cl_path + '.new', n=0):
-			print(line.rstrip())
-		print()
+			# Now prepend header_lines to clold_lines, for use
+			# in the unified_diff call below.
+			clold_lines = header_lines + clold_lines
 
+			for line in clold_file:
+				f.write(line)
+			clold_file.close()
 		f.close()
 
+		# 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):
+			util.writemsg_stdout(line, noiselevel=-1)
+		util.writemsg_stdout("\n", noiselevel=-1)
+
 		if pretend:
 			# remove what we've done
 			os.remove(clnew_path)
 		else:
-			# rename ChangeLog.new to ChangeLog
+			# rename ChangeLog.new to ChangeLog, and set permissions
+			try:
+				clold_stat = os.stat(cl_path)
+			except OSError:
+				clold_stat = None
+
 			shutil.move(clnew_path, cl_path)
 
-		if cl_lines == []:
+			if clold_stat is None:
+				util.apply_permissions(cl_path, mode=0o644)
+			else:
+				util.apply_stat_permissions(cl_path, clold_stat)
+
+		if clold_file is None:
 			return True
 		else:
 			return False



             reply	other threads:[~2011-10-17  0:14 UTC|newest]

Thread overview: 123+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2011-10-17  0:14 Zac Medico [this message]
  -- strict thread matches above, loose matches on Subject: below --
2016-04-29 17:24 [gentoo-commits] proj/portage:master commit in: pym/repoman/ Brian Dolbec
2016-04-29 17:24 Brian Dolbec
2016-04-29 17:24 Brian Dolbec
2016-04-29 17:24 Brian Dolbec
2016-04-28 15:05 [gentoo-commits] proj/portage:repoman " Brian Dolbec
2016-04-29 17:24 ` [gentoo-commits] proj/portage:master " Brian Dolbec
2016-03-10 22:39 Brian Dolbec
2016-01-30 16:44 Brian Dolbec
2016-01-29 23:04 Brian Dolbec
2016-01-29  5:34 Brian Dolbec
2016-01-27 20:39 Brian Dolbec
2015-12-29 20:29 Zac Medico
2015-12-24 14:30 Brian Dolbec
2015-10-13 16:27 Michał Górny
2015-10-07 23:22 Brian Dolbec
2015-10-07 23:09 Brian Dolbec
2015-10-04 21:15 Brian Dolbec
2015-09-26 20:53 Brian Dolbec
2015-09-26 20:53 Brian Dolbec
2015-09-26 20:49 Brian Dolbec
2015-09-26 20:49 Brian Dolbec
2015-09-24 16:19 Brian Dolbec
2015-09-24 16:19 Brian Dolbec
2015-09-24 15:24 Brian Dolbec
2015-09-21 23:51 Brian Dolbec
2015-09-21 23:51 Brian Dolbec
2015-09-21 23:51 Brian Dolbec
2015-09-21 23:51 Brian Dolbec
2015-09-21 23:51 Brian Dolbec
2015-09-21 23:47 [gentoo-commits] proj/portage:repoman " Brian Dolbec
2015-09-21 23:51 ` [gentoo-commits] proj/portage:master " Brian Dolbec
2015-09-21 23:47 [gentoo-commits] proj/portage:repoman " Brian Dolbec
2015-09-21 23:51 ` [gentoo-commits] proj/portage:master " Brian Dolbec
2015-09-21 23:47 [gentoo-commits] proj/portage:repoman " Brian Dolbec
2015-09-21 23:51 ` [gentoo-commits] proj/portage:master " Brian Dolbec
2015-09-21 23:47 [gentoo-commits] proj/portage:repoman " Brian Dolbec
2015-09-21 23:51 ` [gentoo-commits] proj/portage:master " Brian Dolbec
2015-09-21 23:47 [gentoo-commits] proj/portage:repoman " Brian Dolbec
2015-09-21 23:51 ` [gentoo-commits] proj/portage:master " Brian Dolbec
2015-09-21 23:47 [gentoo-commits] proj/portage:repoman " Brian Dolbec
2015-09-21 23:51 ` [gentoo-commits] proj/portage:master " Brian Dolbec
2015-09-21 23:47 [gentoo-commits] proj/portage:repoman " Brian Dolbec
2015-09-21 23:51 ` [gentoo-commits] proj/portage:master " Brian Dolbec
2015-09-21 23:47 [gentoo-commits] proj/portage:repoman " Brian Dolbec
2015-09-21 23:51 ` [gentoo-commits] proj/portage:master " Brian Dolbec
2015-09-21 23:47 [gentoo-commits] proj/portage:repoman " Brian Dolbec
2015-09-21 23:51 ` [gentoo-commits] proj/portage:master " Brian Dolbec
2015-09-21 23:47 [gentoo-commits] proj/portage:repoman " Brian Dolbec
2015-09-21 23:51 ` [gentoo-commits] proj/portage:master " Brian Dolbec
2015-09-21 23:47 [gentoo-commits] proj/portage:repoman " Brian Dolbec
2015-09-21 23:51 ` [gentoo-commits] proj/portage:master " Brian Dolbec
2015-09-21 23:47 [gentoo-commits] proj/portage:repoman " Brian Dolbec
2015-09-21 23:51 ` [gentoo-commits] proj/portage:master " Brian Dolbec
2015-08-10 14:44 Michał Górny
2015-02-11  8:00 Michał Górny
2014-09-11 23:45 Brian Dolbec
2014-04-04 23:01 Brian Dolbec
2014-04-04 23:01 Brian Dolbec
2014-01-27  3:13 Chris Reffett
2013-08-08 17:33 Zac Medico
2013-05-24 19:00 Zac Medico
2013-04-22 21:08 Zac Medico
2013-03-19 16:50 Zac Medico
2013-03-15  3:30 Arfrever Frehtes Taifersar Arahesis
2013-03-14 17:18 Zac Medico
2013-02-11  9:50 Zac Medico
2013-01-19 19:11 Zac Medico
2013-01-01 23:40 Zac Medico
2013-01-01 23:23 Zac Medico
2012-12-15 20:08 Zac Medico
2012-11-22 22:12 Arfrever Frehtes Taifersar Arahesis
2012-11-22 21:53 Arfrever Frehtes Taifersar Arahesis
2012-11-22 21:51 Arfrever Frehtes Taifersar Arahesis
2012-10-31 14:11 Zac Medico
2012-10-08 14:17 Zac Medico
2012-09-12  4:56 Zac Medico
2012-09-10 21:07 Zac Medico
2012-09-10  5:52 Zac Medico
2012-09-10  5:46 Zac Medico
2012-06-21  1:02 Zac Medico
2012-06-09  2:03 Zac Medico
2012-06-08  2:52 Zac Medico
2012-06-04  4:06 Zac Medico
2012-06-04  3:25 Zac Medico
2012-06-02  6:24 Zac Medico
2012-06-02  6:24 Zac Medico
2012-06-02  5:14 Zac Medico
2012-06-01  3:32 Zac Medico
2012-06-01  2:23 Zac Medico
2012-05-31 22:27 Zac Medico
2012-05-31  0:59 Zac Medico
2012-05-30 23:56 Zac Medico
2012-05-30 23:20 Zac Medico
2012-05-25 16:18 Mike Frysinger
2012-04-23 20:18 Zac Medico
2012-04-23 20:16 Zac Medico
2012-04-23 20:08 Zac Medico
2012-04-22 23:01 Zac Medico
2012-04-22 22:58 Zac Medico
2012-04-22 22:53 Zac Medico
2012-03-05  0:01 Zac Medico
2012-02-15  0:04 Zac Medico
2012-02-12 23:32 Zac Medico
2011-10-26 18:13 Zac Medico
2011-10-21  8:11 Zac Medico
2011-10-21  7:38 Zac Medico
2011-10-21  7:20 Zac Medico
2011-10-21  7:06 Zac Medico
2011-10-21  4:53 Zac Medico
2011-10-21  1:27 Zac Medico
2011-10-20 21:51 Zac Medico
2011-10-20 21:29 Zac Medico
2011-10-20 21:26 Zac Medico
2011-10-20 20:40 Fabian Groffen
2011-10-20 20:40 Fabian Groffen
2011-10-20 19:11 Zac Medico
2011-10-17 15:53 Zac Medico
2011-10-17  3:47 Zac Medico
2011-10-17  1:11 Zac Medico
2011-10-15 12:42 Fabian Groffen
2011-09-24 19:30 Zac Medico
2011-09-10 19:40 Zac Medico
2011-08-30 16:26 Zac Medico
2011-08-09  6:44 Zac Medico
2011-07-08  8:08 Zac Medico
2011-07-08  7:47 Zac Medico
2011-07-08  7:13 Zac Medico
2011-05-31 22:25 Zac Medico
2011-04-20 23:58 Zac Medico
2011-02-28 20:39 Zac Medico
2011-02-28  5:27 Zac Medico
2011-02-19 23:49 Zac Medico
2011-02-13  7:52 Zac Medico
2011-02-05  0:58 Zac Medico
2011-02-04  5:02 zmedico

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=b655137b7b5f87c11a7e742b7ef0e028a1139677.zmedico@gentoo \
    --to=zmedico@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