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: Tue, 17 Sep 2013 13:49:23 +0000 (UTC)	[thread overview]
Message-ID: <1379343403.4502c63561b4e6390ecc7457d11c4fc1c15e2829.dywi@gentoo> (raw)

commit:     4502c63561b4e6390ecc7457d11c4fc1c15e2829
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Mon Sep 16 14:56:43 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Mon Sep 16 14:56:43 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=4502c635

initialize overlay before importing ebuilds

from import_ebuilds()'s comment:
 do minimal overlay initialization before importing ebuilds.
 This is recommended because portage expects metadata/layout.conf to exist,
 for example.

---
 roverlay/overlay/root.py | 227 +++++++++++++++++++++++++----------------------
 1 file changed, 123 insertions(+), 104 deletions(-)

diff --git a/roverlay/overlay/root.py b/roverlay/overlay/root.py
index b3be5b3..0a3b15e 100644
--- a/roverlay/overlay/root.py
+++ b/roverlay/overlay/root.py
@@ -135,7 +135,6 @@ class Overlay ( roverlay.overlay.base.OverlayObject ):
       self._runtime_incremental = write_allowed and runtime_incremental
       self._writeable           = write_allowed
 
-      self._profiles_dir        = self.physical_location + os.sep + 'profiles'
       self._catlock             = threading.Lock()
       self._categories          = dict()
 
@@ -148,8 +147,8 @@ class Overlay ( roverlay.overlay.base.OverlayObject ):
          ebuild_header, eapi
       )
       self._use_desc = (
-         use_desc.rstrip() if use_desc is not None else self.DEFAULT_USE_DESC
-      )
+         use_desc if use_desc is not None else self.DEFAULT_USE_DESC
+      ).rstrip()
 
       if keep_n_ebuilds:
          self.keep_n_ebuilds = keep_n_ebuilds
@@ -271,133 +270,143 @@ class Overlay ( roverlay.overlay.base.OverlayObject ):
             raise
    # --- end of _import_eclass (...) ---
 
-   def _init_overlay ( self, reimport_eclass ):
+   def _generate_layout_conf ( self ):
+      # create layout.conf file
+      # * create lines
+
+      kv_join    = lambda k, v: "{k} = {v}".format ( k=k, v=v )
+      v_join     = lambda v: ' '.join ( v )
+
+      yield kv_join ( "repo_name", self.name )
+
+      if self._masters:
+         yield kv_join ( "masters", v_join ( self._masters ) )
+      else:
+         yield "masters ="
+
+
+      # strictly speaking,
+      #  declaring cache-formats here is not correct since egencache
+      #  is run as hook
+      yield kv_join ( "cache-formats", "md5-dict" )
+
+      ##yield kv_join ( "sign-commits", "false" )
+      ##yield kv_join ( "sign-manifests", "false" )
+      ##yield kv_join ( "thin-manifests", "false" )
+
+      hashes = roverlay.overlay.pkgdir.base.get_class().HASH_TYPES
+      if hashes:
+         yield kv_join ( "manifest-hashes", v_join ( hashes ) )
+   # --- end of _generate_layout_conf (...) ---
+
+   def _init_overlay ( self, reimport_eclass, minimal=False ):
       """Initializes the overlay at its physical/filesystem location.
 
       arguments:
-      * reimport_eclass   -- whether to copy existing eclass files
-                               again (True) or not
-      * make_profiles_dir -- if True: create the profiles/ dir now
+      * reimport_eclass -- whether to copy existing eclass files
+                            again (True) or not
+      * minimal         -- whether to do full overlay initialization (False)
+                           or not (True). Defaults to False.
 
       raises:
-      * IOError
+      * IOError, OSError -- passed from file writing / dir creation
       """
-      NEWLINE   = '\n'
-      EMPTY_STR = ""
+      NEWLINE            = '\n'
+      CONFIG_GET         = roverlay.config.get
+      CONFIG_GET_OR_FAIL = roverlay.config.get_or_fail
+      ROOT               = str ( self.physical_location )
+      METADATA_DIR       = ROOT + os.sep + 'metadata'
+      PROFILES_DIR       = ROOT + os.sep + 'profiles'
 
 
-      def write_profiles_dir():
-         """Creates and updates the profiles/ dir."""
-         def write_profiles_file ( filename, to_write ):
-            """Writes a file in profiles/.
+      def get_subdir_file_write ( root_dir ):
+         """Returns a function for writing files in the given directory.
+
+         arguments:
+         * root_dir --
+         """
+         def write_subdir_file ( relpath, content, append_newline=True ):
+            """Writes a file (<root_dir>/<relpath>).
 
             arguments:
-            * filename -- name of the file to write (including file extension)
-            * to_write -- string to write (don't forget newline at the end)
+            * relpath        -- file path relative to root_dir
+            * content        -- data to write
+            * append_newline -- whether to append a newline at EOF
             """
-            fh = None
-            try:
-               fh = open ( self._profiles_dir + os.sep + filename, 'w' )
-               if to_write:
-                  # else touch file
-                  fh.write ( to_write )
-            except IOError as e:
-               self.logger.exception ( e )
-               raise
-            finally:
-               if fh: fh.close()
-         # --- end of write_profiles_file (...) ---
-
-         # always use the default category (+write it into profiles/categories)
-         self._get_category ( self.default_category )
+            content_str = str ( content )
+            if content_str:
+               with open ( root_dir + os.sep + relpath, 'wt' ) as FH:
+                  FH.write ( content_str )
+                  if append_newline:
+                     FH.write ( NEWLINE )
+            else:
+               # touch file
+               with open ( root_dir + os.sep + relpath, 'a' ) as FH:
+                  pass
+         # --- end of write_subdir_file (...) ---
+         return write_subdir_file
+      # --- end of get_subdir_file_write (...) ---
 
-         # profiles/
-         roverlay.util.dodir ( self._profiles_dir )
 
-         # profiles/repo_name
-         write_profiles_file ( 'repo_name', self.name + '\n' )
-
-         # profiles/categories
-         cats = '\n'.join (
-            k for k, v in self._categories.items() if not v.empty()
-         )
-         if cats:
-            write_profiles_file ( 'categories', cats + '\n' )
-
-         # profiles/desc/<r_suggests>.desc
-         use_expand_name = roverlay.config.get_or_fail (
-            "EBUILD.USE_EXPAND.name"
-         ).rstrip ( "_" )
-
-         self._write_rsuggests_use_desc (
-            desc_file = (
-               self._profiles_dir + os.sep + 'desc' + os.sep
-               + use_expand_name.lower() + '.desc'
-            ),
-            use_expand_name = use_expand_name.upper(),
-            backup_file = roverlay.config.get ( 'OVERLAY.backup_desc', True ),
-            flagdesc_file = roverlay.config.get (
-               'EBUILD.USE_EXPAND.desc_file', None
-            ),
-         )
+      write_profiles_file = get_subdir_file_write ( PROFILES_DIR )
+      write_metadata_file = get_subdir_file_write ( METADATA_DIR )
 
+      try:
+         layout_conf_str = NEWLINE.join ( self._generate_layout_conf() )
 
-         # profiles/use.desc
-         if self._use_desc:
-            write_profiles_file ( 'use.desc', self._use_desc + '\n' )
-      # --- end of write_profiles_dir (...) ---
+         ## make overlay dirs, root, metadata/, profiles/
+         roverlay.util.dodir ( ROOT, mkdir_p=True )
+         roverlay.util.dodir ( PROFILES_DIR )
+         roverlay.util.dodir ( METADATA_DIR )
 
-      def write_metadata_dir():
 
-         METADATA_DIR = self.physical_location + os.sep + 'metadata'
-         roverlay.util.dodir ( METADATA_DIR )
+         ## import eclass files
+         self._import_eclass ( reimport_eclass )
 
-         # create layout.conf file
-         # * create lines
-         layout_lines = list()
-         layout_add = layout_lines.append
-         kv_join    = lambda k, v: "{k} = {v}".format ( k=k, v=v )
-         v_join     = lambda v: ' '.join ( v )
 
-         layout_add ( kv_join ( "repo_name", self.name ) )
+         ## populate profiles/
 
-         if self._masters:
-            layout_add ( kv_join ( "masters", v_join ( self._masters ) ) )
-         else:
-            layout_add ( "masters =" )
+         # profiles/repo_name
+         write_profiles_file ( 'repo_name', self.name )
 
+         # profiles/categories
+         cats = NEWLINE.join (
+            k for k, v in self._categories.items() if not v.empty()
+         )
+         if cats:
+            write_profiles_file ( 'categories', cats )
 
-         # strictly speaking,
-         #  declaring cache-formats here is not correct since egencache
-         #  is run as hook
-         layout_add ( kv_join ( "cache-formats", "md5-dict" ) )
 
-         ##layout_add ( kv_join ( "sign-commits", "false" ) )
-         ##layout_add ( kv_join ( "sign-manifests", "false" ) )
-         ##layout_add ( kv_join ( "thin-manifests", "false" ) )
+         if not minimal:
+            # profiles/desc/<r_suggests>.desc
+            use_expand_name = (
+               CONFIG_GET_OR_FAIL ( "EBUILD.USE_EXPAND.name" ).rstrip ( "_" )
+            )
 
-         hashes = roverlay.overlay.pkgdir.base.get_class().HASH_TYPES
-         if hashes:
-            layout_add ( kv_join ( "manifest-hashes", v_join ( hashes ) ) )
+            self._write_rsuggests_use_desc (
+               desc_file       = os.sep.join ([
+                  PROFILES_DIR, 'desc', use_expand_name.lower(), '.desc'
+               ]),
+               use_expand_name = use_expand_name.upper(),
+               backup_file     = CONFIG_GET ( 'OVERLAY.backup_desc', True ),
+               flagdesc_file   = CONFIG_GET (
+                  'EBUILD.USE_EXPAND.desc_file', None
+               ),
+            )
 
-         # * write it
-         with open ( METADATA_DIR + os.sep + 'layout.conf', 'wt' ) as FH:
-            for line in layout_lines:
-               FH.write ( line )
-               FH.write ( NEWLINE )
-      # --- end of write_metadata_dir (...) ---
 
-      try:
-         # mkdir overlay root
-         roverlay.util.dodir ( self.physical_location, mkdir_p=True )
+            # profiles/use.desc
+            if self._use_desc:
+               write_profiles_file ( 'use.desc', self._use_desc )
 
-         self._import_eclass ( reimport_eclass )
+         # -- end if not minimal ~ profiles/
 
-         write_profiles_dir()
-         write_metadata_dir()
+         ## metadata/
 
-      except IOError as e:
+         # metadata/layout.conf
+         write_metadata_file ( 'layout.conf', layout_conf_str )
 
+      except ( OSError, IOError ) as e:
          self.logger.exception ( e )
          self.logger.critical ( "failed to init overlay" )
          raise
@@ -710,13 +719,21 @@ class Overlay ( roverlay.overlay.base.OverlayObject ):
       return not self._writeable
    # --- end of readonly (...) ---
 
-   def import_ebuilds ( self, overwrite, nosync=False ):
+   def import_ebuilds ( self, overwrite, nosync=False, init_overlay=True ):
       """Imports ebuilds from the additions dir.
 
       arguments:
-      * overwrite -- whether to overwrite existing ebuilds
-      * nosync    -- if True: don't fetch src files (defaults to False)
+      * overwrite    -- whether to overwrite existing ebuilds
+      * nosync       -- if True: don't fetch src files (defaults to False)
+      * init_overlay -- if True: do minimal overlay initialization before
+                                 importing ebuilds. This is recommended
+                                 because portage expects metadata/layout.conf
+                                 to exist, for example.
+                                 Defaults to True.
       """
+      if init_overlay:
+         self._init_overlay ( False, minimal=True )
+
       for catview in (
          roverlay.overlay.additionsdir.CategoryRootView ( self.additions_dir )
       ):
@@ -887,7 +904,9 @@ class Overlay ( roverlay.overlay.base.OverlayObject ):
       if self._writeable and not self.skip_manifest:
          # profiles/categories is required for successful Manifest
          # creation
-         if os.path.isfile ( self._profiles_dir + os.sep + 'categories' ):
+         if os.path.isfile ( os.path.join (
+            str ( self.physical_location ), 'profiles', 'categories'
+         ) ):
             for cat in self._categories.values():
                cat.write_manifest ( **manifest_kw )
          else:


             reply	other threads:[~2013-09-17 13:49 UTC|newest]

Thread overview: 41+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2013-09-17 13:49 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-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-05 16:00 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=1379343403.4502c63561b4e6390ecc7457d11c4fc1c15e2829.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