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/overlay/
Date: Thu,  5 Jul 2012 16:00:12 +0000 (UTC)	[thread overview]
Message-ID: <1341503980.9d2a243a6e6eadc71e3962726b29c84d1251d732.dywi@gentoo> (raw)

commit:     9d2a243a6e6eadc71e3962726b29c84d1251d732
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Jul  5 15:59:40 2012 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Jul  5 15:59:40 2012 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=9d2a243a

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 = eclass_files
 
+		self.eclass_names = None
 
 		#
 		self._profiles_dir = os.path.join ( self.physical_location, 'profiles' )
@@ -115,7 +116,7 @@ class Overlay ( object ):
 		returns: None (implicit)
 		"""
 		for cat in self._categories.values():
-			cat.show ( default_header=self._default_header )
+			cat.show ( default_header=self._get_header() )
 	# --- end of show (...) ---
 
 	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=self._default_header )
+				cat.write ( default_header=self._get_header() )
 
 		self._write_categories ( only_active=True )
 	# --- end of write (...) ---
@@ -253,29 +254,58 @@ class Overlay ( object ):
 			self._write_profiles_file ( 'use.desc', use_desc + '\n' )
 	# --- end of _write_usedesc (...) ---
 
+	def _get_eclass_import_info ( self, only_eclass_names=False ):
+		"""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 = os.path.splitext ( os.path.basename ( eclass ) )
+
+				if dest[1] == '.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
+		"""
 
 		if self.eclass_files:
 			# import eclass files
 			eclass_dir = os.path.join ( self.physical_location, 'eclass' )
 			try:
+				eclass_names = list()
 				util.dodir ( eclass_dir )
 
-				for eclass in self.eclass_files:
-					src  = eclass
-					dest = None
-					if isinstance ( eclass, str ):
-						dest = os.path.basename ( eclass )
-					else:
-						# list-like specification ( src, destname )
-						src  = eclass [0]
-						dest = eclass [1]
-
-					dest = os.path.join ( eclass_dir, dest )
-
+				for destname, eclass in self._get_eclass_import_info ( False ):
+					dest = os.path.join ( eclass_dir, destname + '.eclass' )
 					if reimport_eclass or not os.path.isfile ( dest ):
-						shutil.copyfile ( src, dest )
+						shutil.copyfile ( eclass, dest )
 
+					eclass_names.append ( destname )
+
+				self.eclass_names = frozenset ( eclass_names )
 
 			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 <eclasses>)."""
+		if self.eclass_names is None:
+				# writing is possibly disabled since eclass files have not been
+				# imported (or show() used before write())
+			inherit = ' '.join ( self._get_eclass_import_info ( True ) )
+		else:
+			inherit = ' '.join ( self.eclass_names )
 
+		inherit = "inherit " + inherit if inherit else None
 
+		# header and inherit is expected and therefore the first condition here
+		if inherit and self._default_header:
+			return '\n'.join (( self._default_header, '', inherit ))
 
+		elif inherit:
+			return inherit
 
+		elif self._default_header:
+			return self._default_header
 
-
-
+		else:
+			return None
+	# --- end of _get_header (...) ---



             reply	other threads:[~2012-07-05 16:00 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2012-07-05 16:00 André Erdmann [this message]
  -- strict thread matches above, loose matches on Subject: below --
2014-08-23 19:03 [gentoo-commits] proj/R_overlay:master commit in: roverlay/overlay/ André Erdmann
2014-07-29 18:29 ` André Erdmann
2014-07-18 16:20 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-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-04-01 16:38 André Erdmann
2013-09-18 14:00 André Erdmann
2013-09-17 13:49 André Erdmann
2013-09-03 15:51 André Erdmann
2013-09-03 13:15 André Erdmann
2013-09-03  8:35 André Erdmann
2013-09-02 16:21 André Erdmann
2013-09-02 16:21 André Erdmann
2013-08-29 12:36 André Erdmann
2013-08-20 21:46 André Erdmann
2013-08-20 21:46 André Erdmann
2013-07-29 14:56 André Erdmann
2013-07-10 15:10 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-10 16:16 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
2013-06-22 15:24 André Erdmann
2013-06-18 14:12 André Erdmann
2013-06-13 16:34 André Erdmann
2013-04-25 16:44 André Erdmann
2013-04-25 16:44 André Erdmann
2013-02-09 21:28 André Erdmann
2013-02-09 20:45 André Erdmann
2013-02-09 20:45 André Erdmann
2013-01-30 20:16 André Erdmann
2012-08-17 17:26 André Erdmann
2012-08-03 13:38 André Erdmann
2012-08-01 21:10 André Erdmann
2012-07-30 15:53 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-04 18:21 André Erdmann
2012-07-03 17:48 André Erdmann
2012-06-27 14:46 André Erdmann
2012-06-26 15:42 André Erdmann
2012-06-22 18:13 André Erdmann
2012-06-21 16:55 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=1341503980.9d2a243a6e6eadc71e3962726b29c84d1251d732.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