summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorZac Medico <zmedico@gentoo.org>2011-10-20 23:06:33 -0700
committerZac Medico <zmedico@gentoo.org>2011-10-20 23:06:33 -0700
commit1e1413717df6ed6809833004bf47088e021ccb46 (patch)
tree338fe0a2bd4a3b21e5bcc2f27d6317d3137da569
parent7d7fa4af2dbec7e7cc06e5ac176fe0b697ee867b (diff)
downloadportage-1e1413717df6ed6809833004bf47088e021ccb46.tar.gz
portage-1e1413717df6ed6809833004bf47088e021ccb46.tar.bz2
portage-1e1413717df6ed6809833004bf47088e021ccb46.zip
UpdateChangeLog: split out/test copyright regex
This also fixes a case where something like "Copyright 2011 " would be replaced with "Copyright 2011-2011 ".
-rw-r--r--pym/portage/tests/repoman/test_simple.py23
-rw-r--r--pym/repoman/utilities.py40
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 83de883e1..9dae0efda 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
class SimpleRepomanTestCase(TestCase):
+ def testCopyrightUpdate(self):
+ test_cases = (
+ (
+ '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 = find_binary("xmllint")
if not xmllint:
diff --git a/pym/repoman/utilities.py b/pym/repoman/utilities.py
index 6b4bd5098..eec6fdfee 100644
--- a/pym/repoman/utilities.py
+++ b/pym/repoman/utilities.py
@@ -524,6 +524,31 @@ def FindVCS():
return outvcs
+_copyright_re1 = re.compile(r'^(# Copyright \d\d\d\d)-\d\d\d\d ')
+_copyright_re2 = re.compile(r'^(# Copyright )(\d\d\d\d) ')
+
+
+class _copyright_repl(object):
+ __slots__ = ('year',)
+ def __init__(self, year):
+ self.year = year
+ def __call__(self, matchobj):
+ if matchobj.group(2) == 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 = _copyright_re1.sub(r'\1-%s ' % year, line)
+ line = _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
- # These two regexes are taken from echangelog
- # update_copyright(), except that we don't hardcode
- # 1999 here (in order to be more generic).
- line = re.sub(r'^(# Copyright \d+) ',
- r'\1-%s ' % year, line)
- line = re.sub(r'^(# Copyright \d\d\d\d)-\d\d\d\d',
- r'\1-%s' % year, line)
+ line = _update_copyright_year(year, line)
new_header.append(line)
difflines = 0
@@ -671,9 +690,7 @@ def UpdateChangeLog(pkgdir, user, msg, skel_path, category, 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
@@ -685,8 +702,7 @@ def UpdateChangeLog(pkgdir, user, msg, skel_path, category, package,
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 ' % year, line)
+ line = _update_copyright_year(year, line)
header_lines.append(line)
header_lines.append(_unicode_decode('\n'))
clskel_file.close()