Gentoo Archives: gentoo-portage-dev

From: "Michał Górny" <mgorny@g.o>
To: gentoo-portage-dev@l.g.o
Cc: "Michał Górny" <mgorny@g.o>
Subject: [gentoo-portage-dev] [PATCH 1/3] repoman: Update header checks for the new copyright policy
Date: Tue, 18 Sep 2018 09:19:34
Message-Id: 20180918091538.19895-1-mgorny@gentoo.org
1 Update the header checks to account for the new copyright policy:
2 - there can be multiple copyright lines,
3 - copyright owner can be anyone,
4 - at least one copyright line should match last modification date.
5
6 This requires updating the check to appropriately allow the license
7 line to move down. Additionally, the copyright date error is separated
8 from invalid copyright line error.
9 ---
10 repoman/cnf/linechecks/linechecks.yaml | 3 +-
11 .../linechecks/gentoo_header/header.py | 47 ++++++++++++-------
12 2 files changed, 32 insertions(+), 18 deletions(-)
13
14 diff --git a/repoman/cnf/linechecks/linechecks.yaml b/repoman/cnf/linechecks/linechecks.yaml
15 index 634381e80..32b1bf82f 100644
16 --- a/repoman/cnf/linechecks/linechecks.yaml
17 +++ b/repoman/cnf/linechecks/linechecks.yaml
18 @@ -9,7 +9,8 @@ repoman_version: 2.3.3
19 # configuration file for the LineCheck plugins run via the multicheck
20 # scan module
21 errors:
22 - COPYRIGHT_ERROR: 'Invalid Gentoo Copyright on line: %d'
23 + COPYRIGHT_ERROR: 'Invalid Copyright on line: %d'
24 + COPYRIGHT_DATE_ERROR: 'No copyright for last modification date before line %d'
25 LICENSE_ERROR: 'Invalid Gentoo/GPL License on line: %d'
26 ID_HEADER_ERROR: 'Stale CVS header on line: %d'
27 NO_BLANK_LINE_ERROR: 'Non-blank line after header on line: %d'
28 diff --git a/repoman/lib/repoman/modules/linechecks/gentoo_header/header.py b/repoman/lib/repoman/modules/linechecks/gentoo_header/header.py
29 index 4b75fc4b5..c64674319 100644
30 --- a/repoman/lib/repoman/modules/linechecks/gentoo_header/header.py
31 +++ b/repoman/lib/repoman/modules/linechecks/gentoo_header/header.py
32 @@ -17,33 +17,46 @@ class EbuildHeader(LineCheck):
33
34 repoman_check_name = 'ebuild.badheader'
35
36 - gentoo_copyright = r'^# Copyright ((1999|2\d\d\d)-)?%s Gentoo Foundation$'
37 + copyright_re = re.compile(r'^# Copyright ((1999|2\d\d\d)-)?(?P<year>2\d\d\d) \w')
38 gentoo_license = (
39 '# Distributed under the terms'
40 ' of the GNU General Public License v2')
41 id_header_re = re.compile(r'.*\$(Id|Header)(:.*)?\$.*')
42 - blank_line_re = re.compile(r'^$')
43 ignore_comment = False
44
45 def new(self, pkg):
46 if pkg.mtime is None:
47 - self.modification_year = r'2\d\d\d'
48 + self.modification_year = None
49 else:
50 - self.modification_year = str(time.gmtime(pkg.mtime)[0])
51 - self.gentoo_copyright_re = re.compile(
52 - self.gentoo_copyright % self.modification_year)
53 + self.modification_year = time.gmtime(pkg.mtime)[0]
54 + self.last_copyright_line = -1
55 + self.last_copyright_year = -1
56
57 def check(self, num, line):
58 - if num > 2:
59 + if num > self.last_copyright_line + 2:
60 return
61 - elif num == 0:
62 - if not self.gentoo_copyright_re.match(line):
63 + elif num == self.last_copyright_line + 1:
64 + # copyright can extend for a few initial lines
65 + copy_match = self.copyright_re.match(line)
66 + if copy_match is not None:
67 + self.last_copyright_line = num
68 + self.last_copyright_year = max(self.last_copyright_year,
69 + int(copy_match.group('year')))
70 + # no copyright lines found?
71 + elif self.last_copyright_line == -1:
72 return self.errors['COPYRIGHT_ERROR']
73 - elif num == 1 and line.rstrip('\n') != self.gentoo_license:
74 - return self.errors['LICENSE_ERROR']
75 - elif num == 2 and self.id_header_re.match(line):
76 - return self.errors['ID_HEADER_ERROR']
77 - elif num == 2 and not self.blank_line_re.match(line):
78 - return self.errors['NO_BLANK_LINE_ERROR']
79 -
80 -
81 + else:
82 + # verify that the newest copyright line found
83 + # matches the year of last modification
84 + if (self.modification_year is not None
85 + and self.last_copyright_year != self.modification_year):
86 + return self.errors['COPYRIGHT_DATE_ERROR']
87 +
88 + # copyright is immediately followed by license
89 + if line.rstrip('\n') != self.gentoo_license:
90 + return self.errors['LICENSE_ERROR']
91 + elif num == self.last_copyright_line + 2:
92 + if self.id_header_re.match(line):
93 + return self.errors['ID_HEADER_ERROR']
94 + elif line.rstrip('\n') != '':
95 + return self.errors['NO_BLANK_LINE_ERROR']
96 --
97 2.19.0

Replies