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 1RGzPo-0008J8-8x for garchives@archives.gentoo.org; Thu, 20 Oct 2011 20:40:36 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 94D3F21C042; Thu, 20 Oct 2011 20:40:23 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 4A8B021C042 for ; Thu, 20 Oct 2011 20:40:23 +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 7DB331B400D for ; Thu, 20 Oct 2011 20:40:22 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id AB7328004C for ; Thu, 20 Oct 2011 20:40:21 +0000 (UTC) From: "Fabian Groffen" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "Fabian Groffen" 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: grobian X-VCS-Committer-Name: Fabian Groffen X-VCS-Revision: ba8396c5e6bc9a979df46f7b8d209f89f2a89a14 Date: Thu, 20 Oct 2011 20:40:21 +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: d208b23189ba0edec8e1e8b6fbafadcf commit: ba8396c5e6bc9a979df46f7b8d209f89f2a89a14 Author: Fabian Groffen gentoo org> AuthorDate: Thu Oct 20 20:38:00 2011 +0000 Commit: Fabian Groffen gentoo org> CommitDate: Thu Oct 20 20:38:00 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3Dba8396c5 repoman: update copyright on modified files To retain the behaviour of echangelog, update the copyrights on modified files (mostly ebuilds) when necessary. Also update the ChangeLog's copyright. --- pym/repoman/utilities.py | 91 ++++++++++++++++++++++++++++++++++++++++= +++--- 1 files changed, 85 insertions(+), 6 deletions(-) diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py index 0eeea8b..3195136 100644 --- a/pym/repoman/utilities.py +++ b/pym/repoman/utilities.py @@ -523,9 +523,77 @@ def FindVCS(): =20 return outvcs =20 +def update_copyright(fn_path, year, pretend): + """ + Check file for a Copyright statement, and update its year. The + patterns used for replacing copyrights are taken from echangelog. + Only the first lines of each file that start with a hash ('#') are + considered, until a line is found that doesn't start with a hash. + """ + + try: + fn_hdl =3D io.open(_unicode_encode(fn_path, + encoding=3D_encodings['fs'], errors=3D'strict'), + mode=3D'r', encoding=3D_encodings['repo.content'], errors=3D'replace'= ) + except EnvironmentError: + return + + orig_header =3D [] + new_header =3D [] + + for line in fn_hdl: + line_strip =3D line.strip() + orig_header.append(line) + if not line_strip or line_strip[:1] !=3D '#': + new_header.append(line) + break + + # these two regexes are taken from + # echangelog update_copyright() + line =3D re.sub(r'^(# Copyright \d+) ', + r'\1-%s ' % year, line) + line =3D re.sub(r'^(# Copyright) \d\d\d\d-\d\d\d\d', + r'\1 1999-%s' % year, line) + new_header.append(line) + + difflines =3D 0 + for line in difflib.unified_diff(orig_header, new_header, + fromfile=3Dfn_path, tofile=3Dfn_path, n=3D0): + util.writemsg_stdout(line, noiselevel=3D-1) + difflines +=3D 1 + util.writemsg_stdout("\n", noiselevel=3D-1) + + # unified diff has three lines to start with + if difflines > 3 and not pretend: + # write new file with changed header + f, fnnew_path =3D mkstemp() + f =3D io.open(f, mode=3D'w', encoding=3D_encodings['repo.content'], + errors=3D'backslashreplace') + for line in new_header: + f.write(line); + for line in fn_hdl: + f.write(line) + f.close() + try: + fn_stat =3D os.stat(fn_path) + except OSError: + fn_stat =3D None + + shutil.move(fnnew_path, fn_path) + + if fn_stat is None: + util.apply_permissions(fn_path, mode=3D0o644) + else: + util.apply_stat_permissions(fn_path, fn_stat) + fn_hdl.close() + def UpdateChangeLog(pkgdir, category, package, new, removed, changed, \ msg, pretend, repodir): - """ Write an entry to an existing ChangeLog, or create a new one. """ + """ + Write an entry to an existing ChangeLog, or create a new one. + Updates copyright year on changed files, and updates the header of + ChangeLog with the contents of skel.ChangeLog. + """ =20 # figure out who to write as if 'GENTOO_COMMITTER_NAME' in os.environ and \ @@ -548,6 +616,18 @@ def UpdateChangeLog(pkgdir, category, package, new, = removed, changed, \ logging.critical(err) return None =20 + # ChangeLog times are in UTC = =20 + gmtime =3D time.gmtime() =20 + year =3D time.strftime('%Y', gmtime) + date =3D time.strftime('%d %b %Y', gmtime) + + # check modified files and the ChangeLog for copyright updates + # patches and diffs (identified by .patch and .diff) are excluded + for fn in new + changed: + if fn.endswith('.diff') or fn.endswith('.patch'): + continue + update_copyright(os.path.join(pkgdir, fn), year, pretend) + cl_path =3D os.path.join(pkgdir, 'ChangeLog') clold_lines =3D [] clnew_lines =3D [] @@ -573,8 +653,6 @@ def UpdateChangeLog(pkgdir, category, package, new, r= emoved, changed, \ except EnvironmentError: pass =20 - # ChangeLog times are in UTC - gmtime =3D time.gmtime() f, clnew_path =3D mkstemp() =20 # construct correct header first @@ -586,8 +664,9 @@ def UpdateChangeLog(pkgdir, category, package, new, r= emoved, changed, \ clold_lines.append(line) if line_strip[:1] !=3D '#': break - if clskel_file is None: - clnew_lines.append(line) + line =3D re.sub(r'^(# Copyright) \d\d\d\d-\d\d\d\d', + r'\1 1999-%s' % year, line) + clnew_lines.append(line) if not line_strip: break elif clskel_file is not None: @@ -599,7 +678,7 @@ def UpdateChangeLog(pkgdir, category, package, new, r= emoved, changed, \ line =3D line.replace('', category) line =3D line.replace('', package) line =3D re.sub(r'^(# Copyright \d\d\d\d)-\d\d\d\d ', - r'\1-%s ' % time.strftime('%Y', gmtime), line) + r'\1-%s ' % year, line) clnew_lines.append(line) clnew_lines.append(_unicode_decode('\n')) clskel_file.close()