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: Wed, 30 May 2012 16:09:55 +0000 (UTC)	[thread overview]
Message-ID: <1338389668.efc87322e3016a5178feb579b468ff44d8cc0b04.dywi@gentoo> (raw)

commit:     efc87322e3016a5178feb579b468ff44d8cc0b04
Author:     Andre Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed May 30 14:54:28 2012 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed May 30 14:54:28 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=efc87322

roverlay, ebuildjob: status code and dep resolve logic
	modified:   ebuildjob.py

---
 roverlay/ebuildjob.py |  260 ++++++++++++++++++++++++++++++++++---------------
 1 files changed, 181 insertions(+), 79 deletions(-)

diff --git a/roverlay/ebuildjob.py b/roverlay/ebuildjob.py
index 171150c..d45dfdf 100644
--- a/roverlay/ebuildjob.py
+++ b/roverlay/ebuildjob.py
@@ -6,11 +6,42 @@ from roverlay.fileio import DescriptionReader
 from roverlay.ebuild import Ebuild
 
 class EbuildJob:
-	STATUS_LIST = [ 'INIT', 'BUSY', 'WAIT', 'SUCCESS', 'FAIL' ]
-	STATUS_MAP  = dict ( ( name, code ) for code, name in enumerate ( STATUS_LIST ) )
+	# move this to const / config
+	DEPENDENCY_FIELDS = {
+		'R_SUGGESTS' : [ 'Suggests' ],
+		'DEPENDS'    : ['Depends', 'Imports' ],
+		'RDEPENDS'   : [ 'LinkingTo', 'SystemRequirements' ]
+	}
+
+	##
+
+
+	STATUS_LIST = [ 'INIT', 'BUSY', 'WAIT_RESOLVE', 'SUCCESS', 'FAIL' ]
+
+	# status 'jump' control
+	# FAIL is always allowed, S -> S has to be explicitly allowed
+	STATUS_BRANCHMAP = dict (
+		INIT         = [ 'BUSY' ],
+		BUSY         = [ 'BUSY', 'WAIT_RESOLVE', 'SUCCESS' ],
+		WAIT_RESOLVE = [ 'BUSY' ],
+		SUCCESS      = [],
+		FAIL         = [],
+	)
 
 	@classmethod
 	def __init__ ( self, package_file, dep_resolver=None ):
+		"""Initializes an EbuildJob, which creates an ebuild for an R package.
+
+		arguments:
+		* package_file -- path to the R package file
+		* dep_resolver -- dependency resolver
+		"""
+
+		"""Note:
+		it is intended to run this job as thread, that's why it has its own
+		dep resolver 'communication channel', status codes etc.
+		"""
+
 		self.package_file = package_file
 		self.dep_resolver = dep_resolver
 		# get description reader from args?
@@ -18,44 +49,10 @@ class EbuildJob:
 
 		self.ebuild = None
 
-		self._status = 0 # todo
+		self.status = 'INIT'
 
 	# --- end of __init__ (...) ---
 
-	@staticmethod
-	def get_statuscode ( status_id ):
-		if status_id == 'ALL':
-			return EbuildJob.STATUS_LIST
-		elif isinstance ( status_id, int ):
-			if status_id > 0 and status_id < len ( STATUS_LIST ):
-				return EbuildJob.STATUS_LIST [status_id]
-		elif status_id in EbuildJob.STATUS_MAP:
-			return EbuildJob.STATUS_MAP [status_id]
-
-		return None
-
-	# --- end of get_statuscode (...) ---
-
-	@classmethod
-	def status ( self, expected_status=None ):
-		"""Returns the current status of this job or a bool that indicates
-		whether to current status matches the expected one.
-
-		arguments:
-		* expected_status -- if not None: check if this job's state is expected_status
-		"""
-		if expected_status:
-			if isinstance ( expected_status, int ):
-				return bool ( self._status == expected_status )
-			elif expected_status in EbuildJob.STATUS_MAP:
-				return bool ( self._status == EbuildJob.STATUS_MAP [expected_status] )
-			else:
-				return False
-
-		return self._status
-
-		# --- end of status (...) ---
-
 	@classmethod
 	def get_ebuild ( self ):
 		"""Returns the Ebuild that is created by this object. Note that you should
@@ -68,73 +65,178 @@ class EbuildJob:
 	# --- end of get_ebuild (...) ---
 
 	@classmethod
-	def _set_status ( self, new_status ):
-		self._status = EbuildJob.get_statuscode ( new_status )
-		return True
+	def get_status ( self, expected_status=None ):
+		"""Returns the current status of this job or a bool that indicates
+		whether to current status matches the expected one.
 
-	# --- end of _set_status (...) ---
+		arguments:
+		* expected_status -- if not None: check if this job's state is expected_status
+		"""
+		if not expected_status is None:
+			return bool ( self.status == expected_status )
+		else:
+			return self.status
+
+	# --- end of get_status (...) ---
+
+	@classmethod
+	def done_success ( self ):
+		"""Returns True if this has been successfully finished."""
+		return get_status ( 'SUCCESS' )
+
+	# --- end of done_success (...) ---
 
 
 	@classmethod
 	def run ( self ):
 		"""Tells this EbuildJob to run. This means that it reads the package file,
-		resolves dependencies (TODO) and creates an Ebuild object that is ready
-		to be written into a file.
+		resolves dependencies using its resolver (TODO) and creates
+		an Ebuild object that is ready to be written into a file.
 		"""
 
-		# check status
-		if not self.status ( 'INIT' ):
-			return
+		# TODO move hardcoded entries to config/const
 
-		if not self._set_status ( 'BUSY' ):
-			return False
+		try:
 
-		read_data = self.description_reader.readfile ( self.package_file )
+			# set status or return
+			if not self._set_status ( 'BUSY', True ): return
 
-		if read_data is None:
-			# set status accordingly
-			self._set_status ( 'FAIL' )
-			return False
+			read_data = self.description_reader.readfile ( self.package_file )
 
-		fileinfo  = read_data ['fileinfo']
-		desc      = read_data ['description_data']
+			if read_data is None:
+				# set status accordingly
+				self._set_status ( 'FAIL' )
+				return
 
-		ebuild = Ebuild()
+			fileinfo  = read_data ['fileinfo']
+			desc      = read_data ['description_data']
 
-		have_description = False
+			ebuild = Ebuild()
 
-		print ( str ( desc ) )
+			have_description = False
 
-		if 'Title' in desc:
-			have_description = True
-			ebuild.add ( 'DESCRIPTION', desc ['Title'] )
+			if 'Title' in desc:
+				ebuild.add ( 'DESCRIPTION', desc ['Title'] )
+				have_description = True
 
-		if 'Description' in desc:
-			have_description = True
-			ebuild.add ( 'DESCRIPTION', ( '// ' if have_description else '' ) + desc ['Description'] )
+			if 'Description' in desc:
+				ebuild.add ( 'DESCRIPTION', ( '// ' if have_description else '' ) + desc ['Description'] )
+				#have_description=True
 
-		if not have_description:
-			ebuild.add ( 'DESCRIPTION', '<none>' )
-		del have_description
 
-		# origin is todo (sync module knows the package origin)
-		ebuild.add ( 'PKG_ORIGIN', 'CRAN' )
+			# origin is todo (sync module knows the package origin)
+			ebuild.add ( 'PKG_ORIGIN', 'CRAN' )
 
-		ebuild.add ( 'PKG_FILE', fileinfo ['package_file'] )
+			ebuild.add ( 'PKG_FILE', fileinfo ['package_file'] )
 
-		ebuild.add ( 'ebuild_header', [ '# test header' ], False )
+			ebuild.add ( 'ebuild_header',
+								[ '# test header, first line\n',
+									'# test header, second line\n\n\n\n',
+									'#third\n\n#fifth' ],
+								False
+							)
 
-		##  have to resolve deps here
+			if self.dep_resolver and self.dep_resolver.enabled():
 
-		# enter status that allows transferring ebuild -> self.ebuild
-		if self._set_status ( 'WAIT' ):
-			# finalize self.ebuild: forced text creation + make it readonly
+				# collect depdencies from desc and add them to the resolver
+				raw_depends = dict ()
+
+				dep_type = field = None
+
+				for dep_type in EbuildJob.DEPENDENCY_FIELDS.keys():
+
+					raw_depends [dep_type] = []
+
+					for field in EbuildJob.DEPENDENCY_FIELDS [dep_type]:
+
+						if field in desc:
+							if isinstance ( desc [field], list ):
+								raw_depends.extend ( desc [field] )
+								self.dep_resolver.add_dependencies ( desc [field] )
+
+							else:
+								raw_depends.append ( desc [field] )
+								self.dep_resolver.add_depency ( desc [field] )
+
+				del field, dep_type
+
+
+				while not self.dep_resolver.done():
+
+					if not self._set_status ( 'WAIT_RESOLVE' ): return
+
+					# tell the resolver to run (again)
+					self.dep_resolver.run()
+
+					if not self._set_status ( 'BUSY' ): return
+
+				if self.dep_resolver.satisfy_request():
+
+					dep_type = dep_str = dep = None
+
+					# dependencies resolved, add them to the ebuild
+					for dep_type in raw_depends.keys():
+
+						for dep_str in raw_depends [dep_type]:
+							# lookup (str) should return a str here
+							dep = self.dep_resolver.lookup ( dep_str )
+							if dep is None:
+								raise Exception (
+									"dep_resolver is broken: lookup() returns None but satisfy_request() says ok."
+								)
+							else:
+								# add depencies in append mode
+								dep = self.dep_resolver.lookup ( dep_str )
+								ebuild.add ( dep_type,
+													self.dep_resolver.lookup ( dep_str ),
+													True
+												)
+
+					del dep, dep_str, dep_type
+
+					# tell the dep resolver that we're done here
+					self.dep_resolver.close()
+
+				else:
+					# ebuild is not creatable, set status to FAIL and close dep resolver
+					self._set_status ( 'FAIL' )
+					self.dep_resolver.close()
+					return
+
+			## finalize self.ebuild: forced text creation + make it readonly
 			if ebuild.prepare ( True, True ):
 				self.ebuild = ebuild
-				return self._set_status ( 'SUCCESS' )
-
-		self._set_status ( 'FAIL' )
-		return False
+				return None
+			else:
+				return None
 
+		except Exception as any_exception:
+			# any exception means failure
+			self.status = 'FAIL'
+			raise
 
 	# --- end of run (...) ---
+
+	@classmethod
+	def _set_status ( self, new_status, ignore_invalid=False ):
+		"""Changes the status of this job. May refuse to do that if invalid change
+		requested (e.g. 'FAIL' -> 'SUCCESS').
+
+		arguments:
+		new_status --
+		"""
+
+		if new_status == 'FAIL':
+			# always allowed
+			self.status = new_status
+
+		if new_status and new_status in EbuildJob.STATUS_LIST:
+			# check if jumping from self.status to new_status is allowed
+			if new_status in EbuildJob.STATUS_BRANCHMAP [self.status]:
+				self.status = new_status
+				return True
+
+		# default return
+		return False
+
+	# --- end of _set_status (...) ---



             reply	other threads:[~2012-05-30 16:10 UTC|newest]

Thread overview: 159+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-05-30 16: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 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-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=1338389668.efc87322e3016a5178feb579b468ff44d8cc0b04.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