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.77) (envelope-from ) id 1SmoTz-0007dp-Sy for garchives@archives.gentoo.org; Thu, 05 Jul 2012 16:00:44 +0000 Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id B87D7E06B7; Thu, 5 Jul 2012 16:00:16 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) by pigeon.gentoo.org (Postfix) with ESMTP id 7A4DDE06B7 for ; Thu, 5 Jul 2012 16:00:16 +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 AD56C1B4019 for ; Thu, 5 Jul 2012 16:00:15 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id C57A6E5449 for ; Thu, 5 Jul 2012 16:00:12 +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: <1341503980.9d2a243a6e6eadc71e3962726b29c84d1251d732.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/overlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/overlay/__init__.py X-VCS-Directories: roverlay/overlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: 9d2a243a6e6eadc71e3962726b29c84d1251d732 X-VCS-Branch: master Date: Thu, 5 Jul 2012 16:00:12 +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: 1b6a82e5-daf7-4cac-9c1e-7a1e3bb4b86f X-Archives-Hash: df8023ce3125d68911493307c9c558f5 commit: 9d2a243a6e6eadc71e3962726b29c84d1251d732 Author: Andr=C3=A9 Erdmann mailerd de> AuthorDate: Thu Jul 5 15:59:40 2012 +0000 Commit: Andr=C3=A9 Erdmann mailerd de> CommitDate: Thu Jul 5 15:59:40 2012 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=3Dproj/R_overlay.git= ;a=3Dcommit;h=3D9d2a243a overlay: calculate inherit statement for ebuilds modified: roverlay/overlay/__init__.py --- roverlay/overlay/__init__.py | 83 +++++++++++++++++++++++++++++++++---= ------ 1 files changed, 66 insertions(+), 17 deletions(-) diff --git a/roverlay/overlay/__init__.py b/roverlay/overlay/__init__.py index 13b6615..b6a65a1 100644 --- a/roverlay/overlay/__init__.py +++ b/roverlay/overlay/__init__.py @@ -60,6 +60,7 @@ class Overlay ( object ): else: self.eclass_files =3D eclass_files =20 + self.eclass_names =3D None =20 # self._profiles_dir =3D os.path.join ( self.physical_location, 'profile= s' ) @@ -115,7 +116,7 @@ class Overlay ( object ): returns: None (implicit) """ for cat in self._categories.values(): - cat.show ( default_header=3Dself._default_header ) + cat.show ( default_header=3Dself._get_header() ) # --- end of show (...) --- =20 def write ( self, **write_kw ): @@ -138,7 +139,7 @@ class Overlay ( object ): for cat in self._categories.values(): if cat.physical_location and not cat.empty(): util.dodir ( cat.physical_location ) - cat.write ( default_header=3Dself._default_header ) + cat.write ( default_header=3Dself._get_header() ) =20 self._write_categories ( only_active=3DTrue ) # --- end of write (...) --- @@ -253,29 +254,58 @@ class Overlay ( object ): self._write_profiles_file ( 'use.desc', use_desc + '\n' ) # --- end of _write_usedesc (...) --- =20 + def _get_eclass_import_info ( self, only_eclass_names=3DFalse ): + """Yields eclass import information (eclass names and files). + + arguments: + * only_eclass_names -- if True: yield eclass dest names only, + else : yield (eclass name, eclass src file) + Defaults to False. + + raises: AssertionError if a file does not end with '.eclass'. + """ + if self.eclass_files: + + for eclass in self.eclass_files: + dest =3D os.path.splitext ( os.path.basename ( eclass ) ) + + if dest[1] =3D=3D '.eclass' or ( not dest[1] and not '.' in dest[0] = ): + if only_eclass_names: + yield dest[0] + else: + yield ( dest[0], eclass ) + else: + raise AssertionError ( + "{!r} does not end with '.eclass'!".format ( eclass ) + ) + # --- end of _get_eclass_import_info (...) --- + def _import_eclass ( self, reimport_eclass ): + """Imports eclass files to the overlay. Also sets ebuild_names. + + arguments: + * reimport_eclass -- whether to import existing eclass files (again) + + raises: + * AssertionError, passed from _get_eclass_import_info() + * Exception if copying fails + """ =20 if self.eclass_files: # import eclass files eclass_dir =3D os.path.join ( self.physical_location, 'eclass' ) try: + eclass_names =3D list() util.dodir ( eclass_dir ) =20 - for eclass in self.eclass_files: - src =3D eclass - dest =3D None - if isinstance ( eclass, str ): - dest =3D os.path.basename ( eclass ) - else: - # list-like specification ( src, destname ) - src =3D eclass [0] - dest =3D eclass [1] - - dest =3D os.path.join ( eclass_dir, dest ) - + for destname, eclass in self._get_eclass_import_info ( False ): + dest =3D os.path.join ( eclass_dir, destname + '.eclass' ) if reimport_eclass or not os.path.isfile ( dest ): - shutil.copyfile ( src, dest ) + shutil.copyfile ( eclass, dest ) =20 + eclass_names.append ( destname ) + + self.eclass_names =3D frozenset ( eclass_names ) =20 except Exception as e: self.logger.critical ( "Cannot import eclass files!" ) @@ -311,10 +341,29 @@ class Overlay ( object ): self.logger.exception ( e ) self.logger.critical ( "^failed to init overlay" ) raise + # --- end of _init_overlay (...) --- + + def _get_header ( self ): + """Returns the ebuild header (including inherit ).""" + if self.eclass_names is None: + # writing is possibly disabled since eclass files have not been + # imported (or show() used before write()) + inherit =3D ' '.join ( self._get_eclass_import_info ( True ) ) + else: + inherit =3D ' '.join ( self.eclass_names ) =20 + inherit =3D "inherit " + inherit if inherit else None =20 + # header and inherit is expected and therefore the first condition her= e + if inherit and self._default_header: + return '\n'.join (( self._default_header, '', inherit )) =20 + elif inherit: + return inherit =20 + elif self._default_header: + return self._default_header =20 - - + else: + return None + # --- end of _get_header (...) ---