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 1RH8Ix-000482-Ii for garchives@archives.gentoo.org; Fri, 21 Oct 2011 06:10:07 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 6FCBF21C113; Fri, 21 Oct 2011 06:09:59 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 2C0EF21C113 for ; Fri, 21 Oct 2011 06:09:59 +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 94B461B4013 for ; Fri, 21 Oct 2011 06:09:58 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by pelican.gentoo.org (Postfix) with ESMTP id CA51980042 for ; Fri, 21 Oct 2011 06:09:57 +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: <1e1413717df6ed6809833004bf47088e021ccb46.zmedico@gentoo> Subject: [gentoo-commits] proj/portage:master commit in: pym/repoman/, pym/portage/tests/repoman/ X-VCS-Repository: proj/portage X-VCS-Files: pym/portage/tests/repoman/test_simple.py pym/repoman/utilities.py X-VCS-Directories: pym/repoman/ pym/portage/tests/repoman/ X-VCS-Committer: zmedico X-VCS-Committer-Name: Zac Medico X-VCS-Revision: 1e1413717df6ed6809833004bf47088e021ccb46 Date: Fri, 21 Oct 2011 06:09:57 +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: 6b7e63820a0c82ead5c1be0cfebbff08 commit: 1e1413717df6ed6809833004bf47088e021ccb46 Author: Zac Medico gentoo org> AuthorDate: Fri Oct 21 06:06:33 2011 +0000 Commit: Zac Medico gentoo org> CommitDate: Fri Oct 21 06:06:33 2011 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/portage.git;a= =3Dcommit;h=3D1e141371 UpdateChangeLog: split out/test copyright regex This also fixes a case where something like "Copyright 2011 " would be replaced with "Copyright 2011-2011 ". --- pym/portage/tests/repoman/test_simple.py | 23 +++++++++++++++++ pym/repoman/utilities.py | 40 +++++++++++++++++++++---= ------ 2 files changed, 51 insertions(+), 12 deletions(-) diff --git a/pym/portage/tests/repoman/test_simple.py b/pym/portage/tests= /repoman/test_simple.py index 83de883..9dae0ef 100644 --- a/pym/portage/tests/repoman/test_simple.py +++ b/pym/portage/tests/repoman/test_simple.py @@ -14,9 +14,32 @@ from portage.process import find_binary from portage.tests import TestCase from portage.tests.resolver.ResolverPlayground import ResolverPlayground from portage.util import ensure_dirs +from repoman.utilities import _update_copyright_year =20 class SimpleRepomanTestCase(TestCase): =20 + def testCopyrightUpdate(self): + test_cases =3D ( + ( + '2011', + '# Copyright 1999-2008 Gentoo Foundation; Distributed under the GPL = v2', + '# Copyright 1999-2011 Gentoo Foundation; Distributed under the GPL = v2', + ), + ( + '2011', + '# Copyright 1999 Gentoo Foundation; Distributed under the GPL v2', + '# Copyright 1999-2011 Gentoo Foundation; Distributed under the GPL = v2', + ), + ( + '1999', + '# Copyright 1999 Gentoo Foundation; Distributed under the GPL v2', + '# Copyright 1999 Gentoo Foundation; Distributed under the GPL v2', + ), + ) + + for year, before, after in test_cases: + self.assertEqual(_update_copyright_year(year, before), after) + def _must_skip(self): xmllint =3D find_binary("xmllint") if not xmllint: diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py index 6b4bd50..eec6fdf 100644 --- a/pym/repoman/utilities.py +++ b/pym/repoman/utilities.py @@ -524,6 +524,31 @@ def FindVCS(): =20 return outvcs =20 +_copyright_re1 =3D re.compile(r'^(# Copyright \d\d\d\d)-\d\d\d\d ') +_copyright_re2 =3D re.compile(r'^(# Copyright )(\d\d\d\d) ') + + +class _copyright_repl(object): + __slots__ =3D ('year',) + def __init__(self, year): + self.year =3D year + def __call__(self, matchobj): + if matchobj.group(2) =3D=3D self.year: + return matchobj.group(0) + else: + return '%s%s-%s ' % \ + (matchobj.group(1), matchobj.group(2), self.year) + +def _update_copyright_year(year, line): + """ + These two regexes are taken from echangelog + update_copyright(), except that we don't hardcode + 1999 here (in order to be more generic). + """ + line =3D _copyright_re1.sub(r'\1-%s ' % year, line) + line =3D _copyright_re2.sub(_copyright_repl(year), line) + return line + def update_copyright(fn_path, year, pretend): """ Check file for a Copyright statement, and update its year. The @@ -549,13 +574,7 @@ def update_copyright(fn_path, year, pretend): new_header.append(line) break =20 - # These two regexes are taken from echangelog - # update_copyright(), except that we don't hardcode - # 1999 here (in order to be more generic). - 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-%s' % year, line) + line =3D _update_copyright_year(year, line) new_header.append(line) =20 difflines =3D 0 @@ -671,9 +690,7 @@ def UpdateChangeLog(pkgdir, user, msg, skel_path, cat= egory, package, clold_lines.append(line) break old_header_lines.append(line) - header_lines.append( - re.sub(r'^(# Copyright \d\d\d\d)-\d\d\d\d ', - r'\1-%s ' % year, line)) + header_lines.append(_update_copyright_year(year, line)) if not line_strip: break =20 @@ -685,8 +702,7 @@ def UpdateChangeLog(pkgdir, user, msg, skel_path, cat= egory, package, break 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 ' % year, line) + line =3D _update_copyright_year(year, line) header_lines.append(line) header_lines.append(_unicode_decode('\n')) clskel_file.close()