From mboxrd@z Thu Jan  1 00:00:00 1970
Received: from pigeon.gentoo.org ([208.92.234.80] helo=lists.gentoo.org)
	by finch.gentoo.org with esmtp (Exim 4.60)
	(envelope-from <gentoo-commits+bounces-469362-garchives=archives.gentoo.org@lists.gentoo.org>)
	id 1SZPw5-0001f2-UM
	for garchives@archives.gentoo.org; Tue, 29 May 2012 17:10:22 +0000
Received: from pigeon.gentoo.org (localhost [127.0.0.1])
	by pigeon.gentoo.org (Postfix) with SMTP id E2F0CE0768;
	Tue, 29 May 2012 17:09:34 +0000 (UTC)
Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183])
	by pigeon.gentoo.org (Postfix) with ESMTP id A035CE0654
	for <gentoo-commits@lists.gentoo.org>; Tue, 29 May 2012 17:09:34 +0000 (UTC)
Received: from hornbill.gentoo.org (hornbill.gentoo.org [94.100.119.163])
	(using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits))
	(No client certificate requested)
	by smtp.gentoo.org (Postfix) with ESMTPS id CE3481B404C
	for <gentoo-commits@lists.gentoo.org>; Tue, 29 May 2012 17:09:33 +0000 (UTC)
Received: from localhost.localdomain (localhost [127.0.0.1])
	by hornbill.gentoo.org (Postfix) with ESMTP id 0B846E5428
	for <gentoo-commits@lists.gentoo.org>; Tue, 29 May 2012 17:09:32 +0000 (UTC)
From: "André Erdmann" <dywi@mailerd.de>
To: gentoo-commits@lists.gentoo.org
Content-type: text/plain; charset=UTF-8
Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" <dywi@mailerd.de>
Message-ID: <1338310856.033f6e38ee070ee1e71563bbc8d3a308604706e0.dywi@gentoo>
Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/
X-VCS-Repository: proj/R_overlay
X-VCS-Files: roverlay/fileio.py
X-VCS-Directories: roverlay/
X-VCS-Committer: dywi
X-VCS-Committer-Name: André Erdmann
X-VCS-Revision: 033f6e38ee070ee1e71563bbc8d3a308604706e0
X-VCS-Branch: master
Date: Tue, 29 May 2012 17:09:32 +0000 (UTC)
Precedence: bulk
List-Post: <mailto:gentoo-commits@lists.gentoo.org>
List-Help: <mailto:gentoo-commits+help@lists.gentoo.org>
List-Unsubscribe: <mailto:gentoo-commits+unsubscribe@lists.gentoo.org>
List-Subscribe: <mailto:gentoo-commits+subscribe@lists.gentoo.org>
List-Id: Gentoo Linux mail <gentoo-commits.gentoo.org>
X-BeenThere: gentoo-commits@lists.gentoo.org
Content-Transfer-Encoding: quoted-printable
X-Archives-Salt: 29f76242-2316-40ec-8c35-a1ccbe2e86a8
X-Archives-Hash: 0bbea38dbbb96a920fa24897b01bde2a

commit:     033f6e38ee070ee1e71563bbc8d3a308604706e0
Author:     Andre Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue May 29 17:00:56 2012 +0000
Commit:     Andr=C3=A9 Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue May 29 17:00:56 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=3Dproj/R_overlay.git=
;a=3Dcommit;h=3D033f6e38

roverlay, fileio: add possibility to ignore packages with unsuitable desc=
ription data (os type); rename _verify_read_data -> _parse_read_data
	modified:   fileio.py

---
 roverlay/fileio.py |  115 +++++++++++++++++++++++++++++++++++++---------=
-----
 1 files changed, 83 insertions(+), 32 deletions(-)

diff --git a/roverlay/fileio.py b/roverlay/fileio.py
index 6e905b9..5d13cf8 100644
--- a/roverlay/fileio.py
+++ b/roverlay/fileio.py
@@ -49,7 +49,7 @@ class DescriptionReader:
 		a field listed in DESCRIPTION_FIELD_MAP (any match results in immediat=
e return).
 		Then, a new iteration over the field map compares field_identifier
 		with all aliases until the first case-(in)sensitive match (-> immediat=
e return).
-		An emptry string will be returned if none of the above searches succee=
d.
+		None will be returned if none of the above searches succeed.
=20
 		In other words: this method decides whether a field_identifier will be=
 used and if so,
 		with which name.
@@ -224,11 +224,13 @@ class DescriptionReader:
 			package_version =3D package_version,
 		)
=20
-
-
 	@classmethod
-	def _verify_read_data ( self, read_data ):
-		"""Verifies and fixes (e.g. add default values) read data"""
+	def _parse_read_data ( self, read_data ):
+		"""Verifies and parses/fixes read data.
+
+		arguments:
+		* read_data -- data from file, will be modified
+		"""
=20
 		def stats ( data ):
 			"""Temporary function that prints some info about the given data."""
@@ -239,49 +241,92 @@ class DescriptionReader:
 			logging.write ( "=3D=3D=3D end of list =3D=3D=3D\n" )
 			del field
=20
+		def _value_in_strlist ( _val, _list, case_insensitive=3DTrue ):
+			"""Returns true if value is in the given list."""
+			el =3D None
+			if case_insensitive:
+				lowval =3D _val.lower()
+				for el in _list:
+					if el.lower() =3D=3D lowval:
+						return True
+				del lowval
+			else:
+				for el in _list:
+					if el =3D=3D _val:
+						return True
+
+			del el
+			return False
+
+
 		stats ( read_data )
=20
-		# "finalize" data
-		logging.write ( "Fixing data...\n" )
 		field =3D None
=20
-		# join values to a single str
+		# insert default values
+		for field in const.DESCRIPTION_FIELD_MAP.keys():
+			if not field in read_data and 'default_value' in const.DESCRIPTION_FI=
ELD_MAP [field]:
+				read_data [field] =3D const.DESCRIPTION_FIELD_MAP [field] ['default_=
value']
+
+		# join values to a single string
 		for field in self._get_fields_with_flag ( 'joinValues' ):
 			if field in read_data.keys():
 				read_data [field] =3D ' ' . join ( read_data [field] )
=20
-		# verify that all necessary fields have been added and are set
-		missing_fields =3D dict()
+		# ensure that all mandatory fields are set
+		missing_fields =3D list()
+
 		for field in self._get_fields_with_flag ( 'mandatory' ):
 			if field in read_data:
 				if not len (read_data [field]):
-					missing_fields [field] =3D 'unset'
+					missing_fields.append ( field )
 			else:
-				missing_fields [field] =3D 'missing'
+				missing_fields.append ( field )
=20
-		del field
=20
-		if len (missing_fields):
+
+
+		# check for fields that allow only certain values
+		unsuitable_fields =3D list()
+
+		for field in read_data.keys():
+			# skip _fileinfo
+			if field  !=3D '_fileinfo':
+				if 'allowed_values' in const.DESCRIPTION_FIELD_MAP [field]:
+					if not _value_in_strlist ( read_data [field],
+						const.DESCRIPTION_FIELD_MAP [field] ['allowed_values']
+					): unsuitable_fields.append ( field )
+
+
+		stats ( read_data )
+
+
+
+		valid =3D True
+
+		if len ( missing_fields ):
+			valid =3D False
+
 			logging.write (
 				"Verification of mandatory fields failed, the result leading to this=
 was: " +
-				str (missing_fields) + "\n"
+				str ( missing_fields ) + "\n"
 			)
=20
 			#<raise custom exception>
 			raise Exception ("^^^look above")
=20
-		del missing_fields
+		if len ( unsuitable_fields ):
+			valid =3D False
=20
-		# add/insert default values
-		for field in const.DESCRIPTION_FIELD_MAP.keys():
-			if not field in read_data and 'default_value' in const.DESCRIPTION_FI=
ELD_MAP [field]:
-				read_data [field] =3D const.DESCRIPTION_FIELD_MAP [field] ['default_=
value']
-
-
-		stats ( read_data )
+			logging.write (
+				"Some fields have values that forbid further parsing, the result lea=
ding to this was: " +
+					str ( unsuitable_fields ) + "\n"
+				)
=20
-		return True
+		del missing_fields
+		del field
=20
+		return valid
=20
 	@classmethod
 	def readfile ( self, filepath ):
@@ -296,18 +341,18 @@ class DescriptionReader:
 		-> split field values
 		-> filter out unwanted/useless fields
=20
-		The return value is a dict "<field name> =3D> <field value[s]>"
-		with <field value> as str and <field values> as list.
+		The return value is a dict { fileinfo , description_data } or None if
+		the read data are "useless" (not suited to create an ebuild for it,
+		e.g. if OS_TYPE is not unix).
 		"""
=20
-		read_data =3D dict (
-			_ =3D DescriptionReader._get_fileinfo ( filepath )
-		)
+		read_data =3D dict ()
+		fileinfo =3D DescriptionReader._get_fileinfo ( filepath )
=20
=20
 		try:
 			desc_lines =3D DescriptionReader._get_desc_from_file (
-				filepath, read_data ['_'] ['package_name']
+				filepath, fileinfo ['package_name']
 			)
=20
=20
@@ -377,8 +422,14 @@ class DescriptionReader:
 		del sline, line, val, field_context
=20
=20
-		if self._verify_read_data ( read_data ):
-			return read_data
+		if self._parse_read_data ( read_data ):
+			logging.write ( '## success ##\n' )
+			logging.write ( ( str ( read_data ) ) )
+			return dict (
+				fileinfo =3D fileinfo,
+				description_data =3D read_data
+			)
 		else:
+			logging.write ( '## fail ##\n' )
 			return None
=20