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: <1338311195.2e76c1e480434d43b6be4ade11d6ebd7a7025718.dywi@gentoo> (raw)

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

roverlay, ebuildcreator: module that accepts package_files, schedules their processing into jobs and returns ebuilds (but is todo)
	modified:   ebuildcreator.py

---
 roverlay/ebuildcreator.py |  356 +++++++--------------------------------------
 1 files changed, 54 insertions(+), 302 deletions(-)

diff --git a/roverlay/ebuildcreator.py b/roverlay/ebuildcreator.py
index fa648b8..f439c71 100644
--- a/roverlay/ebuildcreator.py
+++ b/roverlay/ebuildcreator.py
@@ -1,350 +1,102 @@
-# R Overlay -- ebuild creation
+# R Overlay -- ebuild creation, "master" module
 # Copyright 2006-2012 Gentoo Foundation
 # Distributed under the terms of the GNU General Public License v2
 
-# temporary import until logging is implemented
-from sys import stderr as logging
+from roverlay import ebuildjob.EbuildJob
 
-# temporary import until config and real constants are implemented
-from roverlay import tmpconst as const
 
-from roverlay.fileio import DescriptionReader
-
-# misc TODO notes:
-# * could use caching via decorators instead of wrappers (-> later)
-# * instead of including the ebuild header in every ebuild 'export' data:
-# ** link that header
-# ** ebuild_export = [ <header_link>, str, [,str]* ]
-#
+class EbuildCreator:
 
-class Ebuild:
-	# could move this to const
-	EBUILD_INDENT = "\t"
 
-	# reading every ebuild header file (copyright, inherit <eclass>) once at most
-	#  <ebuild header file> => [<content of this file>]
-	#  shared among all ebuilds
-	ebuild_headers = dict()
 
 	@classmethod
 	def __init__ ( self ):
-		"""Initializes an empty Ebuild. This is an object that can be used to
-		create text lines for an ebuild file."""
-
-		#self.name        = ''
-		#self.version     = ''
-		#self.origin      = ''
-		#self.pkg_file    = ''
-		#self.depend      = ''
-		#self.rdepend     = ''
-		#self.rsuggests   = ''
-		#self.description = ''
+		"""Initializes an EbuildCreator. This is an Object that controls the
+		R package -> ebuild creation. It continuously creates EbuildJobs for
+		every R package added.
+		"""
+		self.ebuild_headers = dict ()
+		self.depresolve_main = None # TODO
+		self.ebuild_jobs = []
 
-		# temporary var
-		#self.TODO = ''
+	# --- end of init (...) ---
 
-		# this will be a list of str when exported data have been calculated
-		self._ebuild_export = None
 
 	@classmethod
-	def get_ebuild ( self, description_data, force_update=False ):
-		"""
-		Wrapper function that returns ebuild 'export' data.
-		This is a list of str that has no newline chars at the end of each str.
+	def add_package ( self, package_file ):
+		"""Adds an R package to the EbuildCreator, which means that an EbuildJob
+		will be created for it. Returns the EbuildJob, which is also stored
+		in the job queue.
 
 		arguments:
-		* force_update -- force calculation of export data
-
+		* package_file -- path R package file
 		"""
-		if force_update or (self._ebuild_export is None):
-			self._ebuild_export = self._make_export ( description_data )
+		new_job = EbuildJob ( package_file, self.get_resolver ( False ) )
 
-		return self._ebuild_export
+		self.ebuild_jobs.append ( new_job )
 
-	@classmethod
-	def suggest_filename ( self ):
-		"""Suggests a file name for the ebuild.
-		Calculated using ebuild data, but TODO
-		"""
-		# name-version
-		return None
+		return new_job
+
+	# --- end of add_package (...) ---
 
 	@classmethod
-	def write_ebuild ( self, file_to_write, force_update=False ):
-		"""Writes this ebuild into a file
+	def get_resolver ( self, readonly=True ):
+		"""Returns a communication channel to the dependency resolver.
 
 		arguments:
-		* file_to_write -- path of the file to write (will be overwritten if existent)
-		* force_update -- force calculation of ebuild data, don't use cached results
-
-		**TODO notes : mkdir -p $(dirname)
+		readonly -- whether the channel is listen-only (no write methods) or not
+		            defaults to True
 		"""
-		try:
-			# try to get the ebuild lines before opening the file
-			line  = None
-			# append newline here or add in _make_export()
-			lines = [ line + "\n" for line in self.get_ebuild ( force_update ) ]
-			del line
-
-			fh = open ( file_to_write, 'w' )
-			fh.writelines ( lines )
-			fh.close ()
-
-			del lines, fh
-			return True
-		except IOError as err:
-			raise
-
-		# catch failure
-		return False
-
-		@classmethod
-		def _make_ebuild_lines ( self, ebuild_content ):
-			ebuild_export = []
-			last_line_empty = False
-			line = None
-
-			# remove repeated newlines ('repoman sez: ...')
-			for line in ebuild_content:
-				line = line.rstrip()
-				if line:
-					last_line_empty = False
-				elif not last_line_empty:
-					last_line_empty = True
-				else:
-					continue
-
-				ebuild_export.append ( line )
+		# <TODO>
+		return None
+		#return self.depresolve_main.get_channel()
 
-			del last_line_empty, line
-			return ebuild_content
+	# --- end of get_resolver (...) ---
 
+	@classmethod
+	def run ( self ):
+		"""Tells all EbuildJobs to run."""
+		for job in self.ebuild_jobs:
+			job.run()
 
+	@classmethod
+	def collect_ebuilds ( self ):
+		"""Returns all ebuilds. (They may not be ready / TODO)"""
+		return [ job.get_ebuild() for job in self.ebuild_jobs ]
 
-	@staticmethod
-	def _get_ebuild_header ( ebuild_header_file=None ):
+	@classmethod
+	def get_ebuild_header ( self, ebuild_header_file=None ):
 		"""Reads and returns the content of an ebuild header file.
 		This is a normal file that can be included in ebuilds.
 		Every header file will only be read on first access, it's content will
-		be stored in a dict that is shared among all Ebuild instances.
+		be stored in a dict that is shared among all EbuildCreator instances.
 
 		arguments:
-		ebuild_header_file -- path to the header file; defaults to none which
-		                      means that nothing will be read and an empty list
-		                      is returned
+		* ebuild_header_file -- path to the header file; defaults to none which
+		                        means that nothing will be read and an empty list
+		                        is returned.
 		"""
+
 		if ebuild_header_file is None:
 			# nothing to read
 			return []
 
-		elif (ebuild_header_file in ebuild_headers):
+		elif ebuild_header_file in self.ebuild_headers:
 			# previously read
-			return ebuild_headers [ebuild_header_file]
+			return self.ebuild_headers [ebuild_header_file]
 
 		else:
-			# do read
+			# read file
 			try:
-				fh = open (ebuild_header_file, 'rU')
+				fh = open ( ebuild_header_file, 'r' )
 				lines = fh.readlines()
 				fh.close()
-				ebuild_headers [ebuild_header_file] = lines
-				del lines, fh
-				return ebuild_headers [ebuild_header_file]
+				self.ebuild_headers [ebuild_header_file] = lines
+				del fh
+				return lines
 
 			except IOError as err:
+				# todo
 				raise
 
-	@staticmethod
-	def _make_var ( varname, value=None, indent_level=0 ):
-		"""Returns a variable definitions that can be used in ebuilds, optionally
-		with indention.
-
-		arguments:
-		* varname -- name of the variable (e.g. DEPEND)
-		* value -- value of the variable; an empty var (DEPEND="") will be returned
-		           if unset (the default)
-		* indent_level -- indent var definition by indent_level levels
-		"""
-
-		if value:
-			return indent_level * EBUILD_INDENT + varname + '"' + value + '"'
-		else:
-			# empty var
-			return indent_level * EBUILD_INDENT + varname + '""'
-
-	@classmethod
-	def _make_export ( self, description_data, ebuild_header=None ):
-		"""Creates ebuild data that can be written into stdout or a file
-
-		arguments:
-		ebuild_header_file -- path to the header file; defaults to none which
-		                      means that nothing will be read and an empty list
-		                      is returned
-		"""
-
-		# this method is todo
-
-		if not isinstance (description_data, dict):
-			#todo
-			raise Exception ( "bad description data" )
-
-		errors = dict()
-
-		ebuild_content = Ebuild._get_ebuild_header ( ebuild_header )
-
-		# repeated and leading empty lines will be removed later
-		ebuild_content.append ( "" )
-
-		# the code below this line does not work
-		return
-		#raise Exception ( "under construction ..." )
-
-		if self.pkg_file:
-			ebuild_content.append ( _make_var ( "PKG_FILE" , self.pkg_file ) )
-		else:
-			# absense of a pkg source file is an error
-			errors ['PKG_FILE'] = "missing"
-
-		if self.origin:
-			ebuild_content.append ( _make_var ( "PKG_ORIGIN", self.origin ) )
-		else:
-			errors ['PKG_ORIGIN'] = "missing"
-
-		ebuild_content.append ( "" )
-
-		if self.description:
-			ebuild_content.append ( _make_var ( "DESCRIPTION", self.TODO ) )
-		else:
-			ebuild_content.append ( _make_var ( "DESCRIPTION", "<none>" ) )
-			#errors ['DESCRIPTION'] = "missing"
-
-		# determine SRC_URI (origin + pkg_file)
-		if self.pkg_file and self.origin and False:
-			# SRC_URI ~= <> + origin + pkg_file
-			ebuild_content.append ( _make_var ( "SRC_URI", "" ) )
-		else:
-			# either RESTRICT+=" fetch" or treat missing SRC_URI as critical
-			errors ['SRC_URI'] = "missing"
-
-		ebuild_content.append ( "" )
-
-		#LICENSE (!!)
-
-		rdepend = '${DEPEND:-} ' + self.rdepend
-
-		# inherit IUSE from eclass
-		iuse = '${IUSE:-}'
-
-		if self.rsuggests:
-			iuse    += ' R_suggests'
-			rdepend += ' R_suggests ? ${R_SUGGESTS}'
-			ebuild_content.append ( _make_var ( "R_SUGGESTS", self.rsuggests ) )
-
-		ebuild_content.append ( _make_var ( "IUSE", iuse ) )
-		ebuild_content.append ( "" )
-
-		# DEPEND="${DEPEND:-} <pkg dependencies>" to inherit deps from eclass
-		ebuild_content.append ( _make_var (
-											"DEPEND", '${DEPEND:-} ' + self.depend ) )
-
-		ebuild_content.append ( _make_var ( "RDEPEND", rdepend ) )
-
-		# (!!) TODO
-		if errors:
-			raise Exception ( "^^^missing components for ebuild^^^" )
-			#return None
-
-		return self._make_ebuild_lines ( ebuild_content )
-
-class EbuildCreator:
-# could move this to Ebuild
-
-		@classmethod
-		def __init__ ( self,  description_data ):
-			""""Initializes an EbuildCreator.
-			[todo]
-			"""
-			self._description_data = description_data
-
-			self._ebuild = None
-
-		@classmethod
-		def run ( self ):
-			"""Tells this EbuildCreator to operate which produces an Ebuild object
-			that can later be shown or written into a file.
-			"""
-			#todo
-			self._ebuild = None
-
-			if self._description_data is None:
-				return False
-
-			ebuild = Ebuild()
-			dref = self._description_data
-
-			ebuild.name = dref ['Package']
-			ebuild.version = dref ['Version']
-
-			ebuild.origin = "TODO"
-			ebuild.pkg_file = "TODO"
-
-			# depend rdepend rsuggest
-			ebuild.depend  = "TODO"
-			ebuild.rdepend = "TODO"
-			ebuild.suggest = "TODO"
-
-			if 'Description' in dref:
-				ebuild.description = dref ['Description']
-			elif 'Title' in dref:
-				ebuild.description = dref ['Title']
-			else:
-				ebuild.description = "<none>"
-
-			# <dep resolution here?>
-
-			ebuild.get_ebuild ( self._description_data )
-
-			# todo
-			return None
-
-
-		@classmethod
-		def show ( self ):
-			"""Prints the ebuild to stdout/err or into log"""
-			pass
-
-		@classmethod
-		def write ( self ):
-			"""Writes the ebuild into a file"""
-			pass
-
-		@classmethod
-		def ready ( self ):
-			"""Returns true if an Ebuild has been produced, else false."""
-			return not (self._ebuild is None)
-
-
-class EbuildFactory:
-
-		@classmethod
-		def __init__ ( self ):
-			"""Initializes an ebuild factory. This continously produces EbuildCreator
-			for every get_ebuild_creator ( tarball ) call.
-			"""
-			self.desc_reader = DescriptionReader()
-
-		@classmethod
-		def get_ebuild_creator ( self, tarball ):
-			"""Creates and returns an ebuild creator that will handle
-			the data retrieved from <tarball>.
-
-			arguments:
-			* tarball -- tarball to read
-			"""
-			data = self.desc_reader.readfile ( tarball )
-			if data:
-				return EbuildCreator ( data )
-			else:
-				return None
-
-
+	# --- end of get_ebuild_header (...) ---



             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=1338311195.2e76c1e480434d43b6be4ade11d6ebd7a7025718.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