commit:     6d0d5f4507fa95bd357e9119aef802c95fc48324
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Fri Jan  8 08:15:22 2016 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Mon Jan 18 19:20:03 2016 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=6d0d5f45

repoman: Create LiveEclassChecks class plugin

 pym/repoman/checks/ebuilds/eclasses/live.py   | 39 --------------
 pym/repoman/modules/scan/eclasses/__init__.py | 23 ++++++++
 pym/repoman/modules/scan/eclasses/live.py     | 75 +++++++++++++++++++++++++++
 pym/repoman/repos.py                          | 10 ----
 pym/repoman/scanner.py                        | 12 ++---
 5 files changed, 102 insertions(+), 57 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/eclasses/live.py 
b/pym/repoman/checks/ebuilds/eclasses/live.py
deleted file mode 100644
index bf14cff..0000000
--- a/pym/repoman/checks/ebuilds/eclasses/live.py
+++ /dev/null
@@ -1,39 +0,0 @@
-
-'''live.py
-Performs Live eclass checks
-'''
-
-from repoman.repos import has_global_mask
-
-
-class LiveEclassChecks(object):
-       '''Performs checks for the usage of Live eclasses in ebuilds'''
-
-       def __init__(self, qatracker):
-               '''
-               @param qatracker: QATracker instance
-               '''
-               self.qatracker = qatracker
-
-       def check(self, pkg, package, ebuild, y_ebuild, keywords, 
global_pmaskdict):
-               '''Ebuilds that inherit a "Live" eclass (darcs, subversion, 
git, cvs,
-               etc..) should not be allowed to be marked stable
-
-               @param pkg: Package in which we check (object).
-               @param package: Package in which we check (string).
-               @param ebuild: Ebuild which we check (object).
-               @param y_ebuild: Ebuild which we check (string).
-               @param keywords: The keywords of the ebuild.
-               @param global_pmaskdict: A global dictionary of all the masks.
-               '''
-               is_stable = lambda kw: not kw.startswith("~") and not 
kw.startswith("-")
-               bad_stable_keywords = list(filter(is_stable, keywords))
-
-               if bad_stable_keywords:
-                       self.qatracker.add_error(
-                               "LIVEVCS.stable", "%s/%s.ebuild with stable 
keywords:%s " % (
-                                       package, y_ebuild, bad_stable_keywords))
-
-               good_keywords_exist = len(bad_stable_keywords) < len(keywords)
-               if good_keywords_exist and not has_global_mask(pkg, 
global_pmaskdict):
-                       self.qatracker.add_error("LIVEVCS.unmasked", 
ebuild.relative_path)

diff --git a/pym/repoman/modules/scan/eclasses/__init__.py 
b/pym/repoman/modules/scan/eclasses/__init__.py
new file mode 100644
index 0000000..a821f5c
--- /dev/null
+++ b/pym/repoman/modules/scan/eclasses/__init__.py
@@ -0,0 +1,23 @@
+# Copyright 2015-2016 Gentoo Foundation
+# Distributed under the terms of the GNU General Public License v2
+
+doc = """Eclasses plug-in module for repoman.
+Performs an live and ruby eclass checks on ebuilds."""
+__doc__ = doc[:]
+
+
+module_spec = {
+       'name': 'eclasses',
+       'description': doc,
+       'provides':{
+               'live-module': {
+                       'name': "live",
+                       'class': "LiveEclassChecks",
+                       'description': doc,
+                       'functions': ['check'],
+                       'func_kwargs': {
+                       },
+               },
+       }
+}
+

diff --git a/pym/repoman/modules/scan/eclasses/live.py 
b/pym/repoman/modules/scan/eclasses/live.py
new file mode 100644
index 0000000..3216dd1
--- /dev/null
+++ b/pym/repoman/modules/scan/eclasses/live.py
@@ -0,0 +1,75 @@
+
+'''live.py
+Performs Live eclass checks
+'''
+
+from repoman._portage import portage
+from portage.const import LIVE_ECLASSES
+
+class LiveEclassChecks(object):
+       '''Performs checks for the usage of Live eclasses in ebuilds'''
+
+       def __init__(self, **kwargs):
+               '''
+               @param qatracker: QATracker instance
+               '''
+               self.qatracker = kwargs.get('qatracker')
+               self.pmaskdict = kwargs.get('repo_metadata')['pmaskdict']
+               self.repo_settings = kwargs.get('repo_settings')
+
+       def is_live(self, **kwargs):
+               return {'continue': False,
+                       'live_ebuild': LIVE_ECLASSES.intersection(
+                               kwargs.get('ebuild').inherited)}
+
+       def check(self, **kwargs):
+               '''Ebuilds that inherit a "Live" eclass (darcs, subversion, 
git, cvs,
+               etc..) should not be allowed to be marked stable
+
+               @param pkg: Package in which we check (object).
+               @param package: Package in which we check (string).
+               @param ebuild: Ebuild which we check (object).
+               @param y_ebuild: Ebuild which we check (string).
+               @param keywords: The keywords of the ebuild.
+               @param global_pmaskdict: A global dictionary of all the masks.
+               '''
+               pkg = kwargs.get("pkg")
+               package = kwargs.get('xpkg')
+               ebuild = kwargs.get('ebuild')
+               y_ebuild = kwargs.get('y_ebuild')
+               keywords = ebuild.keywords
+
+               if not (kwargs.get('live_ebuild') and
+                               self.repo_settings.repo_config.name == 
"gentoo"):
+                       return {'continue': False}
+
+               is_stable = lambda kw: not kw.startswith("~") and not 
kw.startswith("-")
+               bad_stable_keywords = list(filter(is_stable, keywords))
+
+               if bad_stable_keywords:
+                       self.qatracker.add_error(
+                               "LIVEVCS.stable", "%s/%s.ebuild with stable 
keywords:%s " % (
+                                       package, y_ebuild, bad_stable_keywords))
+
+               good_keywords_exist = len(bad_stable_keywords) < len(keywords)
+               if good_keywords_exist and not self._has_global_mask(pkg, 
self.pmaskdict):
+                       self.qatracker.add_error("LIVEVCS.unmasked", 
ebuild.relative_path)
+               return {'continue': False}
+
+       @staticmethod
+       def _has_global_mask(pkg, global_pmaskdict):
+               mask_atoms = global_pmaskdict.get(pkg.cp)
+               if mask_atoms:
+                       pkg_list = [pkg]
+                       for x in mask_atoms:
+                               if portage.dep.match_from_list(x, pkg_list):
+                                       return x
+               return None
+
+       @property
+       def runInPkgs(self):
+               return (False, [])
+
+       @property
+       def runInEbuilds(self):
+               return (True, [self.is_live, self.check])

diff --git a/pym/repoman/repos.py b/pym/repoman/repos.py
index ca72ac5..a34f785 100644
--- a/pym/repoman/repos.py
+++ b/pym/repoman/repos.py
@@ -295,13 +295,3 @@ def repo_metadata(portdb, repoman_settings):
        return (
                kwlist, liclist, uselist, profile_list, global_pmaskdict,
                list_checks(kwlist, liclist, uselist, repoman_settings))
-
-
-def has_global_mask(pkg, global_pmaskdict):
-       mask_atoms = global_pmaskdict.get(pkg.cp)
-       if mask_atoms:
-               pkg_list = [pkg]
-               for x in mask_atoms:
-                       if portage.dep.match_from_list(x, pkg_list):
-                               return x
-       return None

diff --git a/pym/repoman/scanner.py b/pym/repoman/scanner.py
index 592713c..e5c185b 100644
--- a/pym/repoman/scanner.py
+++ b/pym/repoman/scanner.py
@@ -20,7 +20,6 @@ from portage import _unicode_encode
 from portage.dep import Atom
 from portage.output import green
 from repoman.checks.ebuilds.checks import run_checks
-from repoman.checks.ebuilds.eclasses.live import LiveEclassChecks
 from repoman.checks.ebuilds.eclasses.ruby import RubyEclassChecks
 from repoman.checks.ebuilds.thirdpartymirrors import ThirdPartyMirrors
 from repoman.check_missingslot import check_missingslot
@@ -206,8 +205,6 @@ class Scanner(object):
                                chain(self.changed.changed, self.changed.new, 
self.changed.removed),
                                self.repolevel, self.reposplit, 
self.categories))
 
-               self.live_eclasses = portage.const.LIVE_ECLASSES
-
                # Create our kwargs dict here to initialize the plugins with
                self.kwargs = {
                        "repo_settings": self.repo_settings,
@@ -218,6 +215,7 @@ class Scanner(object):
                        "metadata_dtd": metadata_dtd,
                        "uselist": uselist,
                        "checks": self.checks,
+                       "repo_metadata": self.repo_metadata,
                }
                # initialize the plugin checks here
                self.modules = {}
@@ -230,7 +228,6 @@ class Scanner(object):
                # initialize our checks classes here before the big xpkg loop
                self.thirdparty = 
ThirdPartyMirrors(self.repo_settings.repoman_settings, self.qatracker)
                self.use_flag_checks = USEFlagChecks(self.qatracker, uselist)
-               self.liveeclasscheck = LiveEclassChecks(self.qatracker)
                self.rubyeclasscheck = RubyEclassChecks(self.qatracker)
                self.eapicheck = EAPIChecks(self.qatracker, self.repo_settings)
                self.descriptioncheck = DescriptionChecks(self.qatracker)
@@ -315,7 +312,7 @@ class Scanner(object):
 
                        # initialize per ebuild plugin checks here
                        # need to set it up for ==> self.modules_list or some 
other ordered list
-                       for mod in [('ebuild', 'Ebuild')]:
+                       for mod in [('ebuild', 'Ebuild'), ('live', 
'LiveEclassChecks')]:
                                if mod[0]:
                                        mod_class = 
MODULE_CONTROLLER.get_class(mod[0])
                                        logging.debug("Initializing class name: 
%s", mod_class.__name__)
@@ -342,7 +339,6 @@ class Scanner(object):
                        if y_ebuild_continue:
                                continue
 
-
                        self.eapicheck.check(dynamic_data['pkg'], 
dynamic_data['ebuild'])
 
                        for k, v in dynamic_data['ebuild'].metadata.items():
@@ -367,7 +363,7 @@ class Scanner(object):
                                        if dynamic_data['catdir'] == "virtual" 
and \
                                                missing_var in ("HOMEPAGE", 
"LICENSE"):
                                                continue
-                                       if live_ebuild and missing_var == 
"KEYWORDS":
+                                       if dynamic_data['live_ebuild'] and 
missing_var == "KEYWORDS":
                                                continue
                                        myqakey = missingvars[pos] + ".missing"
                                        self.qatracker.add_error(myqakey, xpkg 
+ "/" + y_ebuild + ".ebuild")
@@ -380,7 +376,7 @@ class Scanner(object):
 
                        self.descriptioncheck.check(dynamic_data['pkg'], 
dynamic_data['ebuild'])
 
-                       if live_ebuild and self.repo_settings.repo_config.name 
== "gentoo":
+                       if dynamic_data['live_ebuild'] and 
self.repo_settings.repo_config.name == "gentoo":
                                self.liveeclasscheck.check(
                                        dynamic_data['pkg'], xpkg, 
dynamic_data['ebuild'], y_ebuild, dynamic_data['ebuild'].keywords, 
self.repo_metadata['pmaskdict'])
 

Reply via email to