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 1SfdEj-0001w6-Ah for garchives@archives.gentoo.org; Fri, 15 Jun 2012 20:35:17 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 4C17621C026; Fri, 15 Jun 2012 20:34:35 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 0DB16E09CF for ; Fri, 15 Jun 2012 20:34: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 4170F1B404C for ; Fri, 15 Jun 2012 20:34:34 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 6E95DE5437 for ; Fri, 15 Jun 2012 20:34:31 +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: <1339792177.d4019f10979a2d10c2fb85ae5a5bf02cd44a07a2.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/portage/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/portage/ebuild.py X-VCS-Directories: roverlay/portage/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: d4019f10979a2d10c2fb85ae5a5bf02cd44a07a2 X-VCS-Branch: master Date: Fri, 15 Jun 2012 20:34:31 +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: 8e373152-d671-437a-b734-3bc6c6704d4f X-Archives-Hash: c7a118de91eadc6c8b885ea6e2e6947c commit: d4019f10979a2d10c2fb85ae5a5bf02cd44a07a2 Author: Andr=C3=A9 Erdmann mailerd de> AuthorDate: Fri Jun 15 20:29:37 2012 +0000 Commit: Andr=C3=A9 Erdmann mailerd de> CommitDate: Fri Jun 15 20:29:37 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/R_overlay.git= ;a=3Dcommit;h=3Dd4019f10 Ebuild.py: fixes and cut long DESCRIPTION values modified: roverlay/portage/ebuild.py --- roverlay/portage/ebuild.py | 139 +++++++++++++++++++++++++++++---------= ----- 1 files changed, 94 insertions(+), 45 deletions(-) diff --git a/roverlay/portage/ebuild.py b/roverlay/portage/ebuild.py index 00620f0..a435f5c 100644 --- a/roverlay/portage/ebuild.py +++ b/roverlay/portage/ebuild.py @@ -6,6 +6,8 @@ import copy =20 import roverlay.config =20 +from roverlay.util import shorten_str + =20 class Ebuild ( object ): EBUILD_INDENT =3D roverlay.config.get ( 'EBUILD.indent', '\t' ) @@ -168,10 +170,12 @@ class Ebuild ( object ): =20 def suggest_dir_name ( self ): """Suggests a direcory name for this Ebuild.""" - if 'pkg_name' in self._data: + if self._data is None: + return self._ebuild_name.partition ( '-' ) [0] + elif 'pkg_name' in self._data: return self._data ['pkg_name'] else: - return self.suggest_name().partition ( '-' ) + return self.suggest_name().partition ( '-' ) [0] # --- end of suggest_dir_name (...) --- =20 def suggest_name ( self, fallback_name=3D'' ): @@ -253,23 +257,30 @@ class Ebuild ( object ): =20 # --- end of get_dep_and_use () --- =20 - def make_var ( varname, value=3DNone, oneline_list=3DTrue, indent_list= =3DTrue, indent_level=3D0 ): + def make_var ( + varname, + value=3DNone, oneline_list=3DTrue, indent_list=3DTrue, indent_level=3D= 0 + ): """Creates a =3D statement for ebuilds. =20 arguments: - * varname -- name of the variable - * value -- value of the variable. This has to be either None (the def= ault), - str, or list of str. - * oneline_list -- if value is a list: controls whether its components= should be - put into one line (True) or multiple (False). Defau= lts to True. - * indent_list -- if value is a list and not oneline_list: - controls whether each value line should be indentend - (by indent_level + 1) or not ("by 0"). Defaults to T= rue. + * varname -- name of the variable + * value -- value of the variable. + This has to be either None (the default), str, + or list of str. + * oneline_list -- if value is a list: controls whether its components + should be put into one line (True) or multiple. + Defaults to True. + * indent_list -- if value is a list and not oneline_list: + controls whether each value line should be + indentend (by indent_level + 1) or not ("by 0"). + Defaults to True. * indent_level -- current indentation level, defaults to 0 =20 """ =20 - # assumption: value is either None, scalar with str representation or= list of str + # assumption: value is either None, + # scalar with str representation or list of str var_value =3D None =20 if not value: @@ -288,16 +299,37 @@ class Ebuild ( object ): else: var_value =3D str ( value ) =20 - return indent_level * Ebuild.EBUILD_INDENT + varname + '=3D"' + var_v= alue + '"' + + # (TODO) + # fixing ebuild var values here + + # cut DESCRIPTION line if too long + if varname =3D=3D 'DESCRIPTION': + var_value =3D shorten_str ( var_value, 45, '... (see metadata)' ) + + + ret =3D'%s%s=3D"%s"' % ( + indent_level * Ebuild.EBUILD_INDENT, + varname, + var_value + ) + + # (TODO) + # fixing ebuild var lines here + + return ret =20 # --- end of make_var (...) --- =20 def remove_newlines ( line_list ): - """ - Removes leading, ending and repeated empty/whitespace lines in line_l= ist. + """Removes leading, ending and repeated blank lines in line_list. =20 arguments: - * line_list + * line_list -- + + returns: filtered lines + + TODO: check if a filter function could be used for this """ lines =3D [] line =3D None @@ -325,26 +357,38 @@ class Ebuild ( object ): =20 # --- end of remove_newlines (...) --- =20 - def add_easyvar ( ebuild_content, varname, value_key=3DNone, add_newli= ne=3DFalse): - """Adds a 'simple' variable to the ebuild lines. This means that it - can directly be taken from self._data [value_key]. This method assume= s - that value_key exists in self._data, any exceptions (KeyError) will b= e passed. + def add_easyvar ( + ebuild_content, varname, + value_key=3DNone, add_newline=3DFalse + ): + """Adds a 'simple' variable to the ebuild lines. + This means that it can directly be taken from self._data [value_key]. + This method assumes that value_key exists in self._data, + any exceptions (KeyError) will be passed. =20 arguments: - * ebuild_content -- list of ebuild text lines, will be modified direc= tly, - so copy it before calling addvar if you need the= original list. - * varname -- name of the variable. Nothing happens if this is None. - * value_key -- key of the value, defaults to varname if it is None - * add_newline -- adds a newline after the var statement, defaults to = False - - Returns given list (ebuild_content), which will then have been modifi= ed. + * ebuild_content -- list of ebuild text lines, will be modified + directly, so copy it before calling addvar if + you need the original list. + * varname -- name of the variable. + Nothing happens if this is None. + * value_key -- key of the value, + defaults to varname if it is None + * add_newline -- adds a newline after the var statement, + defaults to False + + returns: given+modified list (ebuild_content) """ =20 if not varname is None: if value_key is None: - ebuild_content.append ( make_var ( varname, self._data [varname] ) = ) + ebuild_content.append ( + make_var ( varname, self._data [varname] ) + ) else: - ebuild_content.append ( make_var ( varname, self._data [value_key] = ) ) + ebuild_content.append ( + make_var ( varname, self._data [value_key] ) + ) =20 if add_newline: ebuild_content.append ( "" ) @@ -353,6 +397,7 @@ class Ebuild ( object ): =20 # --- end of add_easyvar (...) --- =20 + # -- actual start of _make_ebuild_lines (...) -- try: ebuild_lines =3D [] =20 @@ -366,42 +411,46 @@ class Ebuild ( object ): =20 ebuild_lines.append ( "" ) =20 + # TODO/FIXME: this makes DESCRIPTION mandatory, maybe check with + # >if 'DESCRIPTION' in self._data< add_easyvar ( ebuild_lines, "DESCRIPTION" ) =20 - if 'SRC_URI' in self._data: - add_easyvar ( ebuild_lines, "SRC_URI" ) - else: - # > calculate SRC_URI using self._data ['origin'] -- either here or = in eclass - ebuild_lines.append ( make_var ( "SRC_URI" , None ) ) - # (temporary, todo) setting restrict to fetch - ebuild_lines.append ( make_var ( "RESTRICT" , "fetch" ) ) - - ebuild_lines.append ( "" ) + add_easyvar ( ebuild_lines, "SRC_URI", add_newline=3DTrue ) =20 - # LICENSE ? + # FIXME/TODO: LICENSE? =20 dep_and_use =3D get_dep_and_use () =20 - # check that IUSE has more than one element, don't write IUSE=3D"${IU= SE:-}" etc. + # check that IUSE has more than one element, + # don't write IUSE=3D"${IUSE:-}" etc. if len ( dep_and_use ['IUSE'] ) > 1: - ebuild_lines.append ( make_var ( "IUSE", dep_and_use ['IUSE'], True = ) ) + ebuild_lines.append ( + make_var ( "IUSE", dep_and_use ['IUSE'], True ) + ) =20 if 'R_SUGGESTS' in dep_and_use: - ebuild_lines.append ( make_var ( "R_SUGGESTS", dep_and_use ['R_SUGGE= STS'], False ) ) + ebuild_lines.append ( + make_var ( "R_SUGGESTS", dep_and_use ['R_SUGGESTS'], False ) + ) =20 # see IUSE if len ( dep_and_use ['DEPEND'] ) > 1: - ebuild_lines.append ( make_var ( "DEPEND", dep_and_use ['DEPEND'], F= alse ) ) + ebuild_lines.append ( + make_var ( "DEPEND", dep_and_use ['DEPEND'], False ) + ) =20 # see IUSE if len ( dep_and_use ['RDEPEND'] ) > 1: - ebuild_lines.append ( make_var ( "RDEPEND", dep_and_use ['RDEPEND'],= False ) ) + ebuild_lines.append ( + make_var ( "RDEPEND", dep_and_use ['RDEPEND'], False ) + ) =20 del dep_and_use return remove_newlines ( ebuild_lines ) =20 except ( ValueError, KeyError, NameError ) as err: - self.logger.error ( "Cannot create ebuild text lines. The error messa= ge was %s.", str ( err ) ) + self.logger.exception ( err ) + self.logger.error ( "Cannot create ebuild text lines." ) return None =20 # --- end of make_ebuild_lines (...) ---