From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org) by finch.gentoo.org with esmtp (Exim 4.60) (envelope-from ) id 1RFaqW-0001NO-IO for garchives@archives.gentoo.org; Mon, 17 Oct 2011 00:14:24 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 5289C21C020; Mon, 17 Oct 2011 00:14:16 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 0711B21C020 for ; Mon, 17 Oct 2011 00:14:15 +0000 (UTC) Received: from pelican.gentoo.org (unknown [66.219.59.40]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by smtp.gentoo.org (Postfix) with ESMTPS id 68E821B4012 for ; Mon, 17 Oct 2011 00:14:15 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id CF33D8004C for ; Mon, 17 Oct 2011 00:14:14 +0000 (UTC) From: "Zac Medico" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Zac Medico" Message-ID: Subject: [gentoo-commits] proj/portage:master commit in: pym/repoman/ X-VCS-Repository: proj/portage X-VCS-Files: pym/repoman/utilities.py X-VCS-Directories: pym/repoman/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: b655137b7b5f87c11a7e742b7ef0e028a1139677 Date: Mon, 17 Oct 2011 00:14:14 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: X-Archives-Hash: 5f00771b315951a643a362a9a9ae650d commit: b655137b7b5f87c11a7e742b7ef0e028a1139677 Author: Zac Medico gentoo org> AuthorDate: Mon Oct 17 00:11:08 2011 +0000 Commit: Zac Medico gentoo org> CommitDate: Mon Oct 17 00:11:08 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3Db655137b 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 =20 cl_path =3D os.path.join(pkgdir, 'ChangeLog') + clold_lines =3D [] + clnew_lines =3D [] + header_lines =3D [] + + try: + clold_file =3D io.open(_unicode_encode(cl_path, + encoding=3D_encodings['fs'], errors=3D'strict'), + mode=3D'r', encoding=3D_encodings['repo.content'], errors=3D'replace'= ) + except EnvironmentError: + clold_file =3D None + f, clnew_path =3D mkstemp() =20 # create an empty ChangeLog.new with correct header first try: - f =3D os.fdopen(f, 'w+') - f.write('# ChangeLog for %s/%s\n' % (category, package)) - year =3D 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 =3D io.open(f, mode=3D'w', encoding=3D_encodings['repo.content'], + errors=3D'backslashreplace') + + if clold_file is None: + header_lines.append(_unicode_decode('# ChangeLog for %s/%s\n' % + (category, package))) + year =3D 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 =3D line.strip() + if line_strip and line[:1] !=3D "#": + clold_lines.append(line) + break + header_lines.append(line) + if not line_strip: + break =20 # write new ChangeLog entry + clnew_lines.extend(header_lines) date =3D time.strftime('%d %b %Y') newebuild =3D False for fn in new: if not fn.endswith('.ebuild'): continue ebuild =3D fn.split(os.sep)[-1][0:-7]=20 - f.write('*%s (%s)\n' % (ebuild, date)) + clnew_lines.append(_unicode_decode('*%s (%s)\n' % (ebuild, date))) newebuild =3D True if newebuild: - f.write('\n') + clnew_lines.append(_unicode_decode('\n')) new =3D ['+' + elem for elem in new if elem not in ['ChangeLog', 'Mani= fest']] removed =3D ['-' + elem for elem in removed] changed =3D [elem for elem in changed if elem not in ['ChangeLog', 'Ma= nifest']] @@ -577,45 +603,57 @@ def UpdateChangeLog(pkgdir, category, package, new,= removed, changed, msg, prete for line in textwrap.wrap(mesg, 80, \ initial_indent=3D' ', subsequent_indent=3D' ', \ break_on_hyphens=3DFalse): - f.write('%s\n' % line) + clnew_lines.append(_unicode_decode('%s\n' % line)) for line in textwrap.wrap(msg, 80, \ initial_indent=3D' ', subsequent_indent=3D' '): - 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) =20 # append stuff from old ChangeLog - cl_lines =3D [] - if os.path.exists(cl_path): - c =3D open(cl_path, 'r') - cl_lines =3D 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] =3D '# $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() =20 - # show diff (do we want to keep on doing this, or only when - # pretend?) - f.seek(0) - clnew_lines =3D f.readlines() - for line in difflib.unified_diff(cl_lines, clnew_lines, \ - fromfile=3Dcl_path, tofile=3Dcl_path + '.new', n=3D0): - print(line.rstrip()) - print() + # Now prepend header_lines to clold_lines, for use + # in the unified_diff call below. + clold_lines =3D header_lines + clold_lines =20 + for line in clold_file: + f.write(line) + clold_file.close() f.close() =20 + # 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=3Dcl_path, tofile=3Dcl_path + '.new', n=3D0): + util.writemsg_stdout(line, noiselevel=3D-1) + util.writemsg_stdout("\n", noiselevel=3D-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 =3D os.stat(cl_path) + except OSError: + clold_stat =3D None + shutil.move(clnew_path, cl_path) =20 - if cl_lines =3D=3D []: + if clold_stat is None: + util.apply_permissions(cl_path, mode=3D0o644) + else: + util.apply_stat_permissions(cl_path, clold_stat) + + if clold_file is None: return True else: return False