commit:     6df89d303139784089ebf5a6fecfc560a9f7ec1d
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  3 11:15:10 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Wed Oct  1 23:45:33 2014 +0000
URL:        
http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=6df89d30

repoman/main.py: Split USE flag checks to checks/ebuilds/use_flags.py

---
 pym/repoman/checks/ebuilds/misc.py      |  2 +-
 pym/repoman/checks/ebuilds/use_flags.py | 85 +++++++++++++++++++++++++++++++++
 pym/repoman/main.py                     | 52 ++++----------------
 3 files changed, 95 insertions(+), 44 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/misc.py 
b/pym/repoman/checks/ebuilds/misc.py
index 3bf61f0..744784a 100644
--- a/pym/repoman/checks/ebuilds/misc.py
+++ b/pym/repoman/checks/ebuilds/misc.py
@@ -39,7 +39,7 @@ def bad_split_check(xpkg, y_ebuild, pkgdir, qatracker):
        return False
 
 
-def pkg_invalid(pkg, qatracker):
+def pkg_invalid(pkg, qatracker, ebuild):
        '''Checks for invalid packages
 
        @param pkg: _emerge.Package instance

diff --git a/pym/repoman/checks/ebuilds/use_flags.py 
b/pym/repoman/checks/ebuilds/use_flags.py
new file mode 100644
index 0000000..bc09ed7
--- /dev/null
+++ b/pym/repoman/checks/ebuilds/use_flags.py
@@ -0,0 +1,85 @@
+
+'''use_flags.py
+Performs USE flag related checks
+'''
+
+# import our centrally initialized portage instance
+from repoman._portage import portage
+
+from portage import eapi
+from portage.eapi import eapi_has_iuse_defaults, eapi_has_required_use
+
+
+class USEFlagChecks(object):
+       '''Performs checks on USE flags listed in the ebuilds and 
metadata.xml'''
+
+       def __init__(self, qatracker, globalUseFlags):
+               '''
+               @param qatracker: QATracker instance
+               @param globalUseFlags: Global USE flags
+               '''
+               self.qatracker = qatracker
+               self.useFlags = []
+               self.defaultUseFlags = []
+               self.usedUseFlags = set()
+               self.globalUseFlags = globalUseFlags
+
+       def check(self, pkg, package, ebuild, y_ebuild, localUseFlags):
+               '''Perform the check.
+
+               @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 localUseFlags: Local USE flags of the package
+               '''
+               self._checkGlobal(pkg)
+               self._checkMetadata(package, ebuild, y_ebuild, localUseFlags)
+               self._checkRequiredUSE(pkg, ebuild)
+
+       def getUsedUseFlags(self):
+               '''Get the USE flags that this check has seen'''
+               return self.usedUseFlags
+
+       def _checkGlobal(self, pkg):
+               for myflag in pkg._metadata["IUSE"].split():
+                       flag_name = myflag.lstrip("+-")
+                       self.usedUseFlags.add(flag_name)
+                       if myflag != flag_name:
+                               self.defaultUseFlags.append(myflag)
+                       if flag_name not in self.globalUseFlags:
+                               self.useFlags.append(flag_name)
+
+       def _checkMetadata(self, package, ebuild, y_ebuild, localUseFlags):
+               for mypos in range(len(self.useFlags) - 1, -1, -1):
+                       if self.useFlags[mypos] and (self.useFlags[mypos] in 
localUseFlags):
+                               del self.useFlags[mypos]
+
+               if self.defaultUseFlags and not eapi_has_iuse_defaults(eapi):
+                       for myflag in self.defaultUseFlags:
+                               self.qatracker.add_error(
+                                       'EAPI.incompatible', "%s: IUSE defaults"
+                                       " not supported with EAPI='%s': '%s'" % 
(
+                                               ebuild.relative_path, eapi, 
myflag))
+
+               for mypos in range(len(self.useFlags)):
+                       self.qatracker.add_error(
+                               "IUSE.invalid",
+                               "%s/%s.ebuild: %s" % (package, y_ebuild, 
self.useFlags[mypos]))
+
+       def _checkRequiredUSE(self, pkg, ebuild):
+               required_use = pkg._metadata["REQUIRED_USE"]
+               if required_use:
+                       if not eapi_has_required_use(eapi):
+                               self.qatracker.add_error(
+                                       'EAPI.incompatible', "%s: REQUIRED_USE"
+                                       " not supported with EAPI='%s'"
+                                       % (ebuild.relative_path, eapi,))
+                       try:
+                               portage.dep.check_required_use(
+                                       required_use, (), 
pkg.iuse.is_valid_flag, eapi=eapi)
+                       except portage.exception.InvalidDependString as e:
+                               self.qatracker.add_error(
+                                       "REQUIRED_USE.syntax",
+                                       "%s: REQUIRED_USE: %s" % 
(ebuild.relative_path, e))
+                               del e

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index fcd4c19..5f21e7a 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -44,7 +44,6 @@ from portage.output import (
 from portage.output import ConsoleStyleFile, StyleWriter
 from portage.util import writemsg_level
 from portage.package.ebuild.digestgen import digestgen
-from portage.eapi import eapi_has_iuse_defaults, eapi_has_required_use
 
 from repoman.argparser import parse_args
 from repoman.checks.directories.files import FileChecks
@@ -55,6 +54,7 @@ from repoman.checks.ebuilds.thirdpartymirrors import 
ThirdPartyMirrors
 from repoman.checks.ebuilds.manifests import Manifests
 from repoman.checks.ebuilds.misc import bad_split_check, pkg_invalid
 from repoman.checks.ebuilds.pkgmetadata import PkgMetadata
+from repoman.checks.ebuilds.use_flags import USEFlagChecks
 from repoman.ebuild import Ebuild
 from repoman.errors import err
 from repoman.modules.commit import repochecks
@@ -367,7 +367,7 @@ for xpkg in effective_scanlist:
                        continue
 ###################
                pkg = pkgs[y_ebuild]
-               if pkg_invalid(pkg, qatracker):
+               if pkg_invalid(pkg, qatracker, ebuild):
                        allvalid = False
                        continue
 
@@ -626,32 +626,13 @@ for xpkg in effective_scanlist:
                badlicsyntax = badlicsyntax > 0
                badprovsyntax = badprovsyntax > 0
 
-               # uselist checks - global
-               myuse = []
-               default_use = []
-               for myflag in myaux["IUSE"].split():
-                       flag_name = myflag.lstrip("+-")
-                       used_useflags.add(flag_name)
-                       if myflag != flag_name:
-                               default_use.append(myflag)
-                       if flag_name not in uselist:
-                               myuse.append(flag_name)
-
-               # uselist checks - metadata
-               for mypos in range(len(myuse) - 1, -1, -1):
-                       if myuse[mypos] and (myuse[mypos] in muselist):
-                               del myuse[mypos]
-
-               if default_use and not eapi_has_iuse_defaults(eapi):
-                       for myflag in default_use:
-                               qatracker.add_error('EAPI.incompatible',
-                                       "%s: IUSE defaults"
-                                       " not supported with EAPI='%s': '%s'" %
-                                       (ebuild.relative_path, eapi, myflag))
-
-               for mypos in range(len(myuse)):
-                       qatracker.add_error("IUSE.invalid",
-                               xpkg + "/" + y_ebuild + ".ebuild: %s" % 
myuse[mypos])
+               #################
+               use_flag_checks = USEFlagChecks(qatracker, uselist)
+               use_flag_checks.check(pkg, xpkg, ebuild, y_ebuild, muselist)
+
+               ebuild_used_useflags = use_flag_checks.getUsedUseFlags()
+               used_useflags = used_useflags.union(ebuild_used_useflags)
+               #################
 
                # Check for outdated RUBY targets
                old_ruby_eclasses = ["ruby-ng", "ruby-fakegem", "ruby"]
@@ -715,21 +696,6 @@ for xpkg in effective_scanlist:
                                for mybad in mybadrestrict:
                                        qatracker.add_error("RESTRICT.invalid",
                                                xpkg + "/" + y_ebuild + 
".ebuild: %s" % mybad)
-               # REQUIRED_USE check
-               required_use = myaux["REQUIRED_USE"]
-               if required_use:
-                       if not eapi_has_required_use(eapi):
-                               qatracker.add_error('EAPI.incompatible',
-                                       "%s: REQUIRED_USE"
-                                       " not supported with EAPI='%s'"
-                                       % (ebuild.relative_path, eapi,))
-                       try:
-                               portage.dep.check_required_use(
-                                       required_use, (), 
pkg.iuse.is_valid_flag, eapi=eapi)
-                       except portage.exception.InvalidDependString as e:
-                               qatracker.add_error("REQUIRED_USE.syntax",
-                                       "%s: REQUIRED_USE: %s" % 
(ebuild.relative_path, e))
-                               del e
 
                # Syntax Checks
 

Reply via email to