Michał Górny
2018-09-18 09:15:36 UTC
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']
- 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
2.19.0