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 ) id 1SZPwC-0001gO-JP for garchives@archives.gentoo.org; Tue, 29 May 2012 17:10:29 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id A188FE0743; Tue, 29 May 2012 17:09:36 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 5C042E0743 for ; Tue, 29 May 2012 17:09:36 +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 9303E1B4062 for ; Tue, 29 May 2012 17:09:35 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id DAE0DE5437 for ; Tue, 29 May 2012 17:09:32 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1338311195.2e76c1e480434d43b6be4ade11d6ebd7a7025718.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/ebuildcreator.py X-VCS-Directories: roverlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 2e76c1e480434d43b6be4ade11d6ebd7a7025718 X-VCS-Branch: master Date: Tue, 29 May 2012 17:09:32 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: quoted-printable X-Archives-Salt: a862b270-ef8f-483e-9280-a347f1a6496d X-Archives-Hash: 4f44921a7e6238d84c0dce223fe6950c commit: 2e76c1e480434d43b6be4ade11d6ebd7a7025718 Author: Andre Erdmann mailerd de> AuthorDate: Tue May 29 17:06:35 2012 +0000 Commit: Andr=C3=A9 Erdmann mailerd de> CommitDate: Tue May 29 17:06:35 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/R_overlay.git= ;a=3Dcommit;h=3D2e76c1e4 roverlay, ebuildcreator: module that accepts package_files, schedules the= ir 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 =20 -# temporary import until logging is implemented -from sys import stderr as logging +from roverlay import ebuildjob.EbuildJob =20 -# temporary import until config and real constants are implemented -from roverlay import tmpconst as const =20 -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 =3D [ , str, [,str]* ] -# +class EbuildCreator: =20 -class Ebuild: - # could move this to const - EBUILD_INDENT =3D "\t" =20 - # reading every ebuild header file (copyright, inherit ) once a= t most - # =3D> [] - # shared among all ebuilds - ebuild_headers =3D dict() =20 @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 =3D '' - #self.version =3D '' - #self.origin =3D '' - #self.pkg_file =3D '' - #self.depend =3D '' - #self.rdepend =3D '' - #self.rsuggests =3D '' - #self.description =3D '' + """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 =3D dict () + self.depresolve_main =3D None # TODO + self.ebuild_jobs =3D [] =20 - # temporary var - #self.TODO =3D '' + # --- end of init (...) --- =20 - # this will be a list of str when exported data have been calculated - self._ebuild_export =3D None =20 @classmethod - def get_ebuild ( self, description_data, force_update=3DFalse ): - """ - 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 EbuildJ= ob + will be created for it. Returns the EbuildJob, which is also stored + in the job queue. =20 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 =3D self._make_export ( description_data ) + new_job =3D EbuildJob ( package_file, self.get_resolver ( False ) ) =20 - return self._ebuild_export + self.ebuild_jobs.append ( new_job ) =20 - @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 (...) --- =20 @classmethod - def write_ebuild ( self, file_to_write, force_update=3DFalse ): - """Writes this ebuild into a file + def get_resolver ( self, readonly=3DTrue ): + """Returns a communication channel to the dependency resolver. =20 arguments: - * file_to_write -- path of the file to write (will be overwritten if e= xistent) - * force_update -- force calculation of ebuild data, don't use cached r= esults - - **TODO notes : mkdir -p $(dirname) + readonly -- whether the channel is listen-only (no write methods) or n= ot + defaults to True """ - try: - # try to get the ebuild lines before opening the file - line =3D None - # append newline here or add in _make_export() - lines =3D [ line + "\n" for line in self.get_ebuild ( force_update ) = ] - del line - - fh =3D 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 =3D [] - last_line_empty =3D False - line =3D None - - # remove repeated newlines ('repoman sez: ...') - for line in ebuild_content: - line =3D line.rstrip() - if line: - last_line_empty =3D False - elif not last_line_empty: - last_line_empty =3D True - else: - continue - - ebuild_export.append ( line ) + # + return None + #return self.depresolve_main.get_channel() =20 - del last_line_empty, line - return ebuild_content + # --- end of get_resolver (...) --- =20 + @classmethod + def run ( self ): + """Tells all EbuildJobs to run.""" + for job in self.ebuild_jobs: + job.run() =20 + @classmethod + def collect_ebuilds ( self ): + """Returns all ebuilds. (They may not be ready / TODO)""" + return [ job.get_ebuild() for job in self.ebuild_jobs ] =20 - @staticmethod - def _get_ebuild_header ( ebuild_header_file=3DNone ): + @classmethod + def get_ebuild_header ( self, ebuild_header_file=3DNone ): """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. =20 arguments: - ebuild_header_file -- path to the header file; defaults to none which - means that nothing will be read and an empty lis= t - is returned + * ebuild_header_file -- path to the header file; defaults to none whic= h + means that nothing will be read and an empty l= ist + is returned. """ + if ebuild_header_file is None: # nothing to read return [] =20 - 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] =20 else: - # do read + # read file try: - fh =3D open (ebuild_header_file, 'rU') + fh =3D open ( ebuild_header_file, 'r' ) lines =3D fh.readlines() fh.close() - ebuild_headers [ebuild_header_file] =3D lines - del lines, fh - return ebuild_headers [ebuild_header_file] + self.ebuild_headers [ebuild_header_file] =3D lines + del fh + return lines =20 except IOError as err: + # todo raise =20 - @staticmethod - def _make_var ( varname, value=3DNone, indent_level=3D0 ): - """Returns a variable definitions that can be used in ebuilds, optiona= lly - with indention. - - arguments: - * varname -- name of the variable (e.g. DEPEND) - * value -- value of the variable; an empty var (DEPEND=3D"") will be r= eturned - 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=3DNone ): - """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 lis= t - is returned - """ - - # this method is todo - - if not isinstance (description_data, dict): - #todo - raise Exception ( "bad description data" ) - - errors =3D dict() - - ebuild_content =3D 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'] =3D "missing" - - if self.origin: - ebuild_content.append ( _make_var ( "PKG_ORIGIN", self.origin ) ) - else: - errors ['PKG_ORIGIN'] =3D "missing" - - ebuild_content.append ( "" ) - - if self.description: - ebuild_content.append ( _make_var ( "DESCRIPTION", self.TODO ) ) - else: - ebuild_content.append ( _make_var ( "DESCRIPTION", "" ) ) - #errors ['DESCRIPTION'] =3D "missing" - - # determine SRC_URI (origin + pkg_file) - if self.pkg_file and self.origin and False: - # SRC_URI ~=3D <> + origin + pkg_file - ebuild_content.append ( _make_var ( "SRC_URI", "" ) ) - else: - # either RESTRICT+=3D" fetch" or treat missing SRC_URI as critical - errors ['SRC_URI'] =3D "missing" - - ebuild_content.append ( "" ) - - #LICENSE (!!) - - rdepend =3D '${DEPEND:-} ' + self.rdepend - - # inherit IUSE from eclass - iuse =3D '${IUSE:-}' - - if self.rsuggests: - iuse +=3D ' R_suggests' - rdepend +=3D ' R_suggests ? ${R_SUGGESTS}' - ebuild_content.append ( _make_var ( "R_SUGGESTS", self.rsuggests ) ) - - ebuild_content.append ( _make_var ( "IUSE", iuse ) ) - ebuild_content.append ( "" ) - - # DEPEND=3D"${DEPEND:-} " to inherit deps from eclas= s - 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 =3D description_data - - self._ebuild =3D None - - @classmethod - def run ( self ): - """Tells this EbuildCreator to operate which produces an Ebuild objec= t - that can later be shown or written into a file. - """ - #todo - self._ebuild =3D None - - if self._description_data is None: - return False - - ebuild =3D Ebuild() - dref =3D self._description_data - - ebuild.name =3D dref ['Package'] - ebuild.version =3D dref ['Version'] - - ebuild.origin =3D "TODO" - ebuild.pkg_file =3D "TODO" - - # depend rdepend rsuggest - ebuild.depend =3D "TODO" - ebuild.rdepend =3D "TODO" - ebuild.suggest =3D "TODO" - - if 'Description' in dref: - ebuild.description =3D dref ['Description'] - elif 'Title' in dref: - ebuild.description =3D dref ['Title'] - else: - ebuild.description =3D "" - - # - - 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 EbuildCre= ator - for every get_ebuild_creator ( tarball ) call. - """ - self.desc_reader =3D DescriptionReader() - - @classmethod - def get_ebuild_creator ( self, tarball ): - """Creates and returns an ebuild creator that will handle - the data retrieved from . - - arguments: - * tarball -- tarball to read - """ - data =3D self.desc_reader.readfile ( tarball ) - if data: - return EbuildCreator ( data ) - else: - return None - - + # --- end of get_ebuild_header (...) ---