public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
From: "André Erdmann" <dywi@mailerd.de>
To: gentoo-commits@lists.gentoo.org
Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/
Date: Tue, 29 May 2012 17:09:32 +0000 (UTC)	[thread overview]
Message-ID: <1338310856.033f6e38ee070ee1e71563bbc8d3a308604706e0.dywi@gentoo> (raw)

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

roverlay, fileio: add possibility to ignore packages with unsuitable description 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 immediate return).
 		Then, a new iteration over the field map compares field_identifier
 		with all aliases until the first case-(in)sensitive match (-> immediate return).
-		An emptry string will be returned if none of the above searches succeed.
+		None will be returned if none of the above searches succeed.
 
 		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 = package_version,
 		)
 
-
-
 	@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
+		"""
 
 		def stats ( data ):
 			"""Temporary function that prints some info about the given data."""
@@ -239,49 +241,92 @@ class DescriptionReader:
 			logging.write ( "=== end of list ===\n" )
 			del field
 
+		def _value_in_strlist ( _val, _list, case_insensitive=True ):
+			"""Returns true if value is in the given list."""
+			el = None
+			if case_insensitive:
+				lowval = _val.lower()
+				for el in _list:
+					if el.lower() == lowval:
+						return True
+				del lowval
+			else:
+				for el in _list:
+					if el == _val:
+						return True
+
+			del el
+			return False
+
+
 		stats ( read_data )
 
-		# "finalize" data
-		logging.write ( "Fixing data...\n" )
 		field = None
 
-		# 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_FIELD_MAP [field]:
+				read_data [field] = 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] = ' ' . join ( read_data [field] )
 
-		# verify that all necessary fields have been added and are set
-		missing_fields = dict()
+		# ensure that all mandatory fields are set
+		missing_fields = list()
+
 		for field in self._get_fields_with_flag ( 'mandatory' ):
 			if field in read_data:
 				if not len (read_data [field]):
-					missing_fields [field] = 'unset'
+					missing_fields.append ( field )
 			else:
-				missing_fields [field] = 'missing'
+				missing_fields.append ( field )
 
-		del field
 
-		if len (missing_fields):
+
+
+		# check for fields that allow only certain values
+		unsuitable_fields = list()
+
+		for field in read_data.keys():
+			# skip _fileinfo
+			if field  != '_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 = True
+
+		if len ( missing_fields ):
+			valid = False
+
 			logging.write (
 				"Verification of mandatory fields failed, the result leading to this was: " +
-				str (missing_fields) + "\n"
+				str ( missing_fields ) + "\n"
 			)
 
 			#<raise custom exception>
 			raise Exception ("^^^look above")
 
-		del missing_fields
+		if len ( unsuitable_fields ):
+			valid = False
 
-		# add/insert default values
-		for field in const.DESCRIPTION_FIELD_MAP.keys():
-			if not field in read_data and 'default_value' in const.DESCRIPTION_FIELD_MAP [field]:
-				read_data [field] = const.DESCRIPTION_FIELD_MAP [field] ['default_value']
-
-
-		stats ( read_data )
+			logging.write (
+				"Some fields have values that forbid further parsing, the result leading to this was: " +
+					str ( unsuitable_fields ) + "\n"
+				)
 
-		return True
+		del missing_fields
+		del field
 
+		return valid
 
 	@classmethod
 	def readfile ( self, filepath ):
@@ -296,18 +341,18 @@ class DescriptionReader:
 		-> split field values
 		-> filter out unwanted/useless fields
 
-		The return value is a dict "<field name> => <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).
 		"""
 
-		read_data = dict (
-			_ = DescriptionReader._get_fileinfo ( filepath )
-		)
+		read_data = dict ()
+		fileinfo = DescriptionReader._get_fileinfo ( filepath )
 
 
 		try:
 			desc_lines = DescriptionReader._get_desc_from_file (
-				filepath, read_data ['_'] ['package_name']
+				filepath, fileinfo ['package_name']
 			)
 
 
@@ -377,8 +422,14 @@ class DescriptionReader:
 		del sline, line, val, field_context
 
 
-		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 = fileinfo,
+				description_data = read_data
+			)
 		else:
+			logging.write ( '## fail ##\n' )
 			return None
 



             reply	other threads:[~2012-05-29 17:10 UTC|newest]

Thread overview: 159+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-29 17:09 André Erdmann [this message]
  -- strict thread matches above, loose matches on Subject: below --
2015-01-26 17:41 [gentoo-commits] proj/R_overlay:master commit in: roverlay/ André Erdmann
2015-01-26 17:41 André Erdmann
2014-07-18 16:20 André Erdmann
2014-07-18  2:50 [gentoo-commits] proj/R_overlay:wip/addition_control " André Erdmann
2014-07-18 16:20 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2014-07-18  2:28 [gentoo-commits] proj/R_overlay:wip/addition_control " André Erdmann
2014-07-18 16:20 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2014-07-16 15:14 André Erdmann
2014-06-05 22:09 André Erdmann
2014-04-01 16:38 André Erdmann
2014-02-16 16:30 André Erdmann
2014-02-15 19:49 André Erdmann
2014-02-15 19:49 André Erdmann
2014-01-25 18:14 André Erdmann
2013-12-11 18:40 André Erdmann
2013-12-11 18:40 André Erdmann
2013-09-23 15:30 André Erdmann
2013-09-20 15:57 André Erdmann
2013-09-19 15:00 André Erdmann
2013-09-17 16:40 André Erdmann
2013-09-17 16:40 André Erdmann
2013-09-17 16:40 André Erdmann
2013-09-17 16:40 André Erdmann
2013-09-16 13:43 André Erdmann
2013-09-13 15:10 André Erdmann
2013-09-12 16:36 André Erdmann
2013-09-12 16:36 André Erdmann
2013-09-12 16:36 André Erdmann
2013-09-11 11:14 André Erdmann
2013-09-11 10:19 André Erdmann
2013-09-10 14:40 André Erdmann
2013-09-10 14:40 André Erdmann
2013-09-10 14:40 André Erdmann
2013-09-10 14:40 André Erdmann
2013-09-06 17:27 André Erdmann
2013-09-06 17:27 André Erdmann
2013-09-03 15:50 André Erdmann
2013-09-02 12:27 André Erdmann
2013-09-02  8:44 André Erdmann
2013-08-30 14:49 André Erdmann
2013-08-30 14:49 André Erdmann
2013-08-29 12:36 André Erdmann
2013-08-29 12:36 André Erdmann
2013-08-28 15:54 André Erdmann
2013-08-27 15:39 André Erdmann
2013-08-23 13:52 André Erdmann
2013-08-23 13:52 André Erdmann
2013-08-23 13:52 André Erdmann
2013-08-19 15:42 André Erdmann
2013-08-16 14:05 André Erdmann
2013-08-16 11:02 André Erdmann
2013-08-16 10:43 André Erdmann
2013-08-16 10:43 André Erdmann
2013-08-14 14:56 André Erdmann
2013-08-14 14:56 André Erdmann
2013-08-13  8:56 André Erdmann
2013-08-13  8:56 André Erdmann
2013-08-13  8:56 André Erdmann
2013-08-12  8:28 André Erdmann
2013-08-12  8:18 André Erdmann
2013-08-07 16:10 André Erdmann
2013-08-02 14:30 André Erdmann
2013-08-02 10:34 André Erdmann
2013-08-02 10:34 André Erdmann
2013-08-01 12:44 André Erdmann
2013-08-01 12:44 André Erdmann
2013-07-29 14:56 André Erdmann
2013-07-29  8:55 André Erdmann
2013-07-26 13:02 André Erdmann
2013-07-23  7:51 André Erdmann
2013-07-23  7:51 André Erdmann
2013-07-19 18:00 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-23  7:51 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-17 18:05 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-17 18:05 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-15 22:31 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-16 16:36 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-07-12 13:57 André Erdmann
2013-06-22 15:24 André Erdmann
2013-06-22 15:24 André Erdmann
2013-06-22 15:24 André Erdmann
2013-06-22 15:24 André Erdmann
2013-06-19 18:58 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-06-22 15:24 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-19 18:58 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-06-19 18:59 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-13 16:34 André Erdmann
2013-06-05 18:08 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-06-13 16:34 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-05 18:08 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-06-13 16:34 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-04 21:06 André Erdmann
2013-04-25 16:44 André Erdmann
2013-04-25 16:44 André Erdmann
2013-03-05 11:27 André Erdmann
2013-02-09 20:45 André Erdmann
2013-02-05 17:48 André Erdmann
2013-02-05 17:48 André Erdmann
2013-01-30 20:16 André Erdmann
2013-01-30 20:16 André Erdmann
2013-01-28 23:54 André Erdmann
2013-01-28 23:54 André Erdmann
2013-01-28 23:54 André Erdmann
2012-10-02 10:04 André Erdmann
2012-08-20 11:16 André Erdmann
2012-08-13 18:07 André Erdmann
2012-08-09  9:26 André Erdmann
2012-08-08 23:46 André Erdmann
2012-08-08 23:46 André Erdmann
2012-08-07  8:50 André Erdmann
2012-08-02 15:14 André Erdmann
2012-08-01  7:25 André Erdmann
2012-07-31 17:51 André Erdmann
2012-07-30  8:52 André Erdmann
2012-07-30  8:52 André Erdmann
2012-07-24 16:59 [gentoo-commits] proj/R_overlay:overlay_wip " André Erdmann
2012-07-30  8:52 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2012-07-18 16:49 [gentoo-commits] proj/R_overlay:overlay_wip " André Erdmann
2012-07-30  8:52 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2012-07-16 16:15 André Erdmann
2012-07-16 16:15 André Erdmann
2012-07-16 16:15 [gentoo-commits] proj/R_overlay:depres_wip " André Erdmann
2012-07-16 16:15 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2012-07-10 17:43 André Erdmann
2012-07-09 17:19 André Erdmann
2012-07-04 18:21 André Erdmann
2012-07-04 18:21 André Erdmann
2012-07-03 17:48 André Erdmann
2012-06-28 13:29 André Erdmann
2012-06-26 15:42 André Erdmann
2012-06-25 18:19 André Erdmann
2012-06-21 16:55 André Erdmann
2012-06-20 19:03 André Erdmann
2012-06-20 19:03 André Erdmann
2012-06-18 16:27 André Erdmann
2012-06-15 20:34 André Erdmann
2012-06-15 20:34 André Erdmann
2012-06-15 20:34 André Erdmann
2012-06-15 20:34 André Erdmann
2012-06-15 20:34 André Erdmann
2012-06-15 20:34 André Erdmann
2012-06-12 17:17 André Erdmann
2012-06-06 19:52 André Erdmann
2012-06-06 19:52 André Erdmann
2012-06-06 19:52 André Erdmann
2012-06-05 17:30 André Erdmann
2012-06-04 19:07 André Erdmann
2012-06-04 19:07 André Erdmann
2012-06-04 15:43 André Erdmann
2012-06-01 16:19 André Erdmann
2012-06-01 16:19 André Erdmann
2012-06-01 15:46 André Erdmann
2012-05-31 18:24 André Erdmann
2012-05-30 20:15 André Erdmann
2012-05-30 19:36 André Erdmann
2012-05-30 19:36 André Erdmann
2012-05-30 16:09 André Erdmann
2012-05-30 16:09 André Erdmann
2012-05-30 16:09 André Erdmann
2012-05-30 16:09 André Erdmann
2012-05-30 10:58 André Erdmann
2012-05-30 10:58 André Erdmann
2012-05-30 10:58 André Erdmann
2012-05-30 10:58 André Erdmann
2012-05-29 17:09 André Erdmann
2012-05-29 17:09 André Erdmann
2012-05-29 17:09 André Erdmann
2012-05-29 17:09 André Erdmann
2012-05-26 13:14 André Erdmann
2012-05-26 13:14 André Erdmann

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=1338310856.033f6e38ee070ee1e71563bbc8d3a308604706e0.dywi@gentoo \
    --to=dywi@mailerd.de \
    --cc=gentoo-commits@lists.gentoo.org \
    --cc=gentoo-dev@lists.gentoo.org \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox