Discussion:
[gentoo-portage-dev] [PATCH 1/3] repoman: Update header checks for the new copyright policy
Michał Górny
2018-09-18 09:15:36 UTC
Permalink
Update the header checks to account for the new copyright policy:
- there can be multiple copyright lines,
- copyright owner can be anyone,
- at least one copyright line should match last modification date.

This requires updating the check to appropriately allow the license
line to move down. Additionally, the copyright date error is separated
from invalid copyright line error.
---
repoman/cnf/linechecks/linechecks.yaml | 3 +-
.../linechecks/gentoo_header/header.py | 47 ++++++++++++-------
2 files changed, 32 insertions(+), 18 deletions(-)

diff --git a/repoman/cnf/linechecks/linechecks.yaml b/repoman/cnf/linechecks/linechecks.yaml
index 634381e80..32b1bf82f 100644
--- a/repoman/cnf/linechecks/linechecks.yaml
+++ b/repoman/cnf/linechecks/linechecks.yaml
@@ -9,7 +9,8 @@ repoman_version: 2.3.3
# configuration file for the LineCheck plugins run via the multicheck
# scan module
errors:
- COPYRIGHT_ERROR: 'Invalid Gentoo Copyright on line: %d'
+ COPYRIGHT_ERROR: 'Invalid Copyright on line: %d'
+ COPYRIGHT_DATE_ERROR: 'No copyright for last modification date before line %d'
LICENSE_ERROR: 'Invalid Gentoo/GPL License on line: %d'
ID_HEADER_ERROR: 'Stale CVS header on line: %d'
NO_BLANK_LINE_ERROR: 'Non-blank line after header on line: %d'
diff --git a/repoman/lib/repoman/modules/linechecks/gentoo_header/header.py b/repoman/lib/repoman/modules/linechecks/gentoo_header/header.py
index 4b75fc4b5..c64674319 100644
--- a/repoman/lib/repoman/modules/linechecks/gentoo_header/header.py
+++ b/repoman/lib/repoman/modules/linechecks/gentoo_header/header.py
@@ -17,33 +17,46 @@ class EbuildHeader(LineCheck):

repoman_check_name = 'ebuild.badheader'

- gentoo_copyright = r'^# Copyright ((1999|2\d\d\d)-)?%s Gentoo Foundation$'
+ copyright_re = re.compile(r'^# Copyright ((1999|2\d\d\d)-)?(?P<year>2\d\d\d) \w')
gentoo_license = (
'# Distributed under the terms'
' of the GNU General Public License v2')
id_header_re = re.compile(r'.*\$(Id|Header)(:.*)?\$.*')
- blank_line_re = re.compile(r'^$')
ignore_comment = False

def new(self, pkg):
if pkg.mtime is None:
- self.modification_year = r'2\d\d\d'
+ self.modification_year = None
else:
- self.modification_year = str(time.gmtime(pkg.mtime)[0])
- self.gentoo_copyright_re = re.compile(
- self.gentoo_copyright % self.modification_year)
+ self.modification_year = time.gmtime(pkg.mtime)[0]
+ self.last_copyright_line = -1
+ self.last_copyright_year = -1

def check(self, num, line):
- if num > 2:
+ if num > self.last_copyright_line + 2:
return
- elif num == 0:
- if not self.gentoo_copyright_re.match(line):
+ elif num == self.last_copyright_line + 1:
+ # copyright can extend for a few initial lines
+ copy_match = self.copyright_re.match(line)
+ if copy_match is not None:
+ self.last_copyright_line = num
+ self.last_copyright_year = max(self.last_copyright_year,
+ int(copy_match.group('year')))
+ # no copyright lines found?
+ elif self.last_copyright_line == -1:
return self.errors['COPYRIGHT_ERROR']
- elif num == 1 and line.rstrip('\n') != self.gentoo_license:
- return self.errors['LICENSE_ERROR']
- elif num == 2 and self.id_header_re.match(line):
- return self.errors['ID_HEADER_ERROR']
- elif num == 2 and not self.blank_line_re.match(line):
- return self.errors['NO_BLANK_LINE_ERROR']
-
-
+ else:
+ # verify that the newest copyright line found
+ # matches the year of last modification
+ if (self.modification_year is not None
+ and self.last_copyright_year != self.modification_year):
+ return self.errors['COPYRIGHT_DATE_ERROR']
+
+ # copyright is immediately followed by license
+ if line.rstrip('\n') != self.gentoo_license:
+ return self.errors['LICENSE_ERROR']
+ elif num == self.last_copyright_line + 2:
+ if self.id_header_re.match(line):
+ return self.errors['ID_HEADER_ERROR']
+ elif line.rstrip('\n') != '':
+ return self.errors['NO_BLANK_LINE_ERROR']
--
2.19.0
Michał Górny
2018-09-18 09:15:37 UTC
Permalink
---
repoman/lib/repoman/copyrights.py | 4 ++--
repoman/lib/repoman/tests/simple/test_simple.py | 10 ++++++++++
2 files changed, 12 insertions(+), 2 deletions(-)

diff --git a/repoman/lib/repoman/copyrights.py b/repoman/lib/repoman/copyrights.py
index 94257c942..25627b3fc 100644
--- a/repoman/lib/repoman/copyrights.py
+++ b/repoman/lib/repoman/copyrights.py
@@ -15,9 +15,9 @@ from portage import util


_copyright_re1 = \
- re.compile(br'^(# Copyright \d\d\d\d)-\d\d\d\d( Gentoo Foundation)\b')
+ re.compile(br'^(# Copyright \d\d\d\d)-\d\d\d\d( Gentoo (Foundation|Authors))\b')
_copyright_re2 = \
- re.compile(br'^(# Copyright )(\d\d\d\d)( Gentoo Foundation)\b')
+ re.compile(br'^(# Copyright )(\d\d\d\d)( Gentoo (Foundation|Authors))\b')


class _copyright_repl(object):
diff --git a/repoman/lib/repoman/tests/simple/test_simple.py b/repoman/lib/repoman/tests/simple/test_simple.py
index 3d7a70ad0..351dde2c7 100644
--- a/repoman/lib/repoman/tests/simple/test_simple.py
+++ b/repoman/lib/repoman/tests/simple/test_simple.py
@@ -35,6 +35,16 @@ class SimpleRepomanTestCase(TestCase):
'# Copyright 1999 Gentoo Foundation; Distributed under the GPL v2',
'# Copyright 1999 Gentoo Foundation; Distributed under the GPL v2',
),
+ (
+ '2018',
+ '# Copyright 1999-2008 Gentoo Authors; Distributed under the GPL v2',
+ '# Copyright 1999-2018 Gentoo Authors; Distributed under the GPL v2',
+ ),
+ (
+ '2018',
+ '# Copyright 2017 Gentoo Authors; Distributed under the GPL v2',
+ '# Copyright 2017-2018 Gentoo Authors; Distributed under the GPL v2',
+ ),
)

for year, before, after in test_cases:
--
2.19.0
Michał Górny
2018-09-18 09:15:38 UTC
Permalink
Automatically convert 'Gentoo Foundation' copyright to 'Gentoo Authors'
when updating the copyright date.
---
repoman/lib/repoman/copyrights.py | 4 ++--
repoman/lib/repoman/tests/changelog/test_echangelog.py | 2 +-
repoman/lib/repoman/tests/simple/test_simple.py | 4 ++--
3 files changed, 5 insertions(+), 5 deletions(-)

diff --git a/repoman/lib/repoman/copyrights.py b/repoman/lib/repoman/copyrights.py
index 25627b3fc..1eaaab660 100644
--- a/repoman/lib/repoman/copyrights.py
+++ b/repoman/lib/repoman/copyrights.py
@@ -31,7 +31,7 @@ class _copyright_repl(object):
return matchobj.group(0)
else:
return matchobj.group(1) + matchobj.group(2) + \
- b'-' + self.year + matchobj.group(3)
+ b'-' + self.year + b' Gentoo Authors'


def update_copyright_year(year, line):
@@ -51,7 +51,7 @@ def update_copyright_year(year, line):
year = _unicode_encode(year)
line = _unicode_encode(line)

- line = _copyright_re1.sub(br'\1-' + year + br'\2', line)
+ line = _copyright_re1.sub(br'\1-' + year + b' Gentoo Authors', line)
line = _copyright_re2.sub(_copyright_repl(year), line)
if not is_bytes:
line = _unicode_decode(line)
diff --git a/repoman/lib/repoman/tests/changelog/test_echangelog.py b/repoman/lib/repoman/tests/changelog/test_echangelog.py
index 1640be268..e5e34f16c 100644
--- a/repoman/lib/repoman/tests/changelog/test_echangelog.py
+++ b/repoman/lib/repoman/tests/changelog/test_echangelog.py
@@ -30,7 +30,7 @@ class RepomanEchangelogTestCase(TestCase):
os.makedirs(self.pkgdir)

self.header_pkg = '# ChangeLog for %s/%s\n' % (self.cat, self.pkg)
- self.header_copyright = '# Copyright 1999-%s Gentoo Foundation; Distributed under the GPL v2\n' % \
+ self.header_copyright = '# Copyright 1999-%s Gentoo Authors; Distributed under the GPL v2\n' % \
time.strftime('%Y', time.gmtime())
self.header_cvs = '# $Header: $\n'

diff --git a/repoman/lib/repoman/tests/simple/test_simple.py b/repoman/lib/repoman/tests/simple/test_simple.py
index 351dde2c7..b0cc43297 100644
--- a/repoman/lib/repoman/tests/simple/test_simple.py
+++ b/repoman/lib/repoman/tests/simple/test_simple.py
@@ -23,12 +23,12 @@ class SimpleRepomanTestCase(TestCase):
(
'2011',
'# Copyright 1999-2008 Gentoo Foundation; Distributed under the GPL v2',
- '# Copyright 1999-2011 Gentoo Foundation; Distributed under the GPL v2',
+ '# Copyright 1999-2011 Gentoo Authors; 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',
+ '# Copyright 1999-2011 Gentoo Authors; Distributed under the GPL v2',
),
(
'1999',
--
2.19.0
Loading...