aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBrian Dolbec <dolsen@gentoo.org>2017-07-15 01:01:04 +0000
committerZac Medico <zmedico@gentoo.org>2018-03-29 20:51:17 -0700
commitdf1266a0fb757057658e5bea56a003ca0e5d5d7f (patch)
treebc2c325682d84cfd220dee89c5c3e4cd504232e7
parentrepoman: New linechecks module, emake (diff)
downloadportage-df1266a0fb757057658e5bea56a003ca0e5d5d7f.tar.gz
portage-df1266a0fb757057658e5bea56a003ca0e5d5d7f.tar.bz2
portage-df1266a0fb757057658e5bea56a003ca0e5d5d7f.zip
repoman: New linechecks module, gentoo_header
-rw-r--r--repoman/pym/repoman/modules/linechecks/gentoo_header/__init__.py21
-rw-r--r--repoman/pym/repoman/modules/linechecks/gentoo_header/header.py49
2 files changed, 70 insertions, 0 deletions
diff --git a/repoman/pym/repoman/modules/linechecks/gentoo_header/__init__.py b/repoman/pym/repoman/modules/linechecks/gentoo_header/__init__.py
new file mode 100644
index 000000000..b80a83ecf
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/gentoo_header/__init__.py
@@ -0,0 +1,21 @@
+# Copyright 2015-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """Gentoo-header plug-in module for repoman LineChecks.
+Performs header checks on ebuilds."""
+__doc__ = doc[:]
+
+
+module_spec = {
+ 'name': 'do',
+ 'description': doc,
+ 'provides':{
+ 'header-check': {
+ 'name': "gentooheader",
+ 'sourcefile': "header",
+ 'class': "EbuildHeader",
+ 'description': doc,
+ },
+ }
+}
+
diff --git a/repoman/pym/repoman/modules/linechecks/gentoo_header/header.py b/repoman/pym/repoman/modules/linechecks/gentoo_header/header.py
new file mode 100644
index 000000000..4b75fc4b5
--- /dev/null
+++ b/repoman/pym/repoman/modules/linechecks/gentoo_header/header.py
@@ -0,0 +1,49 @@
+
+import re
+import time
+
+from repoman.modules.linechecks.base import LineCheck
+
+
+class EbuildHeader(LineCheck):
+ """Ensure ebuilds have proper headers
+ Copyright header errors
+ CVS header errors
+ License header errors
+
+ Args:
+ modification_year - Year the ebuild was last modified
+ """
+
+ repoman_check_name = 'ebuild.badheader'
+
+ gentoo_copyright = r'^# Copyright ((1999|2\d\d\d)-)?%s Gentoo Foundation$'
+ 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'
+ else:
+ self.modification_year = str(time.gmtime(pkg.mtime)[0])
+ self.gentoo_copyright_re = re.compile(
+ self.gentoo_copyright % self.modification_year)
+
+ def check(self, num, line):
+ if num > 2:
+ return
+ elif num == 0:
+ if not self.gentoo_copyright_re.match(line):
+ 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']
+
+