public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-05-30 13:03 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2014-05-30 13:03 UTC (permalink / raw
  To: gentoo-commits

commit:     c74159c33da8945c45b98974274d3db17b882b44
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Tue May 27 17:33:12 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Tue May 27 17:47:48 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=c74159c3

repoman/main.py: Create checks/ebuilds/manifests.py and Manifests class

This moves manifest checks and creation to it's own class

---
 pym/repoman/checks/ebuilds/manifests.py | 91 +++++++++++++++++++++++++++++++++
 pym/repoman/main.py                     | 76 +++------------------------
 2 files changed, 99 insertions(+), 68 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/manifests.py b/pym/repoman/checks/ebuilds/manifests.py
new file mode 100644
index 0000000..53c3136
--- /dev/null
+++ b/pym/repoman/checks/ebuilds/manifests.py
@@ -0,0 +1,91 @@
+
+import logging
+import sys
+
+import portage
+from portage import os
+from portage.package.ebuild.digestgen import digestgen
+from portage.util import writemsg_level
+
+
+class Manifests(object):
+
+
+	def __init__(self, options, repoman_settings):
+		self.options = options
+		self.repoman_settings = repoman_settings
+
+		self.digest_only = options.mode != 'manifest-check' and options.digest == 'y'
+		self.generated_manifest = False
+
+
+	def run(self, checkdir, portdb):
+		if self.options.pretend:
+			return False
+		if self.options.mode in ("manifest", 'commit', 'fix') or self.digest_only:
+			failed = False
+			self.auto_assumed = set()
+			fetchlist_dict = portage.FetchlistDict(
+				checkdir, self.repoman_settings, portdb)
+			if self.options.mode == 'manifest' and self.options.force:
+				portage._doebuild_manifest_exempt_depend += 1
+				self.create_manifest(checkdir, fetchlist_dict)
+			self.repoman_settings["O"] = checkdir
+			try:
+				self.generated_manifest = digestgen(
+					mysettings=self.repoman_settings, myportdb=portdb)
+			except portage.exception.PermissionDenied as e:
+				self.generated_manifest = False
+				writemsg_level(
+					"!!! Permission denied: '%s'\n" % (e,),
+					level=logging.ERROR, noiselevel=-1)
+
+			if not self.generated_manifest:
+				print("Unable to generate manifest.")
+				failed = True
+
+			if self.options.mode == "manifest":
+				if not failed and self.options.force and self.auto_assumed and \
+					'assume-digests' in self.repoman_settings.features:
+					# Show which digests were assumed despite the --force option
+					# being given. This output will already have been shown by
+					# digestgen() if assume-digests is not enabled, so only show
+					# it here if assume-digests is enabled.
+					pkgs = list(fetchlist_dict)
+					pkgs.sort()
+					portage.writemsg_stdout(
+						"  digest.assumed %s" %
+						portage.output.colorize(
+							"WARN", str(len(self.auto_assumed)).rjust(18)) + "\n")
+					for cpv in pkgs:
+						fetchmap = fetchlist_dict[cpv]
+						pf = portage.catsplit(cpv)[1]
+						for distfile in sorted(fetchmap):
+							if distfile in self.auto_assumed:
+								portage.writemsg_stdout(
+									"   %s::%s\n" % (pf, distfile))
+
+				return True  # continue, skip remaining loop code
+			elif failed:
+				sys.exit(1)
+		return False  # stay in the loop
+
+
+	def create_manifest(self, checkdir, fetchlist_dict):
+		try:
+			distdir = self.repoman_settings['DISTDIR']
+			mf = self.repoman_settings.repositories.get_repo_for_location(
+				os.path.dirname(os.path.dirname(checkdir)))
+			mf = mf.load_manifest(
+				checkdir, distdir, fetchlist_dict=fetchlist_dict)
+			mf.create(
+				requiredDistfiles=None, assumeDistHashesAlways=True)
+			for distfiles in fetchlist_dict.values():
+				for distfile in distfiles:
+					if os.path.isfile(os.path.join(distdir, distfile)):
+						mf.fhashdict['DIST'].pop(distfile, None)
+					else:
+						self.auto_assumed.add(distfile)
+			mf.write()
+		finally:
+			portage._doebuild_manifest_exempt_depend -= 1

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index 9e2ba76..46cdefd 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -66,6 +66,7 @@ from portage.eapi import eapi_has_iuse_defaults, eapi_has_required_use
 from repoman.argparser import parse_args
 from repoman.checks.ebuilds.checks import run_checks, checks_init
 from repoman.checks.ebuilds.thirdpartymirrors import ThirdPartyMirrors
+from repoman.checks.ebuilds.manifests import Manifests
 from repoman.checks.herds.herdbase import make_herd_base
 from repoman.ebuild import Ebuild
 from repoman.errors import err
@@ -334,76 +335,15 @@ for x in effective_scanlist:
 	if repolevel < 2:
 		checkdir_relative = os.path.join(catdir, checkdir_relative)
 	checkdir_relative = os.path.join(".", checkdir_relative)
-	generated_manifest = False
-
-	do_manifest = options.mode == "manifest"
-	do_digest_only = options.mode != 'manifest-check' and options.digest == 'y'
-	do_commit_or_fix = options.mode in ('commit', 'fix')
-	do_something = not options.pretend
-
-	if do_manifest or do_digest_only or do_commit_or_fix and do_something:
-		auto_assumed = set()
-		fetchlist_dict = portage.FetchlistDict(
-			checkdir, repoman_settings, portdb)
-		if options.mode == 'manifest' and options.force:
-			portage._doebuild_manifest_exempt_depend += 1
-			try:
-				distdir = repoman_settings['DISTDIR']
-				mf = repoman_settings.repositories.get_repo_for_location(
-					os.path.dirname(os.path.dirname(checkdir)))
-				mf = mf.load_manifest(
-					checkdir, distdir, fetchlist_dict=fetchlist_dict)
-				mf.create(
-					requiredDistfiles=None, assumeDistHashesAlways=True)
-				for distfiles in fetchlist_dict.values():
-					for distfile in distfiles:
-						if os.path.isfile(os.path.join(distdir, distfile)):
-							mf.fhashdict['DIST'].pop(distfile, None)
-						else:
-							auto_assumed.add(distfile)
-				mf.write()
-			finally:
-				portage._doebuild_manifest_exempt_depend -= 1
 
-		repoman_settings["O"] = checkdir
-		try:
-			generated_manifest = digestgen(
-				mysettings=repoman_settings, myportdb=portdb)
-		except portage.exception.PermissionDenied as e:
-			generated_manifest = False
-			writemsg_level(
-				"!!! Permission denied: '%s'\n" % (e,),
-				level=logging.ERROR, noiselevel=-1)
-
-		if not generated_manifest:
-			print("Unable to generate manifest.")
-			dofail = 1
-
-		if options.mode == "manifest":
-			if not dofail and options.force and auto_assumed and \
-				'assume-digests' in repoman_settings.features:
-				# Show which digests were assumed despite the --force option
-				# being given. This output will already have been shown by
-				# digestgen() if assume-digests is not enabled, so only show
-				# it here if assume-digests is enabled.
-				pkgs = list(fetchlist_dict)
-				pkgs.sort()
-				portage.writemsg_stdout(
-					"  digest.assumed %s" %
-					portage.output.colorize(
-						"WARN", str(len(auto_assumed)).rjust(18)) + "\n")
-				for cpv in pkgs:
-					fetchmap = fetchlist_dict[cpv]
-					pf = portage.catsplit(cpv)[1]
-					for distfile in sorted(fetchmap):
-						if distfile in auto_assumed:
-							portage.writemsg_stdout(
-								"   %s::%s\n" % (pf, distfile))
-			continue
-		elif dofail:
-			sys.exit(1)
+#####################
+	manifester = Manifests(options, repoman_settings)
+	skip = manifester.run(checkdir, portdb)
+	if skip:
+		continue
+######################
 
-	if not generated_manifest:
+	if not manifester.generated_manifest:
 		repoman_settings['O'] = checkdir
 		repoman_settings['PORTAGE_QUIET'] = '1'
 		if not portage.digestcheck([], repoman_settings, strict=1):


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-05-30 13:03 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2014-05-30 13:03 UTC (permalink / raw
  To: gentoo-commits

commit:     750404bb3e8ab5bccdf9d653e8587610fd034e89
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Tue May 27 07:13:32 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Tue May 27 07:13:32 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=750404bb

repoman/main.py: Break out a new ebuild check, ThirdPartyMirrors

Consolodate the code from 2 locations into one class.

---
 pym/repoman/checks/ebuilds/thirdpartymirrors.py | 40 +++++++++++++++++++++++++
 pym/repoman/main.py                             | 32 +++++---------------
 2 files changed, 47 insertions(+), 25 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/thirdpartymirrors.py b/pym/repoman/checks/ebuilds/thirdpartymirrors.py
new file mode 100644
index 0000000..976a62c
--- /dev/null
+++ b/pym/repoman/checks/ebuilds/thirdpartymirrors.py
@@ -0,0 +1,40 @@
+
+import portage
+
+
+class ThirdPartyMirrors(object):
+
+	def __init__(self, repoman_settings):
+		# Build a regex from thirdpartymirrors for the SRC_URI.mirror check.
+		self.thirdpartymirrors = {}
+		for k, v in repoman_settings.thirdpartymirrors().items():
+			for v in v:
+				if not v.endswith("/"):
+					v += "/"
+		self.thirdpartymirrors[v] = k
+		self.stats = 0
+		self.fails = []
+
+
+	def check(self, myaux, relative_path):
+		# reset our stats in case this is a repeat run
+		self.stats = 0
+		self.fails = []
+		# Check that URIs don't reference a server from thirdpartymirrors.
+		for uri in portage.dep.use_reduce(
+			myaux["SRC_URI"], matchall=True, is_src_uri=True,
+			eapi=myaux["EAPI"], flat=True):
+			contains_mirror = False
+			for mirror, mirror_alias in self.thirdpartymirrors.items():
+				if uri.startswith(mirror):
+					contains_mirror = True
+					break
+			if not contains_mirror:
+				continue
+
+			new_uri = "mirror://%s/%s" % (mirror_alias, uri[len(mirror):])
+			self.stats += 1
+			self.fails.append(
+				"%s: '%s' found in thirdpartymirrors, use '%s'" %
+				(relative_path, mirror, new_uri))
+		return

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index 49ad79d..158323e 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -65,6 +65,7 @@ from portage.eapi import eapi_has_iuse_defaults, eapi_has_required_use
 
 from repoman.argparser import parse_args
 from repoman.checks.ebuilds.checks import run_checks, checks_init
+from repoman.checks.ebuilds.thirdpartymirrors import ThirdPartyMirrors
 from repoman.checks.herds.herdbase import make_herd_base
 from repoman.errors import err
 from repoman.metadata import (metadata_xml_encoding, metadata_doctype_name,
@@ -303,14 +304,6 @@ if options.include_arches:
 check_ebuild_notadded = not \
 	(vcs_settings.vcs == "svn" and repolevel < 3 and options.mode != "commit")
 
-# Build a regex from thirdpartymirrors for the SRC_URI.mirror check.
-thirdpartymirrors = {}
-for k, v in repoman_settings.thirdpartymirrors().items():
-	for v in v:
-		if not v.endswith("/"):
-			v += "/"
-		thirdpartymirrors[v] = k
-
 try:
 	herd_base = make_herd_base(
 		os.path.join(repoman_settings["PORTDIR"], "metadata/herds.xml"))
@@ -887,23 +880,12 @@ for x in effective_scanlist:
 					(relative_path, k, m.start() + 1))
 
 		if not src_uri_error:
-			# Check that URIs don't reference a server from thirdpartymirrors.
-			for uri in portage.dep.use_reduce(
-				myaux["SRC_URI"], matchall=True, is_src_uri=True, eapi=eapi, flat=True):
-				contains_mirror = False
-				for mirror, mirror_alias in thirdpartymirrors.items():
-					if uri.startswith(mirror):
-						contains_mirror = True
-						break
-				if not contains_mirror:
-					continue
-
-				new_uri = "mirror://%s/%s" % (mirror_alias, uri[len(mirror):])
-				stats["SRC_URI.mirror"] += 1
-				fails["SRC_URI.mirror"].append(
-					"%s: '%s' found in thirdpartymirrors, use '%s'" %
-					(relative_path, mirror, new_uri))
-
+			#######################
+			thirdparty = ThirdPartyMirrors(repoman_settings)
+			thirdparty.check(myaux, relative_path)
+			stats["SRC_URI.mirror"] = thirdparty.stats
+			fails["SRC_URI.mirror"] = thirdparty.fails
+			#######################
 		if myaux.get("PROVIDE"):
 			stats["virtual.oldstyle"] += 1
 			fails["virtual.oldstyle"].append(relative_path)


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-06-02  1:10 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2014-06-02  1:10 UTC (permalink / raw
  To: gentoo-commits

commit:     7b48d08d50a9da5514190abc3c70a30372bd7c5d
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Jun  2 01:00:05 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Mon Jun  2 01:00:05 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=7b48d08d

repoman/main.py: Create IsEbuild class and check

Split the code from main.py into checks/ebuilds/isebuild.py.

---
 pym/repoman/checks/ebuilds/isebuild.py | 70 ++++++++++++++++++++++++++++++++++
 pym/repoman/main.py                    | 50 +++++-------------------
 2 files changed, 79 insertions(+), 41 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/isebuild.py b/pym/repoman/checks/ebuilds/isebuild.py
new file mode 100644
index 0000000..2369ea6
--- /dev/null
+++ b/pym/repoman/checks/ebuilds/isebuild.py
@@ -0,0 +1,70 @@
+
+import stat
+
+from _emerge.Package import Package
+from _emerge.RootConfig import RootConfig
+
+import portage
+from portage import os
+
+from repoman.qa_data import no_exec, allvars
+
+
+class IsEbuild(object):
+
+
+	def __init__(self, repoman_settings, repo_settings, portdb, qatracker):
+		''''''
+		self.portdb = portdb
+		self.qatracker = qatracker
+		self.root_config = RootConfig(repoman_settings,
+			repo_settings.trees[repo_settings.root], None)
+
+
+	def check(self, checkdirlist, checkdir, xpkg):
+		self.continue_ = False
+		ebuildlist = []
+		pkgs = {}
+		allvalid = True
+		for y in checkdirlist:
+			file_is_ebuild = y.endswith(".ebuild")
+			file_should_be_non_executable = y in no_exec or file_is_ebuild
+
+			if file_should_be_non_executable:
+				file_is_executable = stat.S_IMODE(
+					os.stat(os.path.join(checkdir, y)).st_mode) & 0o111
+
+				if file_is_executable:
+					self.qatracker.add_error("file.executable", os.path.join(checkdir, y))
+			if file_is_ebuild:
+				pf = y[:-7]
+				ebuildlist.append(pf)
+				catdir = xpkg.split("/")[0]
+				cpv = "%s/%s" % (catdir, pf)
+				try:
+					myaux = dict(zip(allvars, self.portdb.aux_get(cpv, allvars)))
+				except KeyError:
+					allvalid = False
+					self.qatracker.add_error("ebuild.syntax", os.path.join(xpkg, y))
+					continue
+				except IOError:
+					allvalid = False
+					self.qatracker.add_error("ebuild.output", os.path.join(xpkg, y))
+					continue
+				if not portage.eapi_is_supported(myaux["EAPI"]):
+					allvalid = False
+					self.qatracker.add_error("EAPI.unsupported", os.path.join(xpkg, y))
+					continue
+				pkgs[pf] = Package(
+					cpv=cpv, metadata=myaux, root_config=self.root_config,
+					type_name="ebuild")
+
+		if len(pkgs) != len(ebuildlist):
+			# If we can't access all the metadata then it's totally unsafe to
+			# commit since there's no way to generate a correct Manifest.
+			# Do not try to do any more QA checks on this package since missing
+			# metadata leads to false positives for several checks, and false
+			# positives confuse users.
+			self.continue_ = True
+
+		return pkgs, allvalid

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index 3a1ff7a..6a7ada7 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -11,7 +11,6 @@ import io
 import logging
 import re
 import signal
-import stat
 import subprocess
 import sys
 import tempfile
@@ -45,7 +44,6 @@ from portage import os
 from portage import _encodings
 from portage import _unicode_encode
 from _emerge.Package import Package
-from _emerge.RootConfig import RootConfig
 from _emerge.userquery import userquery
 import portage.checksum
 import portage.const
@@ -65,6 +63,7 @@ from portage.eapi import eapi_has_iuse_defaults, eapi_has_required_use
 
 from repoman.argparser import parse_args
 from repoman.checks.ebuilds.checks import run_checks, checks_init
+from repoman.checks.ebuilds.isebuild import IsEbuild
 from repoman.checks.ebuilds.thirdpartymirrors import ThirdPartyMirrors
 from repoman.checks.ebuilds.manifests import Manifests
 from repoman.checks.herds.herdbase import make_herd_base
@@ -75,7 +74,7 @@ from repoman.metadata import (metadata_xml_encoding, metadata_doctype_name,
 from repoman.modules import commit
 from repoman.profile import check_profiles, dev_keywords, setup_profile
 from repoman.qa_data import (format_qa_output, format_qa_output_column, qahelp,
-	qawarnings, qacats, no_exec, allvars, max_desc_len, missingvars,
+	qawarnings, qacats, max_desc_len, missingvars,
 	ruby_deprecated, suspect_virtual, suspect_rdepend, valid_restrict)
 from qa_tracker import QATracker
 from repoman.repos import has_global_mask, RepoSettings, repo_metadata
@@ -206,7 +205,6 @@ repoman_settings.categories = frozenset(
 categories = repoman_settings.categories
 
 portdb.settings = repoman_settings
-root_config = RootConfig(repoman_settings, repo_settings.trees[repo_settings.root], None)
 # We really only need to cache the metadata that's necessary for visibility
 # filtering. Anything else can be discarded to reduce memory consumption.
 portdb._aux_cache_keys.clear()
@@ -351,44 +349,11 @@ for xpkg in effective_scanlist:
 		continue
 
 	checkdirlist = os.listdir(checkdir)
-	ebuildlist = []
-	pkgs = {}
-	allvalid = True
-	for y in checkdirlist:
-		file_is_ebuild = y.endswith(".ebuild")
-		file_should_be_non_executable = y in no_exec or file_is_ebuild
-
-		if file_should_be_non_executable:
-			file_is_executable = stat.S_IMODE(
-				os.stat(os.path.join(checkdir, y)).st_mode) & 0o111
-
-			if file_is_executable:
-				qatracker.add_error("file.executable", os.path.join(checkdir, y))
-		if file_is_ebuild:
-			pf = y[:-7]
-			ebuildlist.append(pf)
-			cpv = "%s/%s" % (catdir, pf)
-			try:
-				myaux = dict(zip(allvars, portdb.aux_get(cpv, allvars)))
-			except KeyError:
-				allvalid = False
-				qatracker.add_error("ebuild.syntax", os.path.join(xpkg, y))
-				continue
-			except IOError:
-				allvalid = False
-				qatracker.add_error("ebuild.output", os.path.join(xpkg, y))
-				continue
-			if not portage.eapi_is_supported(myaux["EAPI"]):
-				allvalid = False
-				qatracker.add_error("EAPI.unsupported", os.path.join(xpkg, y))
-				continue
-			pkgs[pf] = Package(
-				cpv=cpv, metadata=myaux, root_config=root_config,
-				type_name="ebuild")
 
-	slot_keywords = {}
-
-	if len(pkgs) != len(ebuildlist):
+######################
+	is_ebuild = IsEbuild(repoman_settings, repo_settings, portdb, qatracker)
+	pkgs, allvalid = is_ebuild.check(checkdirlist, checkdir, xpkg)
+	if is_ebuild.continue_:
 		# If we can't access all the metadata then it's totally unsafe to
 		# commit since there's no way to generate a correct Manifest.
 		# Do not try to do any more QA checks on this package since missing
@@ -396,6 +361,9 @@ for xpkg in effective_scanlist:
 		# positives confuse users.
 		can_force = False
 		continue
+######################
+
+	slot_keywords = {}
 
 	# Sort ebuilds in ascending order for the KEYWORDS.dropped check.
 	ebuildlist = sorted(pkgs.values())


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-06-02  3:35 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2014-06-02  3:35 UTC (permalink / raw
  To: gentoo-commits

commit:     b808cf28d451235f53d38d70d04a30838dce07a7
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Jun  2 01:48:31 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Mon Jun  2 01:48:31 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=b808cf28

Repoman Manifests: Move some additional code to manifests.py

Move the digest check to the Manifests class.
Optimize usage to use the new qatracker system.

---
 pym/repoman/checks/ebuilds/manifests.py | 20 +++++++++++++++-----
 pym/repoman/main.py                     | 14 ++++----------
 2 files changed, 19 insertions(+), 15 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/manifests.py b/pym/repoman/checks/ebuilds/manifests.py
index 53c3136..c9eda54 100644
--- a/pym/repoman/checks/ebuilds/manifests.py
+++ b/pym/repoman/checks/ebuilds/manifests.py
@@ -11,8 +11,9 @@ from portage.util import writemsg_level
 class Manifests(object):
 
 
-	def __init__(self, options, repoman_settings):
+	def __init__(self, options, qatracker, repoman_settings):
 		self.options = options
+		self.qatracker = qatracker
 		self.repoman_settings = repoman_settings
 
 		self.digest_only = options.mode != 'manifest-check' and options.digest == 'y'
@@ -41,7 +42,8 @@ class Manifests(object):
 					level=logging.ERROR, noiselevel=-1)
 
 			if not self.generated_manifest:
-				print("Unable to generate manifest.")
+				writemsg_level("Unable to generate manifest.",
+					level=logging.ERROR, noiselevel=-1)
 				failed = True
 
 			if self.options.mode == "manifest":
@@ -64,11 +66,11 @@ class Manifests(object):
 							if distfile in self.auto_assumed:
 								portage.writemsg_stdout(
 									"   %s::%s\n" % (pf, distfile))
-
-				return True  # continue, skip remaining loop code
+				# continue, skip remaining main loop code
+				return True
 			elif failed:
 				sys.exit(1)
-		return False  # stay in the loop
+		return False
 
 
 	def create_manifest(self, checkdir, fetchlist_dict):
@@ -89,3 +91,11 @@ class Manifests(object):
 			mf.write()
 		finally:
 			portage._doebuild_manifest_exempt_depend -= 1
+
+
+	def digest_check(self, checkdir):
+		self.repoman_settings['O'] = checkdir
+		self.repoman_settings['PORTAGE_QUIET'] = '1'
+		if not portage.digestcheck([], self.repoman_settings, strict=1):
+			self.qatracker.add_error("manifest.bad", os.path.join(xpkg, 'Manifest'))
+		self.repoman_settings.pop('PORTAGE_QUIET', None)

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index af7c52b..1649c9f 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -326,18 +326,12 @@ for xpkg in effective_scanlist:
 	checkdir_relative = os.path.join(".", checkdir_relative)
 
 #####################
-	manifester = Manifests(options, repoman_settings)
-	continue_ = manifester.run(checkdir, portdb)
-	if continue_:
+	manifester = Manifests(options, qatracker, repoman_settings)
+	if manifester.run(checkdir, portdb):
 		continue
-######################
-
 	if not manifester.generated_manifest:
-		repoman_settings['O'] = checkdir
-		repoman_settings['PORTAGE_QUIET'] = '1'
-		if not portage.digestcheck([], repoman_settings, strict=1):
-			qatracker.add_error("manifest.bad", os.path.join(xpkg, 'Manifest'))
-		repoman_settings.pop('PORTAGE_QUIET', None)
+		 manifester.digest_check(checkdir)
+######################
 
 	if options.mode == 'manifest-check':
 		continue


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-06-02  6:05 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2014-06-02  6:05 UTC (permalink / raw
  To: gentoo-commits

commit:     fc8b6617dfc742e683af929de7ad6d8ab70d9dc6
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Jun  2 05:31:45 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Mon Jun  2 05:31:45 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=fc8b6617

repoman/main.py: Create FetchChecks class

Create the new class in checks/ebuilds/fetches.py.

---
 pym/repoman/checks/ebuilds/fetches.py | 132 ++++++++++++++++++++++++++++++++++
 pym/repoman/main.py                   |  96 ++-----------------------
 2 files changed, 139 insertions(+), 89 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/fetches.py b/pym/repoman/checks/ebuilds/fetches.py
new file mode 100644
index 0000000..3d59339
--- /dev/null
+++ b/pym/repoman/checks/ebuilds/fetches.py
@@ -0,0 +1,132 @@
+
+'''fetches.py
+Performs the src_uri fetchlist and files checks
+'''
+
+from stat import S_ISDIR
+
+import portage
+from portage import os
+
+
+class FetchChecks(object):
+	'''Performs checks on the files needed for the ebuild'''
+
+	def __init__(self, qatracker, repoman_settings, repo_settings, portdb,
+		vcs_settings, vcs_new_changed):
+		'''
+		@param qatracker: QATracker instance
+		@param repoman_settings: settings instance
+		@param repo_settings: repository settings instance
+		@param portdb: portdb instance
+		'''
+		self.portdb = portdb
+		self.qatracker = qatracker
+		self.repo_settings = repo_settings
+		self.repoman_settings = repoman_settings
+		self.vcs_settings = vcs_settings
+		self.vcs_new_changed = vcs_new_changed
+		self._digests = None
+
+
+	def check(self, xpkg, checkdir, checkdir_relative):
+		'''Checks the ebuild sources and files for errors
+
+		@param xpkg: the pacakge being checked
+		@param checkdir: string, directory path
+		@param checkdir_relative: repolevel determined path
+		'''
+		self.checkdir = checkdir
+		fetchlist_dict = portage.FetchlistDict(checkdir, self.repoman_settings, self.portdb)
+		myfiles_all = []
+		self.src_uri_error = False
+		for mykey in fetchlist_dict:
+			try:
+				myfiles_all.extend(fetchlist_dict[mykey])
+			except portage.exception.InvalidDependString as e:
+				self.src_uri_error = True
+				try:
+					self.portdb.aux_get(mykey, ["SRC_URI"])
+				except KeyError:
+					# This will be reported as an "ebuild.syntax" error.
+					pass
+				else:
+					self.qatracker.add_error("SRC_URI.syntax",
+						"%s.ebuild SRC_URI: %s" % (mykey, e))
+		del fetchlist_dict
+		if not self.src_uri_error:
+			# This test can produce false positives if SRC_URI could not
+			# be parsed for one or more ebuilds. There's no point in
+			# producing a false error here since the root cause will
+			# produce a valid error elsewhere, such as "SRC_URI.syntax"
+			# or "ebuild.sytax".
+			myfiles_all = set(myfiles_all)
+			for entry in self.digests:
+				if entry not in myfiles_all:
+					self.qatracker.add_error("digest.unused", checkdir + "::" + entry)
+			for entry in myfiles_all:
+				if entry not in self.digests:
+					self.qatracker.add_error("digest.missing", checkdir + "::" + entry)
+		del myfiles_all
+
+		if os.path.exists(checkdir + "/files"):
+			filesdirlist = os.listdir(checkdir + "/files")
+
+			# Recurse through files directory, use filesdirlist as a stack;
+			# appending directories as needed,
+			# so people can't hide > 20k files in a subdirectory.
+			while filesdirlist:
+				y = filesdirlist.pop(0)
+				relative_path = os.path.join(xpkg, "files", y)
+				full_path = os.path.join(self.repo_settings.repodir, relative_path)
+				try:
+					mystat = os.stat(full_path)
+				except OSError as oe:
+					if oe.errno == 2:
+						# don't worry about it.  it likely was removed via fix above.
+						continue
+					else:
+						raise oe
+				if S_ISDIR(mystat.st_mode):
+					# !!! VCS "portability" alert!  Need some function isVcsDir() or alike !!!
+					if y == "CVS" or y == ".svn":
+						continue
+					for z in os.listdir(checkdir + "/files/" + y):
+						if z == "CVS" or z == ".svn":
+							continue
+						filesdirlist.append(y + "/" + z)
+				# Current policy is no files over 20 KiB, these are the checks.
+				# File size between 20 KiB and 60 KiB causes a warning,
+				# while file size over 60 KiB causes an error.
+				elif mystat.st_size > 61440:
+					self.qatracker.add_error("file.size.fatal",
+						"(%d KiB) %s/files/%s" % (mystat.st_size // 1024, xpkg, y))
+				elif mystat.st_size > 20480:
+					self.qatracker.add_error("file.size",
+						"(%d KiB) %s/files/%s" % (mystat.st_size // 1024, xpkg, y))
+
+				index = self.repo_settings.repo_config.find_invalid_path_char(y)
+				if index != -1:
+					y_relative = os.path.join(checkdir_relative, "files", y)
+					if self.vcs_settings.vcs is not None and not self.vcs_new_changed(y_relative):
+						# If the file isn't in the VCS new or changed set, then
+						# assume that it's an irrelevant temporary file (Manifest
+						# entries are not generated for file names containing
+						# prohibited characters). See bug #406877.
+						index = -1
+				if index != -1:
+					self.qatracker.add_error("file.name",
+						"%s/files/%s: char '%s'" % (checkdir, y, y[index]))
+
+
+	@property
+	def digests(self):
+		'''Property function, returns the saved digests or
+		loads them for the test'''
+		if not self._digests:
+			mf = self.repoman_settings.repositories.get_repo_for_location(
+				os.path.dirname(os.path.dirname(self.checkdir)))
+			mf = mf.load_manifest(self.checkdir, self.repoman_settings["DISTDIR"])
+			self._digests = mf.getTypeDigests("DIST")
+			del mf
+		return self._digests

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index d80cf59..ffb9929 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -16,7 +16,6 @@ import sys
 import tempfile
 import platform
 from itertools import chain
-from stat import S_ISDIR
 
 from os import path as osp
 pym_path = osp.join(osp.dirname(osp.dirname(osp.realpath(__file__)))) #, "pym")
@@ -47,6 +46,7 @@ from portage.eapi import eapi_has_iuse_defaults, eapi_has_required_use
 
 from repoman.argparser import parse_args
 from repoman.checks.ebuilds.checks import run_checks, checks_init
+from repoman.checks.ebuilds.fetches import FetchChecks
 from repoman.checks.ebuilds.isebuild import IsEbuild
 from repoman.checks.ebuilds.thirdpartymirrors import ThirdPartyMirrors
 from repoman.checks.ebuilds.manifests import Manifests
@@ -369,93 +369,11 @@ for xpkg in effective_scanlist:
 	status_check.check(check_ebuild_notadded)
 	eadded.extend(status_check.eadded)
 ###############
-
-	mf = repoman_settings.repositories.get_repo_for_location(
-		os.path.dirname(os.path.dirname(checkdir)))
-	mf = mf.load_manifest(checkdir, repoman_settings["DISTDIR"])
-	mydigests = mf.getTypeDigests("DIST")
-
-	fetchlist_dict = portage.FetchlistDict(checkdir, repoman_settings, portdb)
-	myfiles_all = []
-	src_uri_error = False
-	for mykey in fetchlist_dict:
-		try:
-			myfiles_all.extend(fetchlist_dict[mykey])
-		except portage.exception.InvalidDependString as e:
-			src_uri_error = True
-			try:
-				portdb.aux_get(mykey, ["SRC_URI"])
-			except KeyError:
-				# This will be reported as an "ebuild.syntax" error.
-				pass
-			else:
-				qatracker.add_error("SRC_URI.syntax",
-					"%s.ebuild SRC_URI: %s" % (mykey, e))
-	del fetchlist_dict
-	if not src_uri_error:
-		# This test can produce false positives if SRC_URI could not
-		# be parsed for one or more ebuilds. There's no point in
-		# producing a false error here since the root cause will
-		# produce a valid error elsewhere, such as "SRC_URI.syntax"
-		# or "ebuild.sytax".
-		myfiles_all = set(myfiles_all)
-		for entry in mydigests:
-			if entry not in myfiles_all:
-				qatracker.add_error("digest.unused", checkdir + "::" + entry)
-		for entry in myfiles_all:
-			if entry not in mydigests:
-				qatracker.add_error("digest.missing", checkdir + "::" + entry)
-	del myfiles_all
-
-	if os.path.exists(checkdir + "/files"):
-		filesdirlist = os.listdir(checkdir + "/files")
-
-		# Recurse through files directory, use filesdirlist as a stack;
-		# appending directories as needed,
-		# so people can't hide > 20k files in a subdirectory.
-		while filesdirlist:
-			y = filesdirlist.pop(0)
-			relative_path = os.path.join(xpkg, "files", y)
-			full_path = os.path.join(repo_settings.repodir, relative_path)
-			try:
-				mystat = os.stat(full_path)
-			except OSError as oe:
-				if oe.errno == 2:
-					# don't worry about it.  it likely was removed via fix above.
-					continue
-				else:
-					raise oe
-			if S_ISDIR(mystat.st_mode):
-				# !!! VCS "portability" alert!  Need some function isVcsDir() or alike !!!
-				if y == "CVS" or y == ".svn":
-					continue
-				for z in os.listdir(checkdir + "/files/" + y):
-					if z == "CVS" or z == ".svn":
-						continue
-					filesdirlist.append(y + "/" + z)
-			# Current policy is no files over 20 KiB, these are the checks.
-			# File size between 20 KiB and 60 KiB causes a warning,
-			# while file size over 60 KiB causes an error.
-			elif mystat.st_size > 61440:
-				qatracker.add_error("file.size.fatal",
-					"(%d KiB) %s/files/%s" % (mystat.st_size // 1024, xpkg, y))
-			elif mystat.st_size > 20480:
-				qatracker.add_error("file.size",
-					"(%d KiB) %s/files/%s" % (mystat.st_size // 1024, xpkg, y))
-
-			index = repo_settings.repo_config.find_invalid_path_char(y)
-			if index != -1:
-				y_relative = os.path.join(checkdir_relative, "files", y)
-				if vcs_settings.vcs is not None and not vcs_new_changed(y_relative):
-					# If the file isn't in the VCS new or changed set, then
-					# assume that it's an irrelevant temporary file (Manifest
-					# entries are not generated for file names containing
-					# prohibited characters). See bug #406877.
-					index = -1
-			if index != -1:
-				qatracker.add_error("file.name",
-					"%s/files/%s: char '%s'" % (checkdir, y, y[index]))
-	del mydigests
+#################
+	fetchcheck = FetchChecks(qatracker, repoman_settings, repo_settings, portdb,
+		vcs_settings, vcs_new_changed)
+	fetchcheck.check(xpkg, checkdir, checkdir_relative)
+#################
 
 	if check_changelog and "ChangeLog" not in checkdirlist:
 		qatracker.add_error("changelog.missing", xpkg + "/ChangeLog")
@@ -535,7 +453,7 @@ for xpkg in effective_scanlist:
 					"character at position %s" %
 					(ebuild.relative_path, k, m.start() + 1))
 
-		if not src_uri_error:
+		if not fetchcheck.src_uri_error:
 			#######################
 			thirdparty = ThirdPartyMirrors(repoman_settings, qatracker)
 			thirdparty.check(myaux, ebuild.relative_path)


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-06-02  6:44 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2014-06-02  6:44 UTC (permalink / raw
  To: gentoo-commits

commit:     71ed484f67919a13f97bfa4e0e9a251119df0c99
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Mon Jun  2 06:43:19 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Mon Jun  2 06:43:19 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=71ed484f

repoman/main.py: Split out some small ebuild checks functions

Create new checks/ebuilds/misc.py file
Add bad_split_check().
Add pkg_invalid().

---
 pym/repoman/checks/ebuilds/misc.py | 54 ++++++++++++++++++++++++++++++++++++++
 pym/repoman/main.py                | 29 ++++----------------
 2 files changed, 59 insertions(+), 24 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/misc.py b/pym/repoman/checks/ebuilds/misc.py
new file mode 100644
index 0000000..c1edd2c
--- /dev/null
+++ b/pym/repoman/checks/ebuilds/misc.py
@@ -0,0 +1,54 @@
+
+'''repoman/checks/ebuilds/misc.py
+Miscelaneous ebuild check functions'''
+
+import re
+
+import portage
+
+
+pv_toolong_re = re.compile(r'[0-9]{19,}')
+
+
+def bad_split_check(xpkg, y_ebuild, pkgdir, qatracker):
+	'''Checks for bad category/package splits.
+
+	@param xpkg: the pacakge being checked
+	@param y_ebuild: string of the ebuild name being tested
+	@param pkgdir: string: path
+	@param qatracker: QATracker instance
+	'''
+	myesplit = portage.pkgsplit(y_ebuild)
+
+	is_bad_split = myesplit is None or myesplit[0] != xpkg.split("/")[-1]
+
+	if is_bad_split:
+		is_pv_toolong = pv_toolong_re.search(myesplit[1])
+		is_pv_toolong2 = pv_toolong_re.search(myesplit[2])
+
+		if is_pv_toolong or is_pv_toolong2:
+			qatracker.add_error("ebuild.invalidname",
+				xpkg + "/" + y_ebuild + ".ebuild")
+			return True
+	elif myesplit[0] != pkgdir:
+		print(pkgdir, myesplit[0])
+		qatracker.add_error("ebuild.namenomatch",
+			xpkg + "/" + y_ebuild + ".ebuild")
+		return True
+	return False
+
+
+def pkg_invalid(pkg, qatracker):
+	'''Checks for invalid packages
+
+	@param pkg: _emerge.Package instance
+	@param qatracker: QATracker instance
+	@return boolean:
+	'''
+	if pkg.invalid:
+		for k, msgs in pkg.invalid.items():
+			for msg in msgs:
+				qatracker.add_error(k,
+					"%s: %s" % (ebuild.relative_path, msg))
+		return True
+	return False

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index 9db52c0..c680752 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -51,6 +51,7 @@ from repoman.checks.ebuilds.fetches import FetchChecks
 from repoman.checks.ebuilds.isebuild import IsEbuild
 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.ebuild import Ebuild
 from repoman.errors import err
@@ -76,8 +77,6 @@ util.initialize_logger()
 
 commitmessage = None
 
-pv_toolong_re = re.compile(r'[0-9]{19,}')
-
 bad = create_color_func("BAD")
 
 live_eclasses = portage.const.LIVE_ECLASSES
@@ -368,32 +367,14 @@ for xpkg in effective_scanlist:
 			# ebuild not added to vcs
 			qatracker.add_error("ebuild.notadded",
 				xpkg + "/" + y_ebuild + ".ebuild")
-		myesplit = portage.pkgsplit(y_ebuild)
-
-		is_bad_split = myesplit is None or myesplit[0] != xpkg.split("/")[-1]
-
-		if is_bad_split:
-			is_pv_toolong = pv_toolong_re.search(myesplit[1])
-			is_pv_toolong2 = pv_toolong_re.search(myesplit[2])
 
-			if is_pv_toolong or is_pv_toolong2:
-				qatracker.add_error("ebuild.invalidname",
-					xpkg + "/" + y_ebuild + ".ebuild")
-				continue
-		elif myesplit[0] != pkgdir:
-			print(pkgdir, myesplit[0])
-			qatracker.add_error("ebuild.namenomatch",
-				xpkg + "/" + y_ebuild + ".ebuild")
+##################
+		if bad_split_check(xpkg, y_ebuild, pkgdir, qatracker):
 			continue
-
+###################
 		pkg = pkgs[y_ebuild]
-
-		if pkg.invalid:
+		if pkg_invalid(pkg, qatracker):
 			allvalid = False
-			for k, msgs in pkg.invalid.items():
-				for msg in msgs:
-					qatracker.add_error(k,
-						"%s: %s" % (ebuild.relative_path, msg))
 			continue
 
 		myaux = pkg._metadata


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-06-03 11:16 Tom Wijsman
  0 siblings, 0 replies; 34+ messages in thread
From: Tom Wijsman @ 2014-06-03 11:16 UTC (permalink / raw
  To: gentoo-commits

commit:     7593143201d5566724a1c8ed875c4ab9f6296b99
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  3 11:15:10 2014 +0000
Commit:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
CommitDate: Tue Jun  3 11:15:10 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=75931432

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 b1b676c..c698265 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -37,7 +37,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
@@ -48,6 +47,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
@@ -360,7 +360,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
 
@@ -617,32 +617,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"]
@@ -706,21 +687,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
 


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-06-03 19:33 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2014-06-03 19:33 UTC (permalink / raw
  To: gentoo-commits

commit:     d7ebf107b68630eef02eaa4f74f69252854e31bb
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  3 19:20:43 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Tue Jun  3 19:20:43 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=d7ebf107

Repoman: Refactor PkgMetadata and XmlLint classes for variable data passed in

Move all non-consistent data to be passed in via the check functions.
Initialize XmlLint once in the PkgMetadata class __init__().

---
 pym/repoman/_xml.py                       | 33 ++++++++++++++++++++++---------
 pym/repoman/checks/ebuilds/pkgmetadata.py | 12 +++++------
 2 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/pym/repoman/_xml.py b/pym/repoman/_xml.py
index b97c027..d5b5a5e 100644
--- a/pym/repoman/_xml.py
+++ b/pym/repoman/_xml.py
@@ -14,6 +14,8 @@ from repoman._subprocess import repoman_getstatusoutput
 
 
 class _XMLParser(xml.etree.ElementTree.XMLParser):
+
+
 	def __init__(self, data, **kwargs):
 		xml.etree.ElementTree.XMLParser.__init__(self, **kwargs)
 		self._portage_data = data
@@ -25,11 +27,13 @@ class _XMLParser(xml.etree.ElementTree.XMLParser):
 			self.parser.StartDoctypeDeclHandler = \
 				self._portage_StartDoctypeDeclHandler
 
+
 	def _portage_XmlDeclHandler(self, version, encoding, standalone):
 		if self._base_XmlDeclHandler is not None:
 			self._base_XmlDeclHandler(version, encoding, standalone)
 		self._portage_data["XML_DECLARATION"] = (version, encoding, standalone)
 
+
 	def _portage_StartDoctypeDeclHandler(
 		self, doctypeName, systemId, publicId, has_internal_subset):
 		if self._base_StartDoctypeDeclHandler is not None:
@@ -49,33 +53,44 @@ class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
 
 class XmlLint(object):
 
-	def __init__(self, options, repolevel, repoman_settings):
+	def __init__(self, options, repoman_settings):
 		self.metadata_dtd = os.path.join(repoman_settings["DISTDIR"], 'metadata.dtd')
+		self.options = options
+		self.repoman_settings = repoman_settings
 		self._is_capable = False
 		self.binary = None
-		self._check_capable(options, repolevel, repoman_settings)
+		self._check_capable()
+
 
-	def _check_capable(self, options, repolevel, repoman_settings):
-		if options.mode == "manifest":
+	def _check_capable(self):
+		if self.options.mode == "manifest":
 			return
 		self.binary = find_binary('xmllint')
 		if not self.binary:
 			print(red("!!! xmllint not found. Can't check metadata.xml.\n"))
-			if options.xml_parse or repolevel == 3:
-				print("%s sorry, xmllint is needed.  failing\n" % red("!!!"))
-				sys.exit(1)
 		else:
-			if not fetch_metadata_dtd(self.metadata_dtd, repoman_settings):
+			if not fetch_metadata_dtd(self.metadata_dtd, self.repoman_settings):
 				sys.exit(1)
 			# this can be problematic if xmllint changes their output
 			self._is_capable = True
 
+
 	@property
 	def capable(self):
 		return self._is_capable
 
-	def check(self, checkdir):
+
+	def check(self, checkdir, repolevel):
+		'''Runs checks on the package metadata.xml file
+
+		@param checkdir: string, path
+		@param repolevel: integer
+		@return boolean, False == bad metadata
+		'''
 		if not self.capable:
+			if self.options.xml_parse or repolevel == 3:
+				print("%s sorry, xmllint is needed.  failing\n" % red("!!!"))
+				sys.exit(1)
 			return True
 		# xmlint can produce garbage output even on success, so only dump
 		# the ouput when it fails.

diff --git a/pym/repoman/checks/ebuilds/pkgmetadata.py b/pym/repoman/checks/ebuilds/pkgmetadata.py
index 0778696..674d32f 100644
--- a/pym/repoman/checks/ebuilds/pkgmetadata.py
+++ b/pym/repoman/checks/ebuilds/pkgmetadata.py
@@ -38,27 +38,28 @@ from repoman._xml import _XMLParser, _MetadataTreeBuilder, XmlLint
 class PkgMetadata(object):
 	'''Package metadata.xml checks'''
 
-	def __init__(self, options, qatracker, repolevel, repoman_settings):
+	def __init__(self, options, qatracker, repoman_settings):
 		'''PkgMetadata init function
 
 		@param options: ArgumentParser.parse_known_args(argv[1:]) options
 		@param qatracker: QATracker instance
-		@param repolevel: integer
 		@param repoman_settings: settings instance
 		'''
 		self.options = options
 		self.qatracker = qatracker
-		self.repolevel = repolevel
 		self.repoman_settings = repoman_settings
 		self.musedict = {}
+		self.xmllint = XmlLint(self.options, self.repoman_settings)
+
 
 
-	def check(self, xpkg, checkdir, checkdirlist):
+	def check(self, xpkg, checkdir, checkdirlist, repolevel):
 		'''Performs the checks on the metadata.xml for the package
 
 		@param xpkg: the pacakge being checked
 		@param checkdir: string, directory path
 		@param checkdirlist: list of checkdir's
+		@param repolevel: integer
 		'''
 
 		self.musedict = {}
@@ -165,8 +166,7 @@ class PkgMetadata(object):
 
 			# Only carry out if in package directory or check forced
 			if not metadata_bad:
-				xmllint = XmlLint(self.options, self.repolevel, self.repoman_settings)
-				if not xmllint.check(checkdir):
+				if not self.xmllint.check(checkdir, repolevel):
 					self.qatracker.add_error("metadata.bad", xpkg + "/metadata.xml")
 			del metadata_bad
 		return


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-06-04  9:18 Tom Wijsman
  0 siblings, 0 replies; 34+ messages in thread
From: Tom Wijsman @ 2014-06-04  9:18 UTC (permalink / raw
  To: gentoo-commits

commit:     916886782e5a4123d95ce50e2593d9c2bb114995
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Wed Jun  4 09:17:12 2014 +0000
Commit:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
CommitDate: Wed Jun  4 09:17:12 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=91688678

repoman/main.py: Split KEYWORDS checks to checks/ebuilds/keywords.py

---
 pym/repoman/checks/ebuilds/keywords.py | 67 ++++++++++++++++++++++++++++++++++
 pym/repoman/main.py                    | 32 ++++------------
 2 files changed, 75 insertions(+), 24 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/keywords.py b/pym/repoman/checks/ebuilds/keywords.py
new file mode 100644
index 0000000..29de0db
--- /dev/null
+++ b/pym/repoman/checks/ebuilds/keywords.py
@@ -0,0 +1,67 @@
+
+'''keywords.py
+Perform KEYWORDS related checks
+'''
+
+
+class KeywordChecks(object):
+	'''Perform checks on the KEYWORDS of an ebuild'''
+
+	def __init__(self, qatracker):
+		'''
+		@param qatracker: QATracker instance
+		'''
+		self.qatracker = qatracker
+		self.slot_keywords = {}
+
+	def prepare(self):
+		'''Prepare the checks for the next package.'''
+		self.slot_keywords = {}
+
+	def check(
+		self, pkg, package, ebuild, y_ebuild, keywords, ebuild_archs, changed,
+		live_ebuild):
+		'''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 keywords: All the keywords (including -...) of the ebuild.
+		@param ebuild_archs: Just the architectures (no prefixes) of the ebuild.
+		@param changed: Changes instance
+		@param slot_keywords: A dictionary of keywords per slot.
+		@param live_ebuild: A boolean that determines if this is a live ebuild.
+		'''
+		self._checkAddedWithStableKeywords(
+			package, ebuild, y_ebuild, keywords, changed)
+		self._checkForDroppedKeywords(
+			pkg, ebuild, ebuild_archs, live_ebuild)
+
+		self.slot_keywords[pkg.slot].update(ebuild_archs)
+
+	def _checkAddedWithStableKeywords(
+		self, package, ebuild, y_ebuild, keywords, changed):
+		catdir, pkgdir = package.split("/")
+
+		is_stable = lambda kw: not kw.startswith("~") and not kw.startswith("-")
+		stable_keywords = list(filter(is_stable, keywords))
+		if stable_keywords:
+			if ebuild.ebuild_path in changed.new_ebuilds and catdir != "virtual":
+				stable_keywords.sort()
+				self.qatracker.add_error(
+					"KEYWORDS.stable",
+					"%s/%s.ebuild added with stable keywords: %s" %
+					(package, y_ebuild, " ".join(stable_keywords)))
+
+	def _checkForDroppedKeywords(
+		self, pkg, ebuild, ebuild_archs, live_ebuild):
+		previous_keywords = self.slot_keywords.get(pkg.slot)
+		if previous_keywords is None:
+			self.slot_keywords[pkg.slot] = set()
+		elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
+			dropped_keywords = previous_keywords.difference(ebuild_archs)
+			if dropped_keywords:
+				self.qatracker.add_error("KEYWORDS.dropped",
+					"%s: %s" %
+					(ebuild.relative_path, " ".join(sorted(dropped_keywords))))
\ No newline at end of file

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index b347369..62c1509 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -42,6 +42,7 @@ from repoman.argparser import parse_args
 from repoman.checks.directories.files import FileChecks
 from repoman.checks.ebuilds.checks import run_checks, checks_init
 from repoman.checks.ebuilds.fetches import FetchChecks
+from repoman.checks.ebuilds.keywords import KeywordChecks
 from repoman.checks.ebuilds.isebuild import IsEbuild
 from repoman.checks.ebuilds.thirdpartymirrors import ThirdPartyMirrors
 from repoman.checks.ebuilds.manifests import Manifests
@@ -274,7 +275,7 @@ fetchcheck = FetchChecks(qatracker, repoman_settings, repo_settings, portdb,
 pkgmeta = PkgMetadata(options, qatracker, repoman_settings)
 thirdparty = ThirdPartyMirrors(repoman_settings, qatracker)
 use_flag_checks = USEFlagChecks(qatracker, uselist)
-
+keywordcheck = KeywordChecks(qatracker)
 
 for xpkg in effective_scanlist:
 	# ebuilds and digests added to cvs respectively.
@@ -315,7 +316,7 @@ for xpkg in effective_scanlist:
 		continue
 ######################
 
-	slot_keywords = {}
+	keywordcheck.prepare()
 
 	# Sort ebuilds in ascending order for the KEYWORDS.dropped check.
 	ebuildlist = sorted(pkgs.values())
@@ -425,32 +426,15 @@ for xpkg in effective_scanlist:
 				(ebuild.relative_path, len(myaux['DESCRIPTION']), max_desc_len))
 
 		keywords = myaux["KEYWORDS"].split()
-		stable_keywords = []
-		for keyword in keywords:
-			if not keyword.startswith("~") and \
-				not keyword.startswith("-"):
-				stable_keywords.append(keyword)
-		if stable_keywords:
-			if ebuild.ebuild_path in changed.new_ebuilds and catdir != "virtual":
-				stable_keywords.sort()
-				qatracker.add_error("KEYWORDS.stable",
-					"%s/%s.ebuild added with stable keywords: %s" %
-					(xpkg, y_ebuild, " ".join(stable_keywords)))
 
 		ebuild_archs = set(
 			kw.lstrip("~") for kw in keywords if not kw.startswith("-"))
 
-		previous_keywords = slot_keywords.get(pkg.slot)
-		if previous_keywords is None:
-			slot_keywords[pkg.slot] = set()
-		elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
-			dropped_keywords = previous_keywords.difference(ebuild_archs)
-			if dropped_keywords:
-				qatracker.add_error("KEYWORDS.dropped",
-					"%s: %s" %
-					(ebuild.relative_path, " ".join(sorted(dropped_keywords))))
-
-		slot_keywords[pkg.slot].update(ebuild_archs)
+		#######################
+		keywordcheck.check(
+			pkg, xpkg, ebuild, y_ebuild, keywords, ebuild_archs, changed,
+			live_ebuild)
+		#######################
 
 		# KEYWORDS="-*" is a stupid replacement for package.mask
 		# and screws general KEYWORDS semantics


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-06-04 14:18 Tom Wijsman
  0 siblings, 0 replies; 34+ messages in thread
From: Tom Wijsman @ 2014-06-04 14:18 UTC (permalink / raw
  To: gentoo-commits

commit:     86498a4b2fcedd7c9d461da1114a347d5df997de
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Wed Jun  4 14:17:49 2014 +0000
Commit:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
CommitDate: Wed Jun  4 14:17:49 2014 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=86498a4b

repoman/main.py: More KEYWORDS checks to checks/ebuilds/keywords.py

---
 pym/repoman/checks/ebuilds/keywords.py | 64 ++++++++++++++++++++++++++++++----
 pym/repoman/main.py                    | 32 +----------------
 2 files changed, 59 insertions(+), 37 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/keywords.py b/pym/repoman/checks/ebuilds/keywords.py
index 29de0db..bec7a1d 100644
--- a/pym/repoman/checks/ebuilds/keywords.py
+++ b/pym/repoman/checks/ebuilds/keywords.py
@@ -20,7 +20,7 @@ class KeywordChecks(object):
 
 	def check(
 		self, pkg, package, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-		live_ebuild):
+		live_ebuild, kwlist, profiles):
 		'''Perform the check.
 
 		@param pkg: Package in which we check (object).
@@ -32,20 +32,31 @@ class KeywordChecks(object):
 		@param changed: Changes instance
 		@param slot_keywords: A dictionary of keywords per slot.
 		@param live_ebuild: A boolean that determines if this is a live ebuild.
+		@param kwlist: A list of all global keywords.
+		@param profiles: A list of all profiles.
 		'''
 		self._checkAddedWithStableKeywords(
 			package, ebuild, y_ebuild, keywords, changed)
+
 		self._checkForDroppedKeywords(
 			pkg, ebuild, ebuild_archs, live_ebuild)
 
+		self._checkForInvalidKeywords(
+			pkg, package, y_ebuild, kwlist, profiles)
+
+		self._checkForMaskLikeKeywords(
+			package, y_ebuild, keywords, kwlist)
+
 		self.slot_keywords[pkg.slot].update(ebuild_archs)
 
+	def _isKeywordStable(self, keyword):
+		return not keyword.startswith("~") and not keyword.startswith("-")
+
 	def _checkAddedWithStableKeywords(
 		self, package, ebuild, y_ebuild, keywords, changed):
 		catdir, pkgdir = package.split("/")
 
-		is_stable = lambda kw: not kw.startswith("~") and not kw.startswith("-")
-		stable_keywords = list(filter(is_stable, keywords))
+		stable_keywords = list(filter(self._isKeywordStable, keywords))
 		if stable_keywords:
 			if ebuild.ebuild_path in changed.new_ebuilds and catdir != "virtual":
 				stable_keywords.sort()
@@ -62,6 +73,47 @@ class KeywordChecks(object):
 		elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
 			dropped_keywords = previous_keywords.difference(ebuild_archs)
 			if dropped_keywords:
-				self.qatracker.add_error("KEYWORDS.dropped",
-					"%s: %s" %
-					(ebuild.relative_path, " ".join(sorted(dropped_keywords))))
\ No newline at end of file
+				self.qatracker.add_error(
+					"KEYWORDS.dropped", "%s: %s" % (
+						ebuild.relative_path,
+						" ".join(sorted(dropped_keywords))))
+
+	def _checkForInvalidKeywords(
+		self, pkg, package, y_ebuild, kwlist, profiles):
+		myuse = pkg._metadata["KEYWORDS"].split()
+
+		for mykey in myuse:
+			if mykey not in ("-*", "*", "~*"):
+				myskey = mykey
+
+				if not self._isKeywordStable(myskey[:1]):
+					myskey = myskey[1:]
+
+				if myskey not in kwlist:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s" % (
+							package, y_ebuild, mykey))
+				elif myskey not in profiles:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s (profile invalid)" % (
+							package, y_ebuild, mykey))
+
+	def _checkForMaskLikeKeywords(
+		self, package, y_ebuild, keywords, kwlist):
+
+		# KEYWORDS="-*" is a stupid replacement for package.mask
+		# and screws general KEYWORDS semantics
+		if "-*" in keywords:
+			haskeyword = False
+
+			for kw in keywords:
+				if kw[0] == "~":
+					kw = kw[1:]
+				if kw in kwlist:
+					haskeyword = True
+
+			if not haskeyword:
+				self.qatracker.add_error(
+					"KEYWORDS.stupid", package + "/" + y_ebuild + ".ebuild")

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index 5762abd..649fc84 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -440,22 +440,9 @@ for xpkg in effective_scanlist:
 		#######################
 		keywordcheck.check(
 			pkg, xpkg, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-			live_ebuild)
+			live_ebuild, kwlist, profiles)
 		#######################
 
-		# KEYWORDS="-*" is a stupid replacement for package.mask
-		# and screws general KEYWORDS semantics
-		if "-*" in keywords:
-			haskeyword = False
-			for kw in keywords:
-				if kw[0] == "~":
-					kw = kw[1:]
-				if kw in kwlist:
-					haskeyword = True
-			if not haskeyword:
-				qatracker.add_error("KEYWORDS.stupid",
-					xpkg + "/" + y_ebuild + ".ebuild")
-
 		if live_ebuild and repo_settings.repo_config.name == "gentoo":
 			#######################
 			liveeclasscheck.check(
@@ -622,23 +609,6 @@ for xpkg in effective_scanlist:
 					qatracker.add_error("LICENSE.deprecated",
 						"%s: %s" % (ebuild.relative_path, lic))
 
-		# keyword checks
-		myuse = myaux["KEYWORDS"].split()
-		for mykey in myuse:
-			if mykey not in ("-*", "*", "~*"):
-				myskey = mykey
-				if myskey[:1] == "-":
-					myskey = myskey[1:]
-				if myskey[:1] == "~":
-					myskey = myskey[1:]
-				if myskey not in kwlist:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s" % (xpkg, y_ebuild, mykey))
-				elif myskey not in profiles:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s (profile invalid)"
-						% (xpkg, y_ebuild, mykey))
-
 		# restrict checks
 		myrestrict = None
 		try:


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-10-01 23:02 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2014-10-01 23:02 UTC (permalink / raw
  To: gentoo-commits

commit:     c925718100adf9048b36e99d0a5816fcb87012c6
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 22:58:13 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=c9257181

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
 


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-10-01 23:02 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2014-10-01 23:02 UTC (permalink / raw
  To: gentoo-commits

commit:     3a5cad45548f3acc695226ea78e2c0a4577149c3
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  3 19:20:43 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Wed Oct  1 22:58:13 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=3a5cad45

Repoman: Refactor PkgMetadata and XmlLint classes for variable data passed in

Move all non-consistent data to be passed in via the check functions.
Initialize XmlLint once in the PkgMetadata class __init__().

---
 pym/repoman/_xml.py                       | 33 ++++++++++++++++++++++---------
 pym/repoman/checks/ebuilds/pkgmetadata.py | 12 +++++------
 2 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/pym/repoman/_xml.py b/pym/repoman/_xml.py
index b97c027..d5b5a5e 100644
--- a/pym/repoman/_xml.py
+++ b/pym/repoman/_xml.py
@@ -14,6 +14,8 @@ from repoman._subprocess import repoman_getstatusoutput
 
 
 class _XMLParser(xml.etree.ElementTree.XMLParser):
+
+
 	def __init__(self, data, **kwargs):
 		xml.etree.ElementTree.XMLParser.__init__(self, **kwargs)
 		self._portage_data = data
@@ -25,11 +27,13 @@ class _XMLParser(xml.etree.ElementTree.XMLParser):
 			self.parser.StartDoctypeDeclHandler = \
 				self._portage_StartDoctypeDeclHandler
 
+
 	def _portage_XmlDeclHandler(self, version, encoding, standalone):
 		if self._base_XmlDeclHandler is not None:
 			self._base_XmlDeclHandler(version, encoding, standalone)
 		self._portage_data["XML_DECLARATION"] = (version, encoding, standalone)
 
+
 	def _portage_StartDoctypeDeclHandler(
 		self, doctypeName, systemId, publicId, has_internal_subset):
 		if self._base_StartDoctypeDeclHandler is not None:
@@ -49,33 +53,44 @@ class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
 
 class XmlLint(object):
 
-	def __init__(self, options, repolevel, repoman_settings):
+	def __init__(self, options, repoman_settings):
 		self.metadata_dtd = os.path.join(repoman_settings["DISTDIR"], 'metadata.dtd')
+		self.options = options
+		self.repoman_settings = repoman_settings
 		self._is_capable = False
 		self.binary = None
-		self._check_capable(options, repolevel, repoman_settings)
+		self._check_capable()
+
 
-	def _check_capable(self, options, repolevel, repoman_settings):
-		if options.mode == "manifest":
+	def _check_capable(self):
+		if self.options.mode == "manifest":
 			return
 		self.binary = find_binary('xmllint')
 		if not self.binary:
 			print(red("!!! xmllint not found. Can't check metadata.xml.\n"))
-			if options.xml_parse or repolevel == 3:
-				print("%s sorry, xmllint is needed.  failing\n" % red("!!!"))
-				sys.exit(1)
 		else:
-			if not fetch_metadata_dtd(self.metadata_dtd, repoman_settings):
+			if not fetch_metadata_dtd(self.metadata_dtd, self.repoman_settings):
 				sys.exit(1)
 			# this can be problematic if xmllint changes their output
 			self._is_capable = True
 
+
 	@property
 	def capable(self):
 		return self._is_capable
 
-	def check(self, checkdir):
+
+	def check(self, checkdir, repolevel):
+		'''Runs checks on the package metadata.xml file
+
+		@param checkdir: string, path
+		@param repolevel: integer
+		@return boolean, False == bad metadata
+		'''
 		if not self.capable:
+			if self.options.xml_parse or repolevel == 3:
+				print("%s sorry, xmllint is needed.  failing\n" % red("!!!"))
+				sys.exit(1)
 			return True
 		# xmlint can produce garbage output even on success, so only dump
 		# the ouput when it fails.

diff --git a/pym/repoman/checks/ebuilds/pkgmetadata.py b/pym/repoman/checks/ebuilds/pkgmetadata.py
index 0778696..674d32f 100644
--- a/pym/repoman/checks/ebuilds/pkgmetadata.py
+++ b/pym/repoman/checks/ebuilds/pkgmetadata.py
@@ -38,27 +38,28 @@ from repoman._xml import _XMLParser, _MetadataTreeBuilder, XmlLint
 class PkgMetadata(object):
 	'''Package metadata.xml checks'''
 
-	def __init__(self, options, qatracker, repolevel, repoman_settings):
+	def __init__(self, options, qatracker, repoman_settings):
 		'''PkgMetadata init function
 
 		@param options: ArgumentParser.parse_known_args(argv[1:]) options
 		@param qatracker: QATracker instance
-		@param repolevel: integer
 		@param repoman_settings: settings instance
 		'''
 		self.options = options
 		self.qatracker = qatracker
-		self.repolevel = repolevel
 		self.repoman_settings = repoman_settings
 		self.musedict = {}
+		self.xmllint = XmlLint(self.options, self.repoman_settings)
+
 
 
-	def check(self, xpkg, checkdir, checkdirlist):
+	def check(self, xpkg, checkdir, checkdirlist, repolevel):
 		'''Performs the checks on the metadata.xml for the package
 
 		@param xpkg: the pacakge being checked
 		@param checkdir: string, directory path
 		@param checkdirlist: list of checkdir's
+		@param repolevel: integer
 		'''
 
 		self.musedict = {}
@@ -165,8 +166,7 @@ class PkgMetadata(object):
 
 			# Only carry out if in package directory or check forced
 			if not metadata_bad:
-				xmllint = XmlLint(self.options, self.repolevel, self.repoman_settings)
-				if not xmllint.check(checkdir):
+				if not self.xmllint.check(checkdir, repolevel):
 					self.qatracker.add_error("metadata.bad", xpkg + "/metadata.xml")
 			del metadata_bad
 		return


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-10-01 23:46 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2014-10-01 23:46 UTC (permalink / raw
  To: gentoo-commits

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
 


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-10-01 23:46 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2014-10-01 23:46 UTC (permalink / raw
  To: gentoo-commits

commit:     7dc0305c383403bb643d8e9cba967064c87aa1c6
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  3 19:20:43 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=7dc0305c

Repoman: Refactor PkgMetadata and XmlLint classes for variable data passed in

Move all non-consistent data to be passed in via the check functions.
Initialize XmlLint once in the PkgMetadata class __init__().

---
 pym/repoman/_xml.py                       | 33 ++++++++++++++++++++++---------
 pym/repoman/checks/ebuilds/pkgmetadata.py | 12 +++++------
 2 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/pym/repoman/_xml.py b/pym/repoman/_xml.py
index b97c027..d5b5a5e 100644
--- a/pym/repoman/_xml.py
+++ b/pym/repoman/_xml.py
@@ -14,6 +14,8 @@ from repoman._subprocess import repoman_getstatusoutput
 
 
 class _XMLParser(xml.etree.ElementTree.XMLParser):
+
+
 	def __init__(self, data, **kwargs):
 		xml.etree.ElementTree.XMLParser.__init__(self, **kwargs)
 		self._portage_data = data
@@ -25,11 +27,13 @@ class _XMLParser(xml.etree.ElementTree.XMLParser):
 			self.parser.StartDoctypeDeclHandler = \
 				self._portage_StartDoctypeDeclHandler
 
+
 	def _portage_XmlDeclHandler(self, version, encoding, standalone):
 		if self._base_XmlDeclHandler is not None:
 			self._base_XmlDeclHandler(version, encoding, standalone)
 		self._portage_data["XML_DECLARATION"] = (version, encoding, standalone)
 
+
 	def _portage_StartDoctypeDeclHandler(
 		self, doctypeName, systemId, publicId, has_internal_subset):
 		if self._base_StartDoctypeDeclHandler is not None:
@@ -49,33 +53,44 @@ class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
 
 class XmlLint(object):
 
-	def __init__(self, options, repolevel, repoman_settings):
+	def __init__(self, options, repoman_settings):
 		self.metadata_dtd = os.path.join(repoman_settings["DISTDIR"], 'metadata.dtd')
+		self.options = options
+		self.repoman_settings = repoman_settings
 		self._is_capable = False
 		self.binary = None
-		self._check_capable(options, repolevel, repoman_settings)
+		self._check_capable()
+
 
-	def _check_capable(self, options, repolevel, repoman_settings):
-		if options.mode == "manifest":
+	def _check_capable(self):
+		if self.options.mode == "manifest":
 			return
 		self.binary = find_binary('xmllint')
 		if not self.binary:
 			print(red("!!! xmllint not found. Can't check metadata.xml.\n"))
-			if options.xml_parse or repolevel == 3:
-				print("%s sorry, xmllint is needed.  failing\n" % red("!!!"))
-				sys.exit(1)
 		else:
-			if not fetch_metadata_dtd(self.metadata_dtd, repoman_settings):
+			if not fetch_metadata_dtd(self.metadata_dtd, self.repoman_settings):
 				sys.exit(1)
 			# this can be problematic if xmllint changes their output
 			self._is_capable = True
 
+
 	@property
 	def capable(self):
 		return self._is_capable
 
-	def check(self, checkdir):
+
+	def check(self, checkdir, repolevel):
+		'''Runs checks on the package metadata.xml file
+
+		@param checkdir: string, path
+		@param repolevel: integer
+		@return boolean, False == bad metadata
+		'''
 		if not self.capable:
+			if self.options.xml_parse or repolevel == 3:
+				print("%s sorry, xmllint is needed.  failing\n" % red("!!!"))
+				sys.exit(1)
 			return True
 		# xmlint can produce garbage output even on success, so only dump
 		# the ouput when it fails.

diff --git a/pym/repoman/checks/ebuilds/pkgmetadata.py b/pym/repoman/checks/ebuilds/pkgmetadata.py
index 0778696..674d32f 100644
--- a/pym/repoman/checks/ebuilds/pkgmetadata.py
+++ b/pym/repoman/checks/ebuilds/pkgmetadata.py
@@ -38,27 +38,28 @@ from repoman._xml import _XMLParser, _MetadataTreeBuilder, XmlLint
 class PkgMetadata(object):
 	'''Package metadata.xml checks'''
 
-	def __init__(self, options, qatracker, repolevel, repoman_settings):
+	def __init__(self, options, qatracker, repoman_settings):
 		'''PkgMetadata init function
 
 		@param options: ArgumentParser.parse_known_args(argv[1:]) options
 		@param qatracker: QATracker instance
-		@param repolevel: integer
 		@param repoman_settings: settings instance
 		'''
 		self.options = options
 		self.qatracker = qatracker
-		self.repolevel = repolevel
 		self.repoman_settings = repoman_settings
 		self.musedict = {}
+		self.xmllint = XmlLint(self.options, self.repoman_settings)
+
 
 
-	def check(self, xpkg, checkdir, checkdirlist):
+	def check(self, xpkg, checkdir, checkdirlist, repolevel):
 		'''Performs the checks on the metadata.xml for the package
 
 		@param xpkg: the pacakge being checked
 		@param checkdir: string, directory path
 		@param checkdirlist: list of checkdir's
+		@param repolevel: integer
 		'''
 
 		self.musedict = {}
@@ -165,8 +166,7 @@ class PkgMetadata(object):
 
 			# Only carry out if in package directory or check forced
 			if not metadata_bad:
-				xmllint = XmlLint(self.options, self.repolevel, self.repoman_settings)
-				if not xmllint.check(checkdir):
+				if not self.xmllint.check(checkdir, repolevel):
 					self.qatracker.add_error("metadata.bad", xpkg + "/metadata.xml")
 			del metadata_bad
 		return


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-10-01 23:46 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2014-10-01 23:46 UTC (permalink / raw
  To: gentoo-commits

commit:     3488df72f0af643234e5d05b519334e169822e0d
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Wed Jun  4 09:17:12 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Wed Oct  1 23:45:34 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=3488df72

repoman/main.py: Split KEYWORDS checks to checks/ebuilds/keywords.py

---
 pym/repoman/checks/ebuilds/keywords.py | 67 ++++++++++++++++++++++++++++++++++
 pym/repoman/main.py                    | 32 ++++------------
 2 files changed, 75 insertions(+), 24 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/keywords.py b/pym/repoman/checks/ebuilds/keywords.py
new file mode 100644
index 0000000..29de0db
--- /dev/null
+++ b/pym/repoman/checks/ebuilds/keywords.py
@@ -0,0 +1,67 @@
+
+'''keywords.py
+Perform KEYWORDS related checks
+'''
+
+
+class KeywordChecks(object):
+	'''Perform checks on the KEYWORDS of an ebuild'''
+
+	def __init__(self, qatracker):
+		'''
+		@param qatracker: QATracker instance
+		'''
+		self.qatracker = qatracker
+		self.slot_keywords = {}
+
+	def prepare(self):
+		'''Prepare the checks for the next package.'''
+		self.slot_keywords = {}
+
+	def check(
+		self, pkg, package, ebuild, y_ebuild, keywords, ebuild_archs, changed,
+		live_ebuild):
+		'''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 keywords: All the keywords (including -...) of the ebuild.
+		@param ebuild_archs: Just the architectures (no prefixes) of the ebuild.
+		@param changed: Changes instance
+		@param slot_keywords: A dictionary of keywords per slot.
+		@param live_ebuild: A boolean that determines if this is a live ebuild.
+		'''
+		self._checkAddedWithStableKeywords(
+			package, ebuild, y_ebuild, keywords, changed)
+		self._checkForDroppedKeywords(
+			pkg, ebuild, ebuild_archs, live_ebuild)
+
+		self.slot_keywords[pkg.slot].update(ebuild_archs)
+
+	def _checkAddedWithStableKeywords(
+		self, package, ebuild, y_ebuild, keywords, changed):
+		catdir, pkgdir = package.split("/")
+
+		is_stable = lambda kw: not kw.startswith("~") and not kw.startswith("-")
+		stable_keywords = list(filter(is_stable, keywords))
+		if stable_keywords:
+			if ebuild.ebuild_path in changed.new_ebuilds and catdir != "virtual":
+				stable_keywords.sort()
+				self.qatracker.add_error(
+					"KEYWORDS.stable",
+					"%s/%s.ebuild added with stable keywords: %s" %
+					(package, y_ebuild, " ".join(stable_keywords)))
+
+	def _checkForDroppedKeywords(
+		self, pkg, ebuild, ebuild_archs, live_ebuild):
+		previous_keywords = self.slot_keywords.get(pkg.slot)
+		if previous_keywords is None:
+			self.slot_keywords[pkg.slot] = set()
+		elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
+			dropped_keywords = previous_keywords.difference(ebuild_archs)
+			if dropped_keywords:
+				self.qatracker.add_error("KEYWORDS.dropped",
+					"%s: %s" %
+					(ebuild.relative_path, " ".join(sorted(dropped_keywords))))
\ No newline at end of file

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index 8a1a043..05d9a14 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -49,6 +49,7 @@ from repoman.argparser import parse_args
 from repoman.checks.directories.files import FileChecks
 from repoman.checks.ebuilds.checks import run_checks, checks_init
 from repoman.checks.ebuilds.fetches import FetchChecks
+from repoman.checks.ebuilds.keywords import KeywordChecks
 from repoman.checks.ebuilds.isebuild import IsEbuild
 from repoman.checks.ebuilds.thirdpartymirrors import ThirdPartyMirrors
 from repoman.checks.ebuilds.manifests import Manifests
@@ -281,7 +282,7 @@ fetchcheck = FetchChecks(qatracker, repoman_settings, repo_settings, portdb,
 pkgmeta = PkgMetadata(options, qatracker, repoman_settings)
 thirdparty = ThirdPartyMirrors(repoman_settings, qatracker)
 use_flag_checks = USEFlagChecks(qatracker, uselist)
-
+keywordcheck = KeywordChecks(qatracker)
 
 for xpkg in effective_scanlist:
 	# ebuilds and digests added to cvs respectively.
@@ -322,7 +323,7 @@ for xpkg in effective_scanlist:
 		continue
 ######################
 
-	slot_keywords = {}
+	keywordcheck.prepare()
 
 	# Sort ebuilds in ascending order for the KEYWORDS.dropped check.
 	ebuildlist = sorted(pkgs.values())
@@ -427,32 +428,15 @@ for xpkg in effective_scanlist:
 				(ebuild.relative_path, len(myaux['DESCRIPTION']), max_desc_len))
 
 		keywords = myaux["KEYWORDS"].split()
-		stable_keywords = []
-		for keyword in keywords:
-			if not keyword.startswith("~") and \
-				not keyword.startswith("-"):
-				stable_keywords.append(keyword)
-		if stable_keywords:
-			if ebuild.ebuild_path in changed.new_ebuilds and catdir != "virtual":
-				stable_keywords.sort()
-				qatracker.add_error("KEYWORDS.stable",
-					"%s/%s.ebuild added with stable keywords: %s" %
-					(xpkg, y_ebuild, " ".join(stable_keywords)))
 
 		ebuild_archs = set(
 			kw.lstrip("~") for kw in keywords if not kw.startswith("-"))
 
-		previous_keywords = slot_keywords.get(pkg.slot)
-		if previous_keywords is None:
-			slot_keywords[pkg.slot] = set()
-		elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
-			dropped_keywords = previous_keywords.difference(ebuild_archs)
-			if dropped_keywords:
-				qatracker.add_error("KEYWORDS.dropped",
-					"%s: %s" %
-					(ebuild.relative_path, " ".join(sorted(dropped_keywords))))
-
-		slot_keywords[pkg.slot].update(ebuild_archs)
+		#######################
+		keywordcheck.check(
+			pkg, xpkg, ebuild, y_ebuild, keywords, ebuild_archs, changed,
+			live_ebuild)
+		#######################
 
 		# KEYWORDS="-*" is a stupid replacement for package.mask
 		# and screws general KEYWORDS semantics


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-11-17  0:55 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2014-11-17  0:55 UTC (permalink / raw
  To: gentoo-commits

commit:     177a5b647a326784e2274476feaf5a6bd6596075
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Wed Jun  4 14:17:49 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Mon Nov 17 00:53:14 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=177a5b64

repoman/main.py: More KEYWORDS checks to checks/ebuilds/keywords.py

---
 pym/repoman/checks/ebuilds/keywords.py | 64 ++++++++++++++++++++++++++++++----
 pym/repoman/main.py                    | 32 +----------------
 2 files changed, 59 insertions(+), 37 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/keywords.py b/pym/repoman/checks/ebuilds/keywords.py
index 29de0db..bec7a1d 100644
--- a/pym/repoman/checks/ebuilds/keywords.py
+++ b/pym/repoman/checks/ebuilds/keywords.py
@@ -20,7 +20,7 @@ class KeywordChecks(object):
 
 	def check(
 		self, pkg, package, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-		live_ebuild):
+		live_ebuild, kwlist, profiles):
 		'''Perform the check.
 
 		@param pkg: Package in which we check (object).
@@ -32,20 +32,31 @@ class KeywordChecks(object):
 		@param changed: Changes instance
 		@param slot_keywords: A dictionary of keywords per slot.
 		@param live_ebuild: A boolean that determines if this is a live ebuild.
+		@param kwlist: A list of all global keywords.
+		@param profiles: A list of all profiles.
 		'''
 		self._checkAddedWithStableKeywords(
 			package, ebuild, y_ebuild, keywords, changed)
+
 		self._checkForDroppedKeywords(
 			pkg, ebuild, ebuild_archs, live_ebuild)
 
+		self._checkForInvalidKeywords(
+			pkg, package, y_ebuild, kwlist, profiles)
+
+		self._checkForMaskLikeKeywords(
+			package, y_ebuild, keywords, kwlist)
+
 		self.slot_keywords[pkg.slot].update(ebuild_archs)
 
+	def _isKeywordStable(self, keyword):
+		return not keyword.startswith("~") and not keyword.startswith("-")
+
 	def _checkAddedWithStableKeywords(
 		self, package, ebuild, y_ebuild, keywords, changed):
 		catdir, pkgdir = package.split("/")
 
-		is_stable = lambda kw: not kw.startswith("~") and not kw.startswith("-")
-		stable_keywords = list(filter(is_stable, keywords))
+		stable_keywords = list(filter(self._isKeywordStable, keywords))
 		if stable_keywords:
 			if ebuild.ebuild_path in changed.new_ebuilds and catdir != "virtual":
 				stable_keywords.sort()
@@ -62,6 +73,47 @@ class KeywordChecks(object):
 		elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
 			dropped_keywords = previous_keywords.difference(ebuild_archs)
 			if dropped_keywords:
-				self.qatracker.add_error("KEYWORDS.dropped",
-					"%s: %s" %
-					(ebuild.relative_path, " ".join(sorted(dropped_keywords))))
\ No newline at end of file
+				self.qatracker.add_error(
+					"KEYWORDS.dropped", "%s: %s" % (
+						ebuild.relative_path,
+						" ".join(sorted(dropped_keywords))))
+
+	def _checkForInvalidKeywords(
+		self, pkg, package, y_ebuild, kwlist, profiles):
+		myuse = pkg._metadata["KEYWORDS"].split()
+
+		for mykey in myuse:
+			if mykey not in ("-*", "*", "~*"):
+				myskey = mykey
+
+				if not self._isKeywordStable(myskey[:1]):
+					myskey = myskey[1:]
+
+				if myskey not in kwlist:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s" % (
+							package, y_ebuild, mykey))
+				elif myskey not in profiles:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s (profile invalid)" % (
+							package, y_ebuild, mykey))
+
+	def _checkForMaskLikeKeywords(
+		self, package, y_ebuild, keywords, kwlist):
+
+		# KEYWORDS="-*" is a stupid replacement for package.mask
+		# and screws general KEYWORDS semantics
+		if "-*" in keywords:
+			haskeyword = False
+
+			for kw in keywords:
+				if kw[0] == "~":
+					kw = kw[1:]
+				if kw in kwlist:
+					haskeyword = True
+
+			if not haskeyword:
+				self.qatracker.add_error(
+					"KEYWORDS.stupid", package + "/" + y_ebuild + ".ebuild")

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index 1107c63..e338d82 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -442,22 +442,9 @@ for xpkg in effective_scanlist:
 		#######################
 		keywordcheck.check(
 			pkg, xpkg, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-			live_ebuild)
+			live_ebuild, kwlist, profiles)
 		#######################
 
-		# KEYWORDS="-*" is a stupid replacement for package.mask
-		# and screws general KEYWORDS semantics
-		if "-*" in keywords:
-			haskeyword = False
-			for kw in keywords:
-				if kw[0] == "~":
-					kw = kw[1:]
-				if kw in kwlist:
-					haskeyword = True
-			if not haskeyword:
-				qatracker.add_error("KEYWORDS.stupid",
-					xpkg + "/" + y_ebuild + ".ebuild")
-
 		if live_ebuild and repo_settings.repo_config.name == "gentoo":
 			#######################
 			liveeclasscheck.check(
@@ -631,23 +618,6 @@ for xpkg in effective_scanlist:
 					qatracker.add_error("LICENSE.deprecated",
 						"%s: %s" % (ebuild.relative_path, lic))
 
-		# keyword checks
-		myuse = myaux["KEYWORDS"].split()
-		for mykey in myuse:
-			if mykey not in ("-*", "*", "~*"):
-				myskey = mykey
-				if myskey[:1] == "-":
-					myskey = myskey[1:]
-				if myskey[:1] == "~":
-					myskey = myskey[1:]
-				if myskey not in kwlist:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s" % (xpkg, y_ebuild, mykey))
-				elif myskey not in profiles:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s (profile invalid)"
-						% (xpkg, y_ebuild, mykey))
-
 		# restrict checks
 		myrestrict = None
 		try:


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-11-17  0:55 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2014-11-17  0:55 UTC (permalink / raw
  To: gentoo-commits

commit:     5c827bb7cf9a0b1de5e1ff6640b408486b4e0a8b
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Wed Jun  4 09:17:12 2014 +0000
Commit:     Brian Dolbec <brian.dolbec <AT> gmail <DOT> com>
CommitDate: Mon Nov 17 00:53:14 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=5c827bb7

repoman/main.py: Split KEYWORDS checks to checks/ebuilds/keywords.py

---
 pym/repoman/checks/ebuilds/keywords.py | 67 ++++++++++++++++++++++++++++++++++
 pym/repoman/main.py                    | 32 ++++------------
 2 files changed, 75 insertions(+), 24 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/keywords.py b/pym/repoman/checks/ebuilds/keywords.py
new file mode 100644
index 0000000..29de0db
--- /dev/null
+++ b/pym/repoman/checks/ebuilds/keywords.py
@@ -0,0 +1,67 @@
+
+'''keywords.py
+Perform KEYWORDS related checks
+'''
+
+
+class KeywordChecks(object):
+	'''Perform checks on the KEYWORDS of an ebuild'''
+
+	def __init__(self, qatracker):
+		'''
+		@param qatracker: QATracker instance
+		'''
+		self.qatracker = qatracker
+		self.slot_keywords = {}
+
+	def prepare(self):
+		'''Prepare the checks for the next package.'''
+		self.slot_keywords = {}
+
+	def check(
+		self, pkg, package, ebuild, y_ebuild, keywords, ebuild_archs, changed,
+		live_ebuild):
+		'''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 keywords: All the keywords (including -...) of the ebuild.
+		@param ebuild_archs: Just the architectures (no prefixes) of the ebuild.
+		@param changed: Changes instance
+		@param slot_keywords: A dictionary of keywords per slot.
+		@param live_ebuild: A boolean that determines if this is a live ebuild.
+		'''
+		self._checkAddedWithStableKeywords(
+			package, ebuild, y_ebuild, keywords, changed)
+		self._checkForDroppedKeywords(
+			pkg, ebuild, ebuild_archs, live_ebuild)
+
+		self.slot_keywords[pkg.slot].update(ebuild_archs)
+
+	def _checkAddedWithStableKeywords(
+		self, package, ebuild, y_ebuild, keywords, changed):
+		catdir, pkgdir = package.split("/")
+
+		is_stable = lambda kw: not kw.startswith("~") and not kw.startswith("-")
+		stable_keywords = list(filter(is_stable, keywords))
+		if stable_keywords:
+			if ebuild.ebuild_path in changed.new_ebuilds and catdir != "virtual":
+				stable_keywords.sort()
+				self.qatracker.add_error(
+					"KEYWORDS.stable",
+					"%s/%s.ebuild added with stable keywords: %s" %
+					(package, y_ebuild, " ".join(stable_keywords)))
+
+	def _checkForDroppedKeywords(
+		self, pkg, ebuild, ebuild_archs, live_ebuild):
+		previous_keywords = self.slot_keywords.get(pkg.slot)
+		if previous_keywords is None:
+			self.slot_keywords[pkg.slot] = set()
+		elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
+			dropped_keywords = previous_keywords.difference(ebuild_archs)
+			if dropped_keywords:
+				self.qatracker.add_error("KEYWORDS.dropped",
+					"%s: %s" %
+					(ebuild.relative_path, " ".join(sorted(dropped_keywords))))
\ No newline at end of file

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index 8a1a043..05d9a14 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -49,6 +49,7 @@ from repoman.argparser import parse_args
 from repoman.checks.directories.files import FileChecks
 from repoman.checks.ebuilds.checks import run_checks, checks_init
 from repoman.checks.ebuilds.fetches import FetchChecks
+from repoman.checks.ebuilds.keywords import KeywordChecks
 from repoman.checks.ebuilds.isebuild import IsEbuild
 from repoman.checks.ebuilds.thirdpartymirrors import ThirdPartyMirrors
 from repoman.checks.ebuilds.manifests import Manifests
@@ -281,7 +282,7 @@ fetchcheck = FetchChecks(qatracker, repoman_settings, repo_settings, portdb,
 pkgmeta = PkgMetadata(options, qatracker, repoman_settings)
 thirdparty = ThirdPartyMirrors(repoman_settings, qatracker)
 use_flag_checks = USEFlagChecks(qatracker, uselist)
-
+keywordcheck = KeywordChecks(qatracker)
 
 for xpkg in effective_scanlist:
 	# ebuilds and digests added to cvs respectively.
@@ -322,7 +323,7 @@ for xpkg in effective_scanlist:
 		continue
 ######################
 
-	slot_keywords = {}
+	keywordcheck.prepare()
 
 	# Sort ebuilds in ascending order for the KEYWORDS.dropped check.
 	ebuildlist = sorted(pkgs.values())
@@ -427,32 +428,15 @@ for xpkg in effective_scanlist:
 				(ebuild.relative_path, len(myaux['DESCRIPTION']), max_desc_len))
 
 		keywords = myaux["KEYWORDS"].split()
-		stable_keywords = []
-		for keyword in keywords:
-			if not keyword.startswith("~") and \
-				not keyword.startswith("-"):
-				stable_keywords.append(keyword)
-		if stable_keywords:
-			if ebuild.ebuild_path in changed.new_ebuilds and catdir != "virtual":
-				stable_keywords.sort()
-				qatracker.add_error("KEYWORDS.stable",
-					"%s/%s.ebuild added with stable keywords: %s" %
-					(xpkg, y_ebuild, " ".join(stable_keywords)))
 
 		ebuild_archs = set(
 			kw.lstrip("~") for kw in keywords if not kw.startswith("-"))
 
-		previous_keywords = slot_keywords.get(pkg.slot)
-		if previous_keywords is None:
-			slot_keywords[pkg.slot] = set()
-		elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
-			dropped_keywords = previous_keywords.difference(ebuild_archs)
-			if dropped_keywords:
-				qatracker.add_error("KEYWORDS.dropped",
-					"%s: %s" %
-					(ebuild.relative_path, " ".join(sorted(dropped_keywords))))
-
-		slot_keywords[pkg.slot].update(ebuild_archs)
+		#######################
+		keywordcheck.check(
+			pkg, xpkg, ebuild, y_ebuild, keywords, ebuild_archs, changed,
+			live_ebuild)
+		#######################
 
 		# KEYWORDS="-*" is a stupid replacement for package.mask
 		# and screws general KEYWORDS semantics


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2014-11-17  0:55 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2014-11-17  0:55 UTC (permalink / raw
  To: gentoo-commits

commit:     8e3db8774af398521ad69ad4e7a44ab75f1b4654
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: Mon Nov 17 00:53:13 2014 +0000
URL:        http://sources.gentoo.org/gitweb/?p=proj/portage.git;a=commit;h=8e3db877

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
 


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-08-10 13:44 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2015-08-10 13:44 UTC (permalink / raw
  To: gentoo-commits

commit:     39cc82a67ac407818c3255c2ce625d37b00a5a26
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  3 11:15:10 2014 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Tue Jul 21 05:47:26 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=39cc82a6

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 662b627..d1f2b40 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -46,7 +46,6 @@ from portage.output import ConsoleStyleFile, StyleWriter
 from portage.util import formatter
 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
@@ -58,6 +57,7 @@ from repoman.checks.ebuilds.manifests import Manifests
 from repoman.check_missingslot import check_missingslot
 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
@@ -370,7 +370,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
 
@@ -633,32 +633,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"]
@@ -722,21 +703,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
 


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-08-10 13:44 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2015-08-10 13:44 UTC (permalink / raw
  To: gentoo-commits

commit:     449eac5ad48c485e58665d781bd9fc621dc2184b
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  3 19:20:43 2014 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Tue Jul 21 05:47:28 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=449eac5a

Repoman: Refactor PkgMetadata and XmlLint classes for variable data passed in

Move all non-consistent data to be passed in via the check functions.
Initialize XmlLint once in the PkgMetadata class __init__().

 pym/repoman/_xml.py                       | 33 ++++++++++++++++++++++---------
 pym/repoman/checks/ebuilds/pkgmetadata.py | 12 +++++------
 2 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/pym/repoman/_xml.py b/pym/repoman/_xml.py
index b97c027..d5b5a5e 100644
--- a/pym/repoman/_xml.py
+++ b/pym/repoman/_xml.py
@@ -14,6 +14,8 @@ from repoman._subprocess import repoman_getstatusoutput
 
 
 class _XMLParser(xml.etree.ElementTree.XMLParser):
+
+
 	def __init__(self, data, **kwargs):
 		xml.etree.ElementTree.XMLParser.__init__(self, **kwargs)
 		self._portage_data = data
@@ -25,11 +27,13 @@ class _XMLParser(xml.etree.ElementTree.XMLParser):
 			self.parser.StartDoctypeDeclHandler = \
 				self._portage_StartDoctypeDeclHandler
 
+
 	def _portage_XmlDeclHandler(self, version, encoding, standalone):
 		if self._base_XmlDeclHandler is not None:
 			self._base_XmlDeclHandler(version, encoding, standalone)
 		self._portage_data["XML_DECLARATION"] = (version, encoding, standalone)
 
+
 	def _portage_StartDoctypeDeclHandler(
 		self, doctypeName, systemId, publicId, has_internal_subset):
 		if self._base_StartDoctypeDeclHandler is not None:
@@ -49,33 +53,44 @@ class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
 
 class XmlLint(object):
 
-	def __init__(self, options, repolevel, repoman_settings):
+	def __init__(self, options, repoman_settings):
 		self.metadata_dtd = os.path.join(repoman_settings["DISTDIR"], 'metadata.dtd')
+		self.options = options
+		self.repoman_settings = repoman_settings
 		self._is_capable = False
 		self.binary = None
-		self._check_capable(options, repolevel, repoman_settings)
+		self._check_capable()
+
 
-	def _check_capable(self, options, repolevel, repoman_settings):
-		if options.mode == "manifest":
+	def _check_capable(self):
+		if self.options.mode == "manifest":
 			return
 		self.binary = find_binary('xmllint')
 		if not self.binary:
 			print(red("!!! xmllint not found. Can't check metadata.xml.\n"))
-			if options.xml_parse or repolevel == 3:
-				print("%s sorry, xmllint is needed.  failing\n" % red("!!!"))
-				sys.exit(1)
 		else:
-			if not fetch_metadata_dtd(self.metadata_dtd, repoman_settings):
+			if not fetch_metadata_dtd(self.metadata_dtd, self.repoman_settings):
 				sys.exit(1)
 			# this can be problematic if xmllint changes their output
 			self._is_capable = True
 
+
 	@property
 	def capable(self):
 		return self._is_capable
 
-	def check(self, checkdir):
+
+	def check(self, checkdir, repolevel):
+		'''Runs checks on the package metadata.xml file
+
+		@param checkdir: string, path
+		@param repolevel: integer
+		@return boolean, False == bad metadata
+		'''
 		if not self.capable:
+			if self.options.xml_parse or repolevel == 3:
+				print("%s sorry, xmllint is needed.  failing\n" % red("!!!"))
+				sys.exit(1)
 			return True
 		# xmlint can produce garbage output even on success, so only dump
 		# the ouput when it fails.

diff --git a/pym/repoman/checks/ebuilds/pkgmetadata.py b/pym/repoman/checks/ebuilds/pkgmetadata.py
index 0778696..674d32f 100644
--- a/pym/repoman/checks/ebuilds/pkgmetadata.py
+++ b/pym/repoman/checks/ebuilds/pkgmetadata.py
@@ -38,27 +38,28 @@ from repoman._xml import _XMLParser, _MetadataTreeBuilder, XmlLint
 class PkgMetadata(object):
 	'''Package metadata.xml checks'''
 
-	def __init__(self, options, qatracker, repolevel, repoman_settings):
+	def __init__(self, options, qatracker, repoman_settings):
 		'''PkgMetadata init function
 
 		@param options: ArgumentParser.parse_known_args(argv[1:]) options
 		@param qatracker: QATracker instance
-		@param repolevel: integer
 		@param repoman_settings: settings instance
 		'''
 		self.options = options
 		self.qatracker = qatracker
-		self.repolevel = repolevel
 		self.repoman_settings = repoman_settings
 		self.musedict = {}
+		self.xmllint = XmlLint(self.options, self.repoman_settings)
+
 
 
-	def check(self, xpkg, checkdir, checkdirlist):
+	def check(self, xpkg, checkdir, checkdirlist, repolevel):
 		'''Performs the checks on the metadata.xml for the package
 
 		@param xpkg: the pacakge being checked
 		@param checkdir: string, directory path
 		@param checkdirlist: list of checkdir's
+		@param repolevel: integer
 		'''
 
 		self.musedict = {}
@@ -165,8 +166,7 @@ class PkgMetadata(object):
 
 			# Only carry out if in package directory or check forced
 			if not metadata_bad:
-				xmllint = XmlLint(self.options, self.repolevel, self.repoman_settings)
-				if not xmllint.check(checkdir):
+				if not self.xmllint.check(checkdir, repolevel):
 					self.qatracker.add_error("metadata.bad", xpkg + "/metadata.xml")
 			del metadata_bad
 		return


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-08-10 13:44 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2015-08-10 13:44 UTC (permalink / raw
  To: gentoo-commits

commit:     d4677d5fcb9b89bc02f07779fdcf6c5017dc5881
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Wed Jun  4 14:17:49 2014 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Tue Jul 21 05:47:29 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=d4677d5f

repoman/main.py: More KEYWORDS checks to checks/ebuilds/keywords.py

 pym/repoman/checks/ebuilds/keywords.py | 64 ++++++++++++++++++++++++++++++----
 pym/repoman/main.py                    | 32 +----------------
 2 files changed, 59 insertions(+), 37 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/keywords.py b/pym/repoman/checks/ebuilds/keywords.py
index b724269..235c751 100644
--- a/pym/repoman/checks/ebuilds/keywords.py
+++ b/pym/repoman/checks/ebuilds/keywords.py
@@ -21,7 +21,7 @@ class KeywordChecks(object):
 
 	def check(
 		self, pkg, package, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-		live_ebuild):
+		live_ebuild, kwlist, profiles):
 		'''Perform the check.
 
 		@param pkg: Package in which we check (object).
@@ -33,21 +33,32 @@ class KeywordChecks(object):
 		@param changed: Changes instance
 		@param slot_keywords: A dictionary of keywords per slot.
 		@param live_ebuild: A boolean that determines if this is a live ebuild.
+		@param kwlist: A list of all global keywords.
+		@param profiles: A list of all profiles.
 		'''
 		if not self.options.straight_to_stable:
 			self._checkAddedWithStableKeywords(
 				package, ebuild, y_ebuild, keywords, changed)
+
 		self._checkForDroppedKeywords(
 			pkg, ebuild, ebuild_archs, live_ebuild)
 
+		self._checkForInvalidKeywords(
+			pkg, package, y_ebuild, kwlist, profiles)
+
+		self._checkForMaskLikeKeywords(
+			package, y_ebuild, keywords, kwlist)
+
 		self.slot_keywords[pkg.slot].update(ebuild_archs)
 
+	def _isKeywordStable(self, keyword):
+		return not keyword.startswith("~") and not keyword.startswith("-")
+
 	def _checkAddedWithStableKeywords(
 		self, package, ebuild, y_ebuild, keywords, changed):
 		catdir, pkgdir = package.split("/")
 
-		is_stable = lambda kw: not kw.startswith("~") and not kw.startswith("-")
-		stable_keywords = list(filter(is_stable, keywords))
+		stable_keywords = list(filter(self._isKeywordStable, keywords))
 		if stable_keywords:
 			if ebuild.ebuild_path in changed.new_ebuilds and catdir != "virtual":
 				stable_keywords.sort()
@@ -64,6 +75,47 @@ class KeywordChecks(object):
 		elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
 			dropped_keywords = previous_keywords.difference(ebuild_archs)
 			if dropped_keywords:
-				self.qatracker.add_error("KEYWORDS.dropped",
-					"%s: %s" %
-					(ebuild.relative_path, " ".join(sorted(dropped_keywords))))
+				self.qatracker.add_error(
+					"KEYWORDS.dropped", "%s: %s" % (
+						ebuild.relative_path,
+						" ".join(sorted(dropped_keywords))))
+
+	def _checkForInvalidKeywords(
+		self, pkg, package, y_ebuild, kwlist, profiles):
+		myuse = pkg._metadata["KEYWORDS"].split()
+
+		for mykey in myuse:
+			if mykey not in ("-*", "*", "~*"):
+				myskey = mykey
+
+				if not self._isKeywordStable(myskey[:1]):
+					myskey = myskey[1:]
+
+				if myskey not in kwlist:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s" % (
+							package, y_ebuild, mykey))
+				elif myskey not in profiles:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s (profile invalid)" % (
+							package, y_ebuild, mykey))
+
+	def _checkForMaskLikeKeywords(
+		self, package, y_ebuild, keywords, kwlist):
+
+		# KEYWORDS="-*" is a stupid replacement for package.mask
+		# and screws general KEYWORDS semantics
+		if "-*" in keywords:
+			haskeyword = False
+
+			for kw in keywords:
+				if kw[0] == "~":
+					kw = kw[1:]
+				if kw in kwlist:
+					haskeyword = True
+
+			if not haskeyword:
+				self.qatracker.add_error(
+					"KEYWORDS.stupid", package + "/" + y_ebuild + ".ebuild")

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index 8b9e73d..ab908e0 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -445,22 +445,9 @@ for xpkg in effective_scanlist:
 		#######################
 		keywordcheck.check(
 			pkg, xpkg, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-			live_ebuild)
+			live_ebuild, kwlist, profiles)
 		#######################
 
-		# KEYWORDS="-*" is a stupid replacement for package.mask
-		# and screws general KEYWORDS semantics
-		if "-*" in keywords:
-			haskeyword = False
-			for kw in keywords:
-				if kw[0] == "~":
-					kw = kw[1:]
-				if kw in kwlist:
-					haskeyword = True
-			if not haskeyword:
-				qatracker.add_error("KEYWORDS.stupid",
-					xpkg + "/" + y_ebuild + ".ebuild")
-
 		if live_ebuild and repo_settings.repo_config.name == "gentoo":
 			#######################
 			liveeclasscheck.check(
@@ -637,23 +624,6 @@ for xpkg in effective_scanlist:
 					qatracker.add_error("LICENSE.deprecated",
 						"%s: %s" % (ebuild.relative_path, lic))
 
-		# keyword checks
-		myuse = myaux["KEYWORDS"].split()
-		for mykey in myuse:
-			if mykey not in ("-*", "*", "~*"):
-				myskey = mykey
-				if myskey[:1] == "-":
-					myskey = myskey[1:]
-				if myskey[:1] == "~":
-					myskey = myskey[1:]
-				if myskey not in kwlist:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s" % (xpkg, y_ebuild, mykey))
-				elif myskey not in profiles:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s (profile invalid)"
-						% (xpkg, y_ebuild, mykey))
-
 		# restrict checks
 		myrestrict = None
 		try:


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-08-10 14:45 Michał Górny
  0 siblings, 0 replies; 34+ messages in thread
From: Michał Górny @ 2015-08-10 14:45 UTC (permalink / raw
  To: gentoo-commits

commit:     c589f72b468e24964c4d0f5a78094c8e18972a63
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Wed Jun  4 14:17:49 2014 +0000
Commit:     Michał Górny <mgorny <AT> gentoo <DOT> org>
CommitDate: Mon Aug 10 14:45:20 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=c589f72b

repoman/main.py: More KEYWORDS checks to checks/ebuilds/keywords.py

 pym/repoman/checks/ebuilds/keywords.py | 64 ++++++++++++++++++++++++++++++----
 pym/repoman/main.py                    | 32 +----------------
 2 files changed, 59 insertions(+), 37 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/keywords.py b/pym/repoman/checks/ebuilds/keywords.py
index b724269..235c751 100644
--- a/pym/repoman/checks/ebuilds/keywords.py
+++ b/pym/repoman/checks/ebuilds/keywords.py
@@ -21,7 +21,7 @@ class KeywordChecks(object):
 
 	def check(
 		self, pkg, package, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-		live_ebuild):
+		live_ebuild, kwlist, profiles):
 		'''Perform the check.
 
 		@param pkg: Package in which we check (object).
@@ -33,21 +33,32 @@ class KeywordChecks(object):
 		@param changed: Changes instance
 		@param slot_keywords: A dictionary of keywords per slot.
 		@param live_ebuild: A boolean that determines if this is a live ebuild.
+		@param kwlist: A list of all global keywords.
+		@param profiles: A list of all profiles.
 		'''
 		if not self.options.straight_to_stable:
 			self._checkAddedWithStableKeywords(
 				package, ebuild, y_ebuild, keywords, changed)
+
 		self._checkForDroppedKeywords(
 			pkg, ebuild, ebuild_archs, live_ebuild)
 
+		self._checkForInvalidKeywords(
+			pkg, package, y_ebuild, kwlist, profiles)
+
+		self._checkForMaskLikeKeywords(
+			package, y_ebuild, keywords, kwlist)
+
 		self.slot_keywords[pkg.slot].update(ebuild_archs)
 
+	def _isKeywordStable(self, keyword):
+		return not keyword.startswith("~") and not keyword.startswith("-")
+
 	def _checkAddedWithStableKeywords(
 		self, package, ebuild, y_ebuild, keywords, changed):
 		catdir, pkgdir = package.split("/")
 
-		is_stable = lambda kw: not kw.startswith("~") and not kw.startswith("-")
-		stable_keywords = list(filter(is_stable, keywords))
+		stable_keywords = list(filter(self._isKeywordStable, keywords))
 		if stable_keywords:
 			if ebuild.ebuild_path in changed.new_ebuilds and catdir != "virtual":
 				stable_keywords.sort()
@@ -64,6 +75,47 @@ class KeywordChecks(object):
 		elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
 			dropped_keywords = previous_keywords.difference(ebuild_archs)
 			if dropped_keywords:
-				self.qatracker.add_error("KEYWORDS.dropped",
-					"%s: %s" %
-					(ebuild.relative_path, " ".join(sorted(dropped_keywords))))
+				self.qatracker.add_error(
+					"KEYWORDS.dropped", "%s: %s" % (
+						ebuild.relative_path,
+						" ".join(sorted(dropped_keywords))))
+
+	def _checkForInvalidKeywords(
+		self, pkg, package, y_ebuild, kwlist, profiles):
+		myuse = pkg._metadata["KEYWORDS"].split()
+
+		for mykey in myuse:
+			if mykey not in ("-*", "*", "~*"):
+				myskey = mykey
+
+				if not self._isKeywordStable(myskey[:1]):
+					myskey = myskey[1:]
+
+				if myskey not in kwlist:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s" % (
+							package, y_ebuild, mykey))
+				elif myskey not in profiles:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s (profile invalid)" % (
+							package, y_ebuild, mykey))
+
+	def _checkForMaskLikeKeywords(
+		self, package, y_ebuild, keywords, kwlist):
+
+		# KEYWORDS="-*" is a stupid replacement for package.mask
+		# and screws general KEYWORDS semantics
+		if "-*" in keywords:
+			haskeyword = False
+
+			for kw in keywords:
+				if kw[0] == "~":
+					kw = kw[1:]
+				if kw in kwlist:
+					haskeyword = True
+
+			if not haskeyword:
+				self.qatracker.add_error(
+					"KEYWORDS.stupid", package + "/" + y_ebuild + ".ebuild")

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index bcd2174..d6532f9 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -445,22 +445,9 @@ for xpkg in effective_scanlist:
 		#######################
 		keywordcheck.check(
 			pkg, xpkg, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-			live_ebuild)
+			live_ebuild, kwlist, profiles)
 		#######################
 
-		# KEYWORDS="-*" is a stupid replacement for package.mask
-		# and screws general KEYWORDS semantics
-		if "-*" in keywords:
-			haskeyword = False
-			for kw in keywords:
-				if kw[0] == "~":
-					kw = kw[1:]
-				if kw in kwlist:
-					haskeyword = True
-			if not haskeyword:
-				qatracker.add_error("KEYWORDS.stupid",
-					xpkg + "/" + y_ebuild + ".ebuild")
-
 		if live_ebuild and repo_settings.repo_config.name == "gentoo":
 			#######################
 			liveeclasscheck.check(
@@ -637,23 +624,6 @@ for xpkg in effective_scanlist:
 					qatracker.add_error("LICENSE.deprecated",
 						"%s: %s" % (ebuild.relative_path, lic))
 
-		# keyword checks
-		myuse = myaux["KEYWORDS"].split()
-		for mykey in myuse:
-			if mykey not in ("-*", "*", "~*"):
-				myskey = mykey
-				if myskey[:1] == "-":
-					myskey = myskey[1:]
-				if myskey[:1] == "~":
-					myskey = myskey[1:]
-				if myskey not in kwlist:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s" % (xpkg, y_ebuild, mykey))
-				elif myskey not in profiles:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s (profile invalid)"
-						% (xpkg, y_ebuild, mykey))
-
 		# restrict checks
 		myrestrict = None
 		try:


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-08-11 23:54 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2015-08-11 23:54 UTC (permalink / raw
  To: gentoo-commits

commit:     febac24f8e7fa55d46d9afd8d88c72f8952c512a
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  3 11:15:10 2014 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Tue Aug 11 23:52:52 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=febac24f

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 90c0c14..95af4d4 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -46,7 +46,6 @@ from portage.output import ConsoleStyleFile, StyleWriter
 from portage.util import formatter
 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
@@ -58,6 +57,7 @@ from repoman.checks.ebuilds.manifests import Manifests
 from repoman.check_missingslot import check_missingslot
 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
@@ -370,7 +370,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
 
@@ -633,32 +633,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"]
@@ -722,21 +703,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
 


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-08-11 23:54 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2015-08-11 23:54 UTC (permalink / raw
  To: gentoo-commits

commit:     c7923fcab6f9ce5ee29afd87e1baad5975312223
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Wed Jun  4 14:17:49 2014 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Tue Aug 11 23:52:55 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=c7923fca

repoman/main.py: More KEYWORDS checks to checks/ebuilds/keywords.py

 pym/repoman/checks/ebuilds/keywords.py | 64 ++++++++++++++++++++++++++++++----
 pym/repoman/main.py                    | 32 +----------------
 2 files changed, 59 insertions(+), 37 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/keywords.py b/pym/repoman/checks/ebuilds/keywords.py
index b724269..235c751 100644
--- a/pym/repoman/checks/ebuilds/keywords.py
+++ b/pym/repoman/checks/ebuilds/keywords.py
@@ -21,7 +21,7 @@ class KeywordChecks(object):
 
 	def check(
 		self, pkg, package, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-		live_ebuild):
+		live_ebuild, kwlist, profiles):
 		'''Perform the check.
 
 		@param pkg: Package in which we check (object).
@@ -33,21 +33,32 @@ class KeywordChecks(object):
 		@param changed: Changes instance
 		@param slot_keywords: A dictionary of keywords per slot.
 		@param live_ebuild: A boolean that determines if this is a live ebuild.
+		@param kwlist: A list of all global keywords.
+		@param profiles: A list of all profiles.
 		'''
 		if not self.options.straight_to_stable:
 			self._checkAddedWithStableKeywords(
 				package, ebuild, y_ebuild, keywords, changed)
+
 		self._checkForDroppedKeywords(
 			pkg, ebuild, ebuild_archs, live_ebuild)
 
+		self._checkForInvalidKeywords(
+			pkg, package, y_ebuild, kwlist, profiles)
+
+		self._checkForMaskLikeKeywords(
+			package, y_ebuild, keywords, kwlist)
+
 		self.slot_keywords[pkg.slot].update(ebuild_archs)
 
+	def _isKeywordStable(self, keyword):
+		return not keyword.startswith("~") and not keyword.startswith("-")
+
 	def _checkAddedWithStableKeywords(
 		self, package, ebuild, y_ebuild, keywords, changed):
 		catdir, pkgdir = package.split("/")
 
-		is_stable = lambda kw: not kw.startswith("~") and not kw.startswith("-")
-		stable_keywords = list(filter(is_stable, keywords))
+		stable_keywords = list(filter(self._isKeywordStable, keywords))
 		if stable_keywords:
 			if ebuild.ebuild_path in changed.new_ebuilds and catdir != "virtual":
 				stable_keywords.sort()
@@ -64,6 +75,47 @@ class KeywordChecks(object):
 		elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
 			dropped_keywords = previous_keywords.difference(ebuild_archs)
 			if dropped_keywords:
-				self.qatracker.add_error("KEYWORDS.dropped",
-					"%s: %s" %
-					(ebuild.relative_path, " ".join(sorted(dropped_keywords))))
+				self.qatracker.add_error(
+					"KEYWORDS.dropped", "%s: %s" % (
+						ebuild.relative_path,
+						" ".join(sorted(dropped_keywords))))
+
+	def _checkForInvalidKeywords(
+		self, pkg, package, y_ebuild, kwlist, profiles):
+		myuse = pkg._metadata["KEYWORDS"].split()
+
+		for mykey in myuse:
+			if mykey not in ("-*", "*", "~*"):
+				myskey = mykey
+
+				if not self._isKeywordStable(myskey[:1]):
+					myskey = myskey[1:]
+
+				if myskey not in kwlist:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s" % (
+							package, y_ebuild, mykey))
+				elif myskey not in profiles:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s (profile invalid)" % (
+							package, y_ebuild, mykey))
+
+	def _checkForMaskLikeKeywords(
+		self, package, y_ebuild, keywords, kwlist):
+
+		# KEYWORDS="-*" is a stupid replacement for package.mask
+		# and screws general KEYWORDS semantics
+		if "-*" in keywords:
+			haskeyword = False
+
+			for kw in keywords:
+				if kw[0] == "~":
+					kw = kw[1:]
+				if kw in kwlist:
+					haskeyword = True
+
+			if not haskeyword:
+				self.qatracker.add_error(
+					"KEYWORDS.stupid", package + "/" + y_ebuild + ".ebuild")

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index bcd2174..d6532f9 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -445,22 +445,9 @@ for xpkg in effective_scanlist:
 		#######################
 		keywordcheck.check(
 			pkg, xpkg, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-			live_ebuild)
+			live_ebuild, kwlist, profiles)
 		#######################
 
-		# KEYWORDS="-*" is a stupid replacement for package.mask
-		# and screws general KEYWORDS semantics
-		if "-*" in keywords:
-			haskeyword = False
-			for kw in keywords:
-				if kw[0] == "~":
-					kw = kw[1:]
-				if kw in kwlist:
-					haskeyword = True
-			if not haskeyword:
-				qatracker.add_error("KEYWORDS.stupid",
-					xpkg + "/" + y_ebuild + ".ebuild")
-
 		if live_ebuild and repo_settings.repo_config.name == "gentoo":
 			#######################
 			liveeclasscheck.check(
@@ -637,23 +624,6 @@ for xpkg in effective_scanlist:
 					qatracker.add_error("LICENSE.deprecated",
 						"%s: %s" % (ebuild.relative_path, lic))
 
-		# keyword checks
-		myuse = myaux["KEYWORDS"].split()
-		for mykey in myuse:
-			if mykey not in ("-*", "*", "~*"):
-				myskey = mykey
-				if myskey[:1] == "-":
-					myskey = myskey[1:]
-				if myskey[:1] == "~":
-					myskey = myskey[1:]
-				if myskey not in kwlist:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s" % (xpkg, y_ebuild, mykey))
-				elif myskey not in profiles:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s (profile invalid)"
-						% (xpkg, y_ebuild, mykey))
-
 		# restrict checks
 		myrestrict = None
 		try:


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-09-05 21:48 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2015-09-05 21:48 UTC (permalink / raw
  To: gentoo-commits

commit:     36fe5b2808a6c174e9025152293b0738cc9fd16a
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  3 11:15:10 2014 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Sep  5 21:47:35 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=36fe5b28

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 34e9067..a5214d8 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -46,7 +46,6 @@ from portage.output import ConsoleStyleFile, StyleWriter
 from portage.util import formatter
 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
@@ -58,6 +57,7 @@ from repoman.checks.ebuilds.manifests import Manifests
 from repoman.check_missingslot import check_missingslot
 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
@@ -370,7 +370,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
 
@@ -633,32 +633,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"]
@@ -722,21 +703,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
 


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-09-05 21:48 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2015-09-05 21:48 UTC (permalink / raw
  To: gentoo-commits

commit:     6bd98ee4b60bb581cf535f666dbde4bf1fe6fce5
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  3 19:20:43 2014 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Sep  5 21:47:36 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=6bd98ee4

Repoman: Refactor PkgMetadata and XmlLint classes for variable data passed in

Move all non-consistent data to be passed in via the check functions.
Initialize XmlLint once in the PkgMetadata class __init__().

 pym/repoman/_xml.py                       | 33 ++++++++++++++++++++++---------
 pym/repoman/checks/ebuilds/pkgmetadata.py | 12 +++++------
 2 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/pym/repoman/_xml.py b/pym/repoman/_xml.py
index b97c027..d5b5a5e 100644
--- a/pym/repoman/_xml.py
+++ b/pym/repoman/_xml.py
@@ -14,6 +14,8 @@ from repoman._subprocess import repoman_getstatusoutput
 
 
 class _XMLParser(xml.etree.ElementTree.XMLParser):
+
+
 	def __init__(self, data, **kwargs):
 		xml.etree.ElementTree.XMLParser.__init__(self, **kwargs)
 		self._portage_data = data
@@ -25,11 +27,13 @@ class _XMLParser(xml.etree.ElementTree.XMLParser):
 			self.parser.StartDoctypeDeclHandler = \
 				self._portage_StartDoctypeDeclHandler
 
+
 	def _portage_XmlDeclHandler(self, version, encoding, standalone):
 		if self._base_XmlDeclHandler is not None:
 			self._base_XmlDeclHandler(version, encoding, standalone)
 		self._portage_data["XML_DECLARATION"] = (version, encoding, standalone)
 
+
 	def _portage_StartDoctypeDeclHandler(
 		self, doctypeName, systemId, publicId, has_internal_subset):
 		if self._base_StartDoctypeDeclHandler is not None:
@@ -49,33 +53,44 @@ class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
 
 class XmlLint(object):
 
-	def __init__(self, options, repolevel, repoman_settings):
+	def __init__(self, options, repoman_settings):
 		self.metadata_dtd = os.path.join(repoman_settings["DISTDIR"], 'metadata.dtd')
+		self.options = options
+		self.repoman_settings = repoman_settings
 		self._is_capable = False
 		self.binary = None
-		self._check_capable(options, repolevel, repoman_settings)
+		self._check_capable()
+
 
-	def _check_capable(self, options, repolevel, repoman_settings):
-		if options.mode == "manifest":
+	def _check_capable(self):
+		if self.options.mode == "manifest":
 			return
 		self.binary = find_binary('xmllint')
 		if not self.binary:
 			print(red("!!! xmllint not found. Can't check metadata.xml.\n"))
-			if options.xml_parse or repolevel == 3:
-				print("%s sorry, xmllint is needed.  failing\n" % red("!!!"))
-				sys.exit(1)
 		else:
-			if not fetch_metadata_dtd(self.metadata_dtd, repoman_settings):
+			if not fetch_metadata_dtd(self.metadata_dtd, self.repoman_settings):
 				sys.exit(1)
 			# this can be problematic if xmllint changes their output
 			self._is_capable = True
 
+
 	@property
 	def capable(self):
 		return self._is_capable
 
-	def check(self, checkdir):
+
+	def check(self, checkdir, repolevel):
+		'''Runs checks on the package metadata.xml file
+
+		@param checkdir: string, path
+		@param repolevel: integer
+		@return boolean, False == bad metadata
+		'''
 		if not self.capable:
+			if self.options.xml_parse or repolevel == 3:
+				print("%s sorry, xmllint is needed.  failing\n" % red("!!!"))
+				sys.exit(1)
 			return True
 		# xmlint can produce garbage output even on success, so only dump
 		# the ouput when it fails.

diff --git a/pym/repoman/checks/ebuilds/pkgmetadata.py b/pym/repoman/checks/ebuilds/pkgmetadata.py
index 0778696..674d32f 100644
--- a/pym/repoman/checks/ebuilds/pkgmetadata.py
+++ b/pym/repoman/checks/ebuilds/pkgmetadata.py
@@ -38,27 +38,28 @@ from repoman._xml import _XMLParser, _MetadataTreeBuilder, XmlLint
 class PkgMetadata(object):
 	'''Package metadata.xml checks'''
 
-	def __init__(self, options, qatracker, repolevel, repoman_settings):
+	def __init__(self, options, qatracker, repoman_settings):
 		'''PkgMetadata init function
 
 		@param options: ArgumentParser.parse_known_args(argv[1:]) options
 		@param qatracker: QATracker instance
-		@param repolevel: integer
 		@param repoman_settings: settings instance
 		'''
 		self.options = options
 		self.qatracker = qatracker
-		self.repolevel = repolevel
 		self.repoman_settings = repoman_settings
 		self.musedict = {}
+		self.xmllint = XmlLint(self.options, self.repoman_settings)
+
 
 
-	def check(self, xpkg, checkdir, checkdirlist):
+	def check(self, xpkg, checkdir, checkdirlist, repolevel):
 		'''Performs the checks on the metadata.xml for the package
 
 		@param xpkg: the pacakge being checked
 		@param checkdir: string, directory path
 		@param checkdirlist: list of checkdir's
+		@param repolevel: integer
 		'''
 
 		self.musedict = {}
@@ -165,8 +166,7 @@ class PkgMetadata(object):
 
 			# Only carry out if in package directory or check forced
 			if not metadata_bad:
-				xmllint = XmlLint(self.options, self.repolevel, self.repoman_settings)
-				if not xmllint.check(checkdir):
+				if not self.xmllint.check(checkdir, repolevel):
 					self.qatracker.add_error("metadata.bad", xpkg + "/metadata.xml")
 			del metadata_bad
 		return


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-09-05 21:48 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2015-09-05 21:48 UTC (permalink / raw
  To: gentoo-commits

commit:     0d1ae797f9dae8ffcc3cb4bccf2c31f3303ddf0b
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Wed Jun  4 14:17:49 2014 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sat Sep  5 21:47:37 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=0d1ae797

repoman/main.py: More KEYWORDS checks to checks/ebuilds/keywords.py

 pym/repoman/checks/ebuilds/keywords.py | 64 ++++++++++++++++++++++++++++++----
 pym/repoman/main.py                    | 32 +----------------
 2 files changed, 59 insertions(+), 37 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/keywords.py b/pym/repoman/checks/ebuilds/keywords.py
index b724269..235c751 100644
--- a/pym/repoman/checks/ebuilds/keywords.py
+++ b/pym/repoman/checks/ebuilds/keywords.py
@@ -21,7 +21,7 @@ class KeywordChecks(object):
 
 	def check(
 		self, pkg, package, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-		live_ebuild):
+		live_ebuild, kwlist, profiles):
 		'''Perform the check.
 
 		@param pkg: Package in which we check (object).
@@ -33,21 +33,32 @@ class KeywordChecks(object):
 		@param changed: Changes instance
 		@param slot_keywords: A dictionary of keywords per slot.
 		@param live_ebuild: A boolean that determines if this is a live ebuild.
+		@param kwlist: A list of all global keywords.
+		@param profiles: A list of all profiles.
 		'''
 		if not self.options.straight_to_stable:
 			self._checkAddedWithStableKeywords(
 				package, ebuild, y_ebuild, keywords, changed)
+
 		self._checkForDroppedKeywords(
 			pkg, ebuild, ebuild_archs, live_ebuild)
 
+		self._checkForInvalidKeywords(
+			pkg, package, y_ebuild, kwlist, profiles)
+
+		self._checkForMaskLikeKeywords(
+			package, y_ebuild, keywords, kwlist)
+
 		self.slot_keywords[pkg.slot].update(ebuild_archs)
 
+	def _isKeywordStable(self, keyword):
+		return not keyword.startswith("~") and not keyword.startswith("-")
+
 	def _checkAddedWithStableKeywords(
 		self, package, ebuild, y_ebuild, keywords, changed):
 		catdir, pkgdir = package.split("/")
 
-		is_stable = lambda kw: not kw.startswith("~") and not kw.startswith("-")
-		stable_keywords = list(filter(is_stable, keywords))
+		stable_keywords = list(filter(self._isKeywordStable, keywords))
 		if stable_keywords:
 			if ebuild.ebuild_path in changed.new_ebuilds and catdir != "virtual":
 				stable_keywords.sort()
@@ -64,6 +75,47 @@ class KeywordChecks(object):
 		elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
 			dropped_keywords = previous_keywords.difference(ebuild_archs)
 			if dropped_keywords:
-				self.qatracker.add_error("KEYWORDS.dropped",
-					"%s: %s" %
-					(ebuild.relative_path, " ".join(sorted(dropped_keywords))))
+				self.qatracker.add_error(
+					"KEYWORDS.dropped", "%s: %s" % (
+						ebuild.relative_path,
+						" ".join(sorted(dropped_keywords))))
+
+	def _checkForInvalidKeywords(
+		self, pkg, package, y_ebuild, kwlist, profiles):
+		myuse = pkg._metadata["KEYWORDS"].split()
+
+		for mykey in myuse:
+			if mykey not in ("-*", "*", "~*"):
+				myskey = mykey
+
+				if not self._isKeywordStable(myskey[:1]):
+					myskey = myskey[1:]
+
+				if myskey not in kwlist:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s" % (
+							package, y_ebuild, mykey))
+				elif myskey not in profiles:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s (profile invalid)" % (
+							package, y_ebuild, mykey))
+
+	def _checkForMaskLikeKeywords(
+		self, package, y_ebuild, keywords, kwlist):
+
+		# KEYWORDS="-*" is a stupid replacement for package.mask
+		# and screws general KEYWORDS semantics
+		if "-*" in keywords:
+			haskeyword = False
+
+			for kw in keywords:
+				if kw[0] == "~":
+					kw = kw[1:]
+				if kw in kwlist:
+					haskeyword = True
+
+			if not haskeyword:
+				self.qatracker.add_error(
+					"KEYWORDS.stupid", package + "/" + y_ebuild + ".ebuild")

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index 7795f2f..db76d52 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -445,22 +445,9 @@ for xpkg in effective_scanlist:
 		#######################
 		keywordcheck.check(
 			pkg, xpkg, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-			live_ebuild)
+			live_ebuild, kwlist, profiles)
 		#######################
 
-		# KEYWORDS="-*" is a stupid replacement for package.mask
-		# and screws general KEYWORDS semantics
-		if "-*" in keywords:
-			haskeyword = False
-			for kw in keywords:
-				if kw[0] == "~":
-					kw = kw[1:]
-				if kw in kwlist:
-					haskeyword = True
-			if not haskeyword:
-				qatracker.add_error("KEYWORDS.stupid",
-					xpkg + "/" + y_ebuild + ".ebuild")
-
 		if live_ebuild and repo_settings.repo_config.name == "gentoo":
 			#######################
 			liveeclasscheck.check(
@@ -637,23 +624,6 @@ for xpkg in effective_scanlist:
 					qatracker.add_error("LICENSE.deprecated",
 						"%s: %s" % (ebuild.relative_path, lic))
 
-		# keyword checks
-		myuse = myaux["KEYWORDS"].split()
-		for mykey in myuse:
-			if mykey not in ("-*", "*", "~*"):
-				myskey = mykey
-				if myskey[:1] == "-":
-					myskey = myskey[1:]
-				if myskey[:1] == "~":
-					myskey = myskey[1:]
-				if myskey not in kwlist:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s" % (xpkg, y_ebuild, mykey))
-				elif myskey not in profiles:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s (profile invalid)"
-						% (xpkg, y_ebuild, mykey))
-
 		# restrict checks
 		myrestrict = None
 		try:


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-09-17  3:08 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2015-09-17  3:08 UTC (permalink / raw
  To: gentoo-commits

commit:     c3defe18576100debd545bd3bcb78f1d14d90146
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  3 11:15:10 2014 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Thu Sep 17 03:06:46 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=c3defe18

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 34e9067..a5214d8 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -46,7 +46,6 @@ from portage.output import ConsoleStyleFile, StyleWriter
 from portage.util import formatter
 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
@@ -58,6 +57,7 @@ from repoman.checks.ebuilds.manifests import Manifests
 from repoman.check_missingslot import check_missingslot
 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
@@ -370,7 +370,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
 
@@ -633,32 +633,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"]
@@ -722,21 +703,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
 


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-09-17  3:08 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2015-09-17  3:08 UTC (permalink / raw
  To: gentoo-commits

commit:     d63aaac5ca2573ed8e00e21fe6c8730b0e34d979
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Wed Jun  4 14:17:49 2014 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Thu Sep 17 03:06:48 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=d63aaac5

repoman/main.py: More KEYWORDS checks to checks/ebuilds/keywords.py

 pym/repoman/checks/ebuilds/keywords.py | 64 ++++++++++++++++++++++++++++++----
 pym/repoman/main.py                    | 32 +----------------
 2 files changed, 59 insertions(+), 37 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/keywords.py b/pym/repoman/checks/ebuilds/keywords.py
index b724269..235c751 100644
--- a/pym/repoman/checks/ebuilds/keywords.py
+++ b/pym/repoman/checks/ebuilds/keywords.py
@@ -21,7 +21,7 @@ class KeywordChecks(object):
 
 	def check(
 		self, pkg, package, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-		live_ebuild):
+		live_ebuild, kwlist, profiles):
 		'''Perform the check.
 
 		@param pkg: Package in which we check (object).
@@ -33,21 +33,32 @@ class KeywordChecks(object):
 		@param changed: Changes instance
 		@param slot_keywords: A dictionary of keywords per slot.
 		@param live_ebuild: A boolean that determines if this is a live ebuild.
+		@param kwlist: A list of all global keywords.
+		@param profiles: A list of all profiles.
 		'''
 		if not self.options.straight_to_stable:
 			self._checkAddedWithStableKeywords(
 				package, ebuild, y_ebuild, keywords, changed)
+
 		self._checkForDroppedKeywords(
 			pkg, ebuild, ebuild_archs, live_ebuild)
 
+		self._checkForInvalidKeywords(
+			pkg, package, y_ebuild, kwlist, profiles)
+
+		self._checkForMaskLikeKeywords(
+			package, y_ebuild, keywords, kwlist)
+
 		self.slot_keywords[pkg.slot].update(ebuild_archs)
 
+	def _isKeywordStable(self, keyword):
+		return not keyword.startswith("~") and not keyword.startswith("-")
+
 	def _checkAddedWithStableKeywords(
 		self, package, ebuild, y_ebuild, keywords, changed):
 		catdir, pkgdir = package.split("/")
 
-		is_stable = lambda kw: not kw.startswith("~") and not kw.startswith("-")
-		stable_keywords = list(filter(is_stable, keywords))
+		stable_keywords = list(filter(self._isKeywordStable, keywords))
 		if stable_keywords:
 			if ebuild.ebuild_path in changed.new_ebuilds and catdir != "virtual":
 				stable_keywords.sort()
@@ -64,6 +75,47 @@ class KeywordChecks(object):
 		elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
 			dropped_keywords = previous_keywords.difference(ebuild_archs)
 			if dropped_keywords:
-				self.qatracker.add_error("KEYWORDS.dropped",
-					"%s: %s" %
-					(ebuild.relative_path, " ".join(sorted(dropped_keywords))))
+				self.qatracker.add_error(
+					"KEYWORDS.dropped", "%s: %s" % (
+						ebuild.relative_path,
+						" ".join(sorted(dropped_keywords))))
+
+	def _checkForInvalidKeywords(
+		self, pkg, package, y_ebuild, kwlist, profiles):
+		myuse = pkg._metadata["KEYWORDS"].split()
+
+		for mykey in myuse:
+			if mykey not in ("-*", "*", "~*"):
+				myskey = mykey
+
+				if not self._isKeywordStable(myskey[:1]):
+					myskey = myskey[1:]
+
+				if myskey not in kwlist:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s" % (
+							package, y_ebuild, mykey))
+				elif myskey not in profiles:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s (profile invalid)" % (
+							package, y_ebuild, mykey))
+
+	def _checkForMaskLikeKeywords(
+		self, package, y_ebuild, keywords, kwlist):
+
+		# KEYWORDS="-*" is a stupid replacement for package.mask
+		# and screws general KEYWORDS semantics
+		if "-*" in keywords:
+			haskeyword = False
+
+			for kw in keywords:
+				if kw[0] == "~":
+					kw = kw[1:]
+				if kw in kwlist:
+					haskeyword = True
+
+			if not haskeyword:
+				self.qatracker.add_error(
+					"KEYWORDS.stupid", package + "/" + y_ebuild + ".ebuild")

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index 7795f2f..db76d52 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -445,22 +445,9 @@ for xpkg in effective_scanlist:
 		#######################
 		keywordcheck.check(
 			pkg, xpkg, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-			live_ebuild)
+			live_ebuild, kwlist, profiles)
 		#######################
 
-		# KEYWORDS="-*" is a stupid replacement for package.mask
-		# and screws general KEYWORDS semantics
-		if "-*" in keywords:
-			haskeyword = False
-			for kw in keywords:
-				if kw[0] == "~":
-					kw = kw[1:]
-				if kw in kwlist:
-					haskeyword = True
-			if not haskeyword:
-				qatracker.add_error("KEYWORDS.stupid",
-					xpkg + "/" + y_ebuild + ".ebuild")
-
 		if live_ebuild and repo_settings.repo_config.name == "gentoo":
 			#######################
 			liveeclasscheck.check(
@@ -637,23 +624,6 @@ for xpkg in effective_scanlist:
 					qatracker.add_error("LICENSE.deprecated",
 						"%s: %s" % (ebuild.relative_path, lic))
 
-		# keyword checks
-		myuse = myaux["KEYWORDS"].split()
-		for mykey in myuse:
-			if mykey not in ("-*", "*", "~*"):
-				myskey = mykey
-				if myskey[:1] == "-":
-					myskey = myskey[1:]
-				if myskey[:1] == "~":
-					myskey = myskey[1:]
-				if myskey not in kwlist:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s" % (xpkg, y_ebuild, mykey))
-				elif myskey not in profiles:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s (profile invalid)"
-						% (xpkg, y_ebuild, mykey))
-
 		# restrict checks
 		myrestrict = None
 		try:


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-09-17  3:08 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2015-09-17  3:08 UTC (permalink / raw
  To: gentoo-commits

commit:     aa7f136978e5791cef265c5da82b8cdc9d2055c3
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  3 19:20:43 2014 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Thu Sep 17 03:06:47 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=aa7f1369

Repoman: Refactor PkgMetadata and XmlLint classes for variable data passed in

Move all non-consistent data to be passed in via the check functions.
Initialize XmlLint once in the PkgMetadata class __init__().

 pym/repoman/_xml.py                       | 33 ++++++++++++++++++++++---------
 pym/repoman/checks/ebuilds/pkgmetadata.py | 12 +++++------
 2 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/pym/repoman/_xml.py b/pym/repoman/_xml.py
index b97c027..d5b5a5e 100644
--- a/pym/repoman/_xml.py
+++ b/pym/repoman/_xml.py
@@ -14,6 +14,8 @@ from repoman._subprocess import repoman_getstatusoutput
 
 
 class _XMLParser(xml.etree.ElementTree.XMLParser):
+
+
 	def __init__(self, data, **kwargs):
 		xml.etree.ElementTree.XMLParser.__init__(self, **kwargs)
 		self._portage_data = data
@@ -25,11 +27,13 @@ class _XMLParser(xml.etree.ElementTree.XMLParser):
 			self.parser.StartDoctypeDeclHandler = \
 				self._portage_StartDoctypeDeclHandler
 
+
 	def _portage_XmlDeclHandler(self, version, encoding, standalone):
 		if self._base_XmlDeclHandler is not None:
 			self._base_XmlDeclHandler(version, encoding, standalone)
 		self._portage_data["XML_DECLARATION"] = (version, encoding, standalone)
 
+
 	def _portage_StartDoctypeDeclHandler(
 		self, doctypeName, systemId, publicId, has_internal_subset):
 		if self._base_StartDoctypeDeclHandler is not None:
@@ -49,33 +53,44 @@ class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
 
 class XmlLint(object):
 
-	def __init__(self, options, repolevel, repoman_settings):
+	def __init__(self, options, repoman_settings):
 		self.metadata_dtd = os.path.join(repoman_settings["DISTDIR"], 'metadata.dtd')
+		self.options = options
+		self.repoman_settings = repoman_settings
 		self._is_capable = False
 		self.binary = None
-		self._check_capable(options, repolevel, repoman_settings)
+		self._check_capable()
+
 
-	def _check_capable(self, options, repolevel, repoman_settings):
-		if options.mode == "manifest":
+	def _check_capable(self):
+		if self.options.mode == "manifest":
 			return
 		self.binary = find_binary('xmllint')
 		if not self.binary:
 			print(red("!!! xmllint not found. Can't check metadata.xml.\n"))
-			if options.xml_parse or repolevel == 3:
-				print("%s sorry, xmllint is needed.  failing\n" % red("!!!"))
-				sys.exit(1)
 		else:
-			if not fetch_metadata_dtd(self.metadata_dtd, repoman_settings):
+			if not fetch_metadata_dtd(self.metadata_dtd, self.repoman_settings):
 				sys.exit(1)
 			# this can be problematic if xmllint changes their output
 			self._is_capable = True
 
+
 	@property
 	def capable(self):
 		return self._is_capable
 
-	def check(self, checkdir):
+
+	def check(self, checkdir, repolevel):
+		'''Runs checks on the package metadata.xml file
+
+		@param checkdir: string, path
+		@param repolevel: integer
+		@return boolean, False == bad metadata
+		'''
 		if not self.capable:
+			if self.options.xml_parse or repolevel == 3:
+				print("%s sorry, xmllint is needed.  failing\n" % red("!!!"))
+				sys.exit(1)
 			return True
 		# xmlint can produce garbage output even on success, so only dump
 		# the ouput when it fails.

diff --git a/pym/repoman/checks/ebuilds/pkgmetadata.py b/pym/repoman/checks/ebuilds/pkgmetadata.py
index 0778696..674d32f 100644
--- a/pym/repoman/checks/ebuilds/pkgmetadata.py
+++ b/pym/repoman/checks/ebuilds/pkgmetadata.py
@@ -38,27 +38,28 @@ from repoman._xml import _XMLParser, _MetadataTreeBuilder, XmlLint
 class PkgMetadata(object):
 	'''Package metadata.xml checks'''
 
-	def __init__(self, options, qatracker, repolevel, repoman_settings):
+	def __init__(self, options, qatracker, repoman_settings):
 		'''PkgMetadata init function
 
 		@param options: ArgumentParser.parse_known_args(argv[1:]) options
 		@param qatracker: QATracker instance
-		@param repolevel: integer
 		@param repoman_settings: settings instance
 		'''
 		self.options = options
 		self.qatracker = qatracker
-		self.repolevel = repolevel
 		self.repoman_settings = repoman_settings
 		self.musedict = {}
+		self.xmllint = XmlLint(self.options, self.repoman_settings)
+
 
 
-	def check(self, xpkg, checkdir, checkdirlist):
+	def check(self, xpkg, checkdir, checkdirlist, repolevel):
 		'''Performs the checks on the metadata.xml for the package
 
 		@param xpkg: the pacakge being checked
 		@param checkdir: string, directory path
 		@param checkdirlist: list of checkdir's
+		@param repolevel: integer
 		'''
 
 		self.musedict = {}
@@ -165,8 +166,7 @@ class PkgMetadata(object):
 
 			# Only carry out if in package directory or check forced
 			if not metadata_bad:
-				xmllint = XmlLint(self.options, self.repolevel, self.repoman_settings)
-				if not xmllint.check(checkdir):
+				if not self.xmllint.check(checkdir, repolevel):
 					self.qatracker.add_error("metadata.bad", xpkg + "/metadata.xml")
 			del metadata_bad
 		return


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-09-17  4:51 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2015-09-17  4:51 UTC (permalink / raw
  To: gentoo-commits

commit:     41d11470db9553ed525d412f987fe967d7c57cad
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  3 11:15:10 2014 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Thu Sep 17 04:41:24 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=41d11470

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 c45af26..132f2f7 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -46,7 +46,6 @@ from portage.output import ConsoleStyleFile, StyleWriter
 from portage.util import formatter
 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
@@ -58,6 +57,7 @@ from repoman.checks.ebuilds.manifests import Manifests
 from repoman.check_missingslot import check_missingslot
 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
@@ -370,7 +370,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
 
@@ -633,32 +633,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"]
@@ -722,21 +703,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
 


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-09-17  4:51 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2015-09-17  4:51 UTC (permalink / raw
  To: gentoo-commits

commit:     33eb07b788baef1e063c4157d903cb14762a7518
Author:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
AuthorDate: Tue Jun  3 19:20:43 2014 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Thu Sep 17 04:41:25 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=33eb07b7

Repoman: Refactor PkgMetadata and XmlLint classes for variable data passed in

Move all non-consistent data to be passed in via the check functions.
Initialize XmlLint once in the PkgMetadata class __init__().

 pym/repoman/_xml.py                       | 33 ++++++++++++++++++++++---------
 pym/repoman/checks/ebuilds/pkgmetadata.py | 12 +++++------
 2 files changed, 30 insertions(+), 15 deletions(-)

diff --git a/pym/repoman/_xml.py b/pym/repoman/_xml.py
index b97c027..d5b5a5e 100644
--- a/pym/repoman/_xml.py
+++ b/pym/repoman/_xml.py
@@ -14,6 +14,8 @@ from repoman._subprocess import repoman_getstatusoutput
 
 
 class _XMLParser(xml.etree.ElementTree.XMLParser):
+
+
 	def __init__(self, data, **kwargs):
 		xml.etree.ElementTree.XMLParser.__init__(self, **kwargs)
 		self._portage_data = data
@@ -25,11 +27,13 @@ class _XMLParser(xml.etree.ElementTree.XMLParser):
 			self.parser.StartDoctypeDeclHandler = \
 				self._portage_StartDoctypeDeclHandler
 
+
 	def _portage_XmlDeclHandler(self, version, encoding, standalone):
 		if self._base_XmlDeclHandler is not None:
 			self._base_XmlDeclHandler(version, encoding, standalone)
 		self._portage_data["XML_DECLARATION"] = (version, encoding, standalone)
 
+
 	def _portage_StartDoctypeDeclHandler(
 		self, doctypeName, systemId, publicId, has_internal_subset):
 		if self._base_StartDoctypeDeclHandler is not None:
@@ -49,33 +53,44 @@ class _MetadataTreeBuilder(xml.etree.ElementTree.TreeBuilder):
 
 class XmlLint(object):
 
-	def __init__(self, options, repolevel, repoman_settings):
+	def __init__(self, options, repoman_settings):
 		self.metadata_dtd = os.path.join(repoman_settings["DISTDIR"], 'metadata.dtd')
+		self.options = options
+		self.repoman_settings = repoman_settings
 		self._is_capable = False
 		self.binary = None
-		self._check_capable(options, repolevel, repoman_settings)
+		self._check_capable()
+
 
-	def _check_capable(self, options, repolevel, repoman_settings):
-		if options.mode == "manifest":
+	def _check_capable(self):
+		if self.options.mode == "manifest":
 			return
 		self.binary = find_binary('xmllint')
 		if not self.binary:
 			print(red("!!! xmllint not found. Can't check metadata.xml.\n"))
-			if options.xml_parse or repolevel == 3:
-				print("%s sorry, xmllint is needed.  failing\n" % red("!!!"))
-				sys.exit(1)
 		else:
-			if not fetch_metadata_dtd(self.metadata_dtd, repoman_settings):
+			if not fetch_metadata_dtd(self.metadata_dtd, self.repoman_settings):
 				sys.exit(1)
 			# this can be problematic if xmllint changes their output
 			self._is_capable = True
 
+
 	@property
 	def capable(self):
 		return self._is_capable
 
-	def check(self, checkdir):
+
+	def check(self, checkdir, repolevel):
+		'''Runs checks on the package metadata.xml file
+
+		@param checkdir: string, path
+		@param repolevel: integer
+		@return boolean, False == bad metadata
+		'''
 		if not self.capable:
+			if self.options.xml_parse or repolevel == 3:
+				print("%s sorry, xmllint is needed.  failing\n" % red("!!!"))
+				sys.exit(1)
 			return True
 		# xmlint can produce garbage output even on success, so only dump
 		# the ouput when it fails.

diff --git a/pym/repoman/checks/ebuilds/pkgmetadata.py b/pym/repoman/checks/ebuilds/pkgmetadata.py
index 0778696..674d32f 100644
--- a/pym/repoman/checks/ebuilds/pkgmetadata.py
+++ b/pym/repoman/checks/ebuilds/pkgmetadata.py
@@ -38,27 +38,28 @@ from repoman._xml import _XMLParser, _MetadataTreeBuilder, XmlLint
 class PkgMetadata(object):
 	'''Package metadata.xml checks'''
 
-	def __init__(self, options, qatracker, repolevel, repoman_settings):
+	def __init__(self, options, qatracker, repoman_settings):
 		'''PkgMetadata init function
 
 		@param options: ArgumentParser.parse_known_args(argv[1:]) options
 		@param qatracker: QATracker instance
-		@param repolevel: integer
 		@param repoman_settings: settings instance
 		'''
 		self.options = options
 		self.qatracker = qatracker
-		self.repolevel = repolevel
 		self.repoman_settings = repoman_settings
 		self.musedict = {}
+		self.xmllint = XmlLint(self.options, self.repoman_settings)
+
 
 
-	def check(self, xpkg, checkdir, checkdirlist):
+	def check(self, xpkg, checkdir, checkdirlist, repolevel):
 		'''Performs the checks on the metadata.xml for the package
 
 		@param xpkg: the pacakge being checked
 		@param checkdir: string, directory path
 		@param checkdirlist: list of checkdir's
+		@param repolevel: integer
 		'''
 
 		self.musedict = {}
@@ -165,8 +166,7 @@ class PkgMetadata(object):
 
 			# Only carry out if in package directory or check forced
 			if not metadata_bad:
-				xmllint = XmlLint(self.options, self.repolevel, self.repoman_settings)
-				if not xmllint.check(checkdir):
+				if not self.xmllint.check(checkdir, repolevel):
 					self.qatracker.add_error("metadata.bad", xpkg + "/metadata.xml")
 			del metadata_bad
 		return


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-09-17  4:51 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2015-09-17  4:51 UTC (permalink / raw
  To: gentoo-commits

commit:     0983c08bedbda4efd645e29624f093ae4167c346
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Wed Jun  4 14:17:49 2014 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Thu Sep 17 04:41:27 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=0983c08b

repoman/main.py: More KEYWORDS checks to checks/ebuilds/keywords.py

 pym/repoman/checks/ebuilds/keywords.py | 64 ++++++++++++++++++++++++++++++----
 pym/repoman/main.py                    | 32 +----------------
 2 files changed, 59 insertions(+), 37 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/keywords.py b/pym/repoman/checks/ebuilds/keywords.py
index b724269..235c751 100644
--- a/pym/repoman/checks/ebuilds/keywords.py
+++ b/pym/repoman/checks/ebuilds/keywords.py
@@ -21,7 +21,7 @@ class KeywordChecks(object):
 
 	def check(
 		self, pkg, package, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-		live_ebuild):
+		live_ebuild, kwlist, profiles):
 		'''Perform the check.
 
 		@param pkg: Package in which we check (object).
@@ -33,21 +33,32 @@ class KeywordChecks(object):
 		@param changed: Changes instance
 		@param slot_keywords: A dictionary of keywords per slot.
 		@param live_ebuild: A boolean that determines if this is a live ebuild.
+		@param kwlist: A list of all global keywords.
+		@param profiles: A list of all profiles.
 		'''
 		if not self.options.straight_to_stable:
 			self._checkAddedWithStableKeywords(
 				package, ebuild, y_ebuild, keywords, changed)
+
 		self._checkForDroppedKeywords(
 			pkg, ebuild, ebuild_archs, live_ebuild)
 
+		self._checkForInvalidKeywords(
+			pkg, package, y_ebuild, kwlist, profiles)
+
+		self._checkForMaskLikeKeywords(
+			package, y_ebuild, keywords, kwlist)
+
 		self.slot_keywords[pkg.slot].update(ebuild_archs)
 
+	def _isKeywordStable(self, keyword):
+		return not keyword.startswith("~") and not keyword.startswith("-")
+
 	def _checkAddedWithStableKeywords(
 		self, package, ebuild, y_ebuild, keywords, changed):
 		catdir, pkgdir = package.split("/")
 
-		is_stable = lambda kw: not kw.startswith("~") and not kw.startswith("-")
-		stable_keywords = list(filter(is_stable, keywords))
+		stable_keywords = list(filter(self._isKeywordStable, keywords))
 		if stable_keywords:
 			if ebuild.ebuild_path in changed.new_ebuilds and catdir != "virtual":
 				stable_keywords.sort()
@@ -64,6 +75,47 @@ class KeywordChecks(object):
 		elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
 			dropped_keywords = previous_keywords.difference(ebuild_archs)
 			if dropped_keywords:
-				self.qatracker.add_error("KEYWORDS.dropped",
-					"%s: %s" %
-					(ebuild.relative_path, " ".join(sorted(dropped_keywords))))
+				self.qatracker.add_error(
+					"KEYWORDS.dropped", "%s: %s" % (
+						ebuild.relative_path,
+						" ".join(sorted(dropped_keywords))))
+
+	def _checkForInvalidKeywords(
+		self, pkg, package, y_ebuild, kwlist, profiles):
+		myuse = pkg._metadata["KEYWORDS"].split()
+
+		for mykey in myuse:
+			if mykey not in ("-*", "*", "~*"):
+				myskey = mykey
+
+				if not self._isKeywordStable(myskey[:1]):
+					myskey = myskey[1:]
+
+				if myskey not in kwlist:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s" % (
+							package, y_ebuild, mykey))
+				elif myskey not in profiles:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s (profile invalid)" % (
+							package, y_ebuild, mykey))
+
+	def _checkForMaskLikeKeywords(
+		self, package, y_ebuild, keywords, kwlist):
+
+		# KEYWORDS="-*" is a stupid replacement for package.mask
+		# and screws general KEYWORDS semantics
+		if "-*" in keywords:
+			haskeyword = False
+
+			for kw in keywords:
+				if kw[0] == "~":
+					kw = kw[1:]
+				if kw in kwlist:
+					haskeyword = True
+
+			if not haskeyword:
+				self.qatracker.add_error(
+					"KEYWORDS.stupid", package + "/" + y_ebuild + ".ebuild")

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index 4ded687..ea54ec4 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -445,22 +445,9 @@ for xpkg in effective_scanlist:
 		#######################
 		keywordcheck.check(
 			pkg, xpkg, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-			live_ebuild)
+			live_ebuild, kwlist, profiles)
 		#######################
 
-		# KEYWORDS="-*" is a stupid replacement for package.mask
-		# and screws general KEYWORDS semantics
-		if "-*" in keywords:
-			haskeyword = False
-			for kw in keywords:
-				if kw[0] == "~":
-					kw = kw[1:]
-				if kw in kwlist:
-					haskeyword = True
-			if not haskeyword:
-				qatracker.add_error("KEYWORDS.stupid",
-					xpkg + "/" + y_ebuild + ".ebuild")
-
 		if live_ebuild and repo_settings.repo_config.name == "gentoo":
 			#######################
 			liveeclasscheck.check(
@@ -637,23 +624,6 @@ for xpkg in effective_scanlist:
 					qatracker.add_error("LICENSE.deprecated",
 						"%s: %s" % (ebuild.relative_path, lic))
 
-		# keyword checks
-		myuse = myaux["KEYWORDS"].split()
-		for mykey in myuse:
-			if mykey not in ("-*", "*", "~*"):
-				myskey = mykey
-				if myskey[:1] == "-":
-					myskey = myskey[1:]
-				if myskey[:1] == "~":
-					myskey = myskey[1:]
-				if myskey not in kwlist:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s" % (xpkg, y_ebuild, mykey))
-				elif myskey not in profiles:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s (profile invalid)"
-						% (xpkg, y_ebuild, mykey))
-
 		# restrict checks
 		myrestrict = None
 		try:


^ permalink raw reply related	[flat|nested] 34+ messages in thread

* [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/
@ 2015-09-20  2:06 Brian Dolbec
  0 siblings, 0 replies; 34+ messages in thread
From: Brian Dolbec @ 2015-09-20  2:06 UTC (permalink / raw
  To: gentoo-commits

commit:     c0d5f1a033ba73a3557be7daab1a488c3b9984c8
Author:     Tom Wijsman <tomwij <AT> gentoo <DOT> org>
AuthorDate: Wed Jun  4 14:17:49 2014 +0000
Commit:     Brian Dolbec <dolsen <AT> gentoo <DOT> org>
CommitDate: Sun Sep 20 01:54:07 2015 +0000
URL:        https://gitweb.gentoo.org/proj/portage.git/commit/?id=c0d5f1a0

repoman/main.py: More KEYWORDS checks to checks/ebuilds/keywords.py

 pym/repoman/checks/ebuilds/keywords.py | 64 ++++++++++++++++++++++++++++++----
 pym/repoman/main.py                    | 32 +----------------
 2 files changed, 59 insertions(+), 37 deletions(-)

diff --git a/pym/repoman/checks/ebuilds/keywords.py b/pym/repoman/checks/ebuilds/keywords.py
index b724269..235c751 100644
--- a/pym/repoman/checks/ebuilds/keywords.py
+++ b/pym/repoman/checks/ebuilds/keywords.py
@@ -21,7 +21,7 @@ class KeywordChecks(object):
 
 	def check(
 		self, pkg, package, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-		live_ebuild):
+		live_ebuild, kwlist, profiles):
 		'''Perform the check.
 
 		@param pkg: Package in which we check (object).
@@ -33,21 +33,32 @@ class KeywordChecks(object):
 		@param changed: Changes instance
 		@param slot_keywords: A dictionary of keywords per slot.
 		@param live_ebuild: A boolean that determines if this is a live ebuild.
+		@param kwlist: A list of all global keywords.
+		@param profiles: A list of all profiles.
 		'''
 		if not self.options.straight_to_stable:
 			self._checkAddedWithStableKeywords(
 				package, ebuild, y_ebuild, keywords, changed)
+
 		self._checkForDroppedKeywords(
 			pkg, ebuild, ebuild_archs, live_ebuild)
 
+		self._checkForInvalidKeywords(
+			pkg, package, y_ebuild, kwlist, profiles)
+
+		self._checkForMaskLikeKeywords(
+			package, y_ebuild, keywords, kwlist)
+
 		self.slot_keywords[pkg.slot].update(ebuild_archs)
 
+	def _isKeywordStable(self, keyword):
+		return not keyword.startswith("~") and not keyword.startswith("-")
+
 	def _checkAddedWithStableKeywords(
 		self, package, ebuild, y_ebuild, keywords, changed):
 		catdir, pkgdir = package.split("/")
 
-		is_stable = lambda kw: not kw.startswith("~") and not kw.startswith("-")
-		stable_keywords = list(filter(is_stable, keywords))
+		stable_keywords = list(filter(self._isKeywordStable, keywords))
 		if stable_keywords:
 			if ebuild.ebuild_path in changed.new_ebuilds and catdir != "virtual":
 				stable_keywords.sort()
@@ -64,6 +75,47 @@ class KeywordChecks(object):
 		elif ebuild_archs and "*" not in ebuild_archs and not live_ebuild:
 			dropped_keywords = previous_keywords.difference(ebuild_archs)
 			if dropped_keywords:
-				self.qatracker.add_error("KEYWORDS.dropped",
-					"%s: %s" %
-					(ebuild.relative_path, " ".join(sorted(dropped_keywords))))
+				self.qatracker.add_error(
+					"KEYWORDS.dropped", "%s: %s" % (
+						ebuild.relative_path,
+						" ".join(sorted(dropped_keywords))))
+
+	def _checkForInvalidKeywords(
+		self, pkg, package, y_ebuild, kwlist, profiles):
+		myuse = pkg._metadata["KEYWORDS"].split()
+
+		for mykey in myuse:
+			if mykey not in ("-*", "*", "~*"):
+				myskey = mykey
+
+				if not self._isKeywordStable(myskey[:1]):
+					myskey = myskey[1:]
+
+				if myskey not in kwlist:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s" % (
+							package, y_ebuild, mykey))
+				elif myskey not in profiles:
+					self.qatracker.add_error(
+						"KEYWORDS.invalid",
+						"%s/%s.ebuild: %s (profile invalid)" % (
+							package, y_ebuild, mykey))
+
+	def _checkForMaskLikeKeywords(
+		self, package, y_ebuild, keywords, kwlist):
+
+		# KEYWORDS="-*" is a stupid replacement for package.mask
+		# and screws general KEYWORDS semantics
+		if "-*" in keywords:
+			haskeyword = False
+
+			for kw in keywords:
+				if kw[0] == "~":
+					kw = kw[1:]
+				if kw in kwlist:
+					haskeyword = True
+
+			if not haskeyword:
+				self.qatracker.add_error(
+					"KEYWORDS.stupid", package + "/" + y_ebuild + ".ebuild")

diff --git a/pym/repoman/main.py b/pym/repoman/main.py
index 4ded687..ea54ec4 100755
--- a/pym/repoman/main.py
+++ b/pym/repoman/main.py
@@ -445,22 +445,9 @@ for xpkg in effective_scanlist:
 		#######################
 		keywordcheck.check(
 			pkg, xpkg, ebuild, y_ebuild, keywords, ebuild_archs, changed,
-			live_ebuild)
+			live_ebuild, kwlist, profiles)
 		#######################
 
-		# KEYWORDS="-*" is a stupid replacement for package.mask
-		# and screws general KEYWORDS semantics
-		if "-*" in keywords:
-			haskeyword = False
-			for kw in keywords:
-				if kw[0] == "~":
-					kw = kw[1:]
-				if kw in kwlist:
-					haskeyword = True
-			if not haskeyword:
-				qatracker.add_error("KEYWORDS.stupid",
-					xpkg + "/" + y_ebuild + ".ebuild")
-
 		if live_ebuild and repo_settings.repo_config.name == "gentoo":
 			#######################
 			liveeclasscheck.check(
@@ -637,23 +624,6 @@ for xpkg in effective_scanlist:
 					qatracker.add_error("LICENSE.deprecated",
 						"%s: %s" % (ebuild.relative_path, lic))
 
-		# keyword checks
-		myuse = myaux["KEYWORDS"].split()
-		for mykey in myuse:
-			if mykey not in ("-*", "*", "~*"):
-				myskey = mykey
-				if myskey[:1] == "-":
-					myskey = myskey[1:]
-				if myskey[:1] == "~":
-					myskey = myskey[1:]
-				if myskey not in kwlist:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s" % (xpkg, y_ebuild, mykey))
-				elif myskey not in profiles:
-					qatracker.add_error("KEYWORDS.invalid",
-						"%s/%s.ebuild: %s (profile invalid)"
-						% (xpkg, y_ebuild, mykey))
-
 		# restrict checks
 		myrestrict = None
 		try:


^ permalink raw reply related	[flat|nested] 34+ messages in thread

end of thread, other threads:[~2015-09-20  2:06 UTC | newest]

Thread overview: 34+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2015-08-10 13:44 [gentoo-commits] proj/portage:repoman commit in: pym/repoman/, pym/repoman/checks/ebuilds/ Brian Dolbec
  -- strict thread matches above, loose matches on Subject: below --
2015-09-20  2:06 Brian Dolbec
2015-09-17  4:51 Brian Dolbec
2015-09-17  4:51 Brian Dolbec
2015-09-17  4:51 Brian Dolbec
2015-09-17  3:08 Brian Dolbec
2015-09-17  3:08 Brian Dolbec
2015-09-17  3:08 Brian Dolbec
2015-09-05 21:48 Brian Dolbec
2015-09-05 21:48 Brian Dolbec
2015-09-05 21:48 Brian Dolbec
2015-08-11 23:54 Brian Dolbec
2015-08-11 23:54 Brian Dolbec
2015-08-10 14:45 Michał Górny
2015-08-10 13:44 Brian Dolbec
2015-08-10 13:44 Brian Dolbec
2014-11-17  0:55 Brian Dolbec
2014-11-17  0:55 Brian Dolbec
2014-11-17  0:55 Brian Dolbec
2014-10-01 23:46 Brian Dolbec
2014-10-01 23:46 Brian Dolbec
2014-10-01 23:46 Brian Dolbec
2014-10-01 23:02 Brian Dolbec
2014-10-01 23:02 Brian Dolbec
2014-06-04 14:18 Tom Wijsman
2014-06-04  9:18 Tom Wijsman
2014-06-03 19:33 Brian Dolbec
2014-06-03 11:16 Tom Wijsman
2014-06-02  6:44 Brian Dolbec
2014-06-02  6:05 Brian Dolbec
2014-06-02  3:35 Brian Dolbec
2014-06-02  1:10 Brian Dolbec
2014-05-30 13:03 Brian Dolbec
2014-05-30 13:03 Brian Dolbec

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox