1 |
commit: 921078cfc279df30c2982f9516c0998a12505c2d |
2 |
Author: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
3 |
AuthorDate: Sat Jul 15 01:01:04 2017 +0000 |
4 |
Commit: Brian Dolbec <dolsen <AT> gentoo <DOT> org> |
5 |
CommitDate: Fri Mar 30 00:43:45 2018 +0000 |
6 |
URL: https://gitweb.gentoo.org/proj/portage.git/commit/?id=921078cf |
7 |
|
8 |
repoman: New linechecks module, gentoo_header |
9 |
|
10 |
.../modules/linechecks/gentoo_header/__init__.py | 21 ++++++++++ |
11 |
.../modules/linechecks/gentoo_header/header.py | 49 ++++++++++++++++++++++ |
12 |
2 files changed, 70 insertions(+) |
13 |
|
14 |
diff --git a/repoman/pym/repoman/modules/linechecks/gentoo_header/__init__.py b/repoman/pym/repoman/modules/linechecks/gentoo_header/__init__.py |
15 |
new file mode 100644 |
16 |
index 000000000..b80a83ecf |
17 |
--- /dev/null |
18 |
+++ b/repoman/pym/repoman/modules/linechecks/gentoo_header/__init__.py |
19 |
@@ -0,0 +1,21 @@ |
20 |
+# Copyright 2015-2016 Gentoo Foundation |
21 |
+# Distributed under the terms of the GNU General Public License v2 |
22 |
+ |
23 |
+doc = """Gentoo-header plug-in module for repoman LineChecks. |
24 |
+Performs header checks on ebuilds.""" |
25 |
+__doc__ = doc[:] |
26 |
+ |
27 |
+ |
28 |
+module_spec = { |
29 |
+ 'name': 'do', |
30 |
+ 'description': doc, |
31 |
+ 'provides':{ |
32 |
+ 'header-check': { |
33 |
+ 'name': "gentooheader", |
34 |
+ 'sourcefile': "header", |
35 |
+ 'class': "EbuildHeader", |
36 |
+ 'description': doc, |
37 |
+ }, |
38 |
+ } |
39 |
+} |
40 |
+ |
41 |
|
42 |
diff --git a/repoman/pym/repoman/modules/linechecks/gentoo_header/header.py b/repoman/pym/repoman/modules/linechecks/gentoo_header/header.py |
43 |
new file mode 100644 |
44 |
index 000000000..4b75fc4b5 |
45 |
--- /dev/null |
46 |
+++ b/repoman/pym/repoman/modules/linechecks/gentoo_header/header.py |
47 |
@@ -0,0 +1,49 @@ |
48 |
+ |
49 |
+import re |
50 |
+import time |
51 |
+ |
52 |
+from repoman.modules.linechecks.base import LineCheck |
53 |
+ |
54 |
+ |
55 |
+class EbuildHeader(LineCheck): |
56 |
+ """Ensure ebuilds have proper headers |
57 |
+ Copyright header errors |
58 |
+ CVS header errors |
59 |
+ License header errors |
60 |
+ |
61 |
+ Args: |
62 |
+ modification_year - Year the ebuild was last modified |
63 |
+ """ |
64 |
+ |
65 |
+ repoman_check_name = 'ebuild.badheader' |
66 |
+ |
67 |
+ gentoo_copyright = r'^# Copyright ((1999|2\d\d\d)-)?%s Gentoo Foundation$' |
68 |
+ gentoo_license = ( |
69 |
+ '# Distributed under the terms' |
70 |
+ ' of the GNU General Public License v2') |
71 |
+ id_header_re = re.compile(r'.*\$(Id|Header)(:.*)?\$.*') |
72 |
+ blank_line_re = re.compile(r'^$') |
73 |
+ ignore_comment = False |
74 |
+ |
75 |
+ def new(self, pkg): |
76 |
+ if pkg.mtime is None: |
77 |
+ self.modification_year = r'2\d\d\d' |
78 |
+ else: |
79 |
+ self.modification_year = str(time.gmtime(pkg.mtime)[0]) |
80 |
+ self.gentoo_copyright_re = re.compile( |
81 |
+ self.gentoo_copyright % self.modification_year) |
82 |
+ |
83 |
+ def check(self, num, line): |
84 |
+ if num > 2: |
85 |
+ return |
86 |
+ elif num == 0: |
87 |
+ if not self.gentoo_copyright_re.match(line): |
88 |
+ return self.errors['COPYRIGHT_ERROR'] |
89 |
+ elif num == 1 and line.rstrip('\n') != self.gentoo_license: |
90 |
+ return self.errors['LICENSE_ERROR'] |
91 |
+ elif num == 2 and self.id_header_re.match(line): |
92 |
+ return self.errors['ID_HEADER_ERROR'] |
93 |
+ elif num == 2 and not self.blank_line_re.match(line): |
94 |
+ return self.errors['NO_BLANK_LINE_ERROR'] |
95 |
+ |
96 |
+ |