diff options
author | 2013-08-07 17:47:51 +0200 | |
---|---|---|
committer | 2013-08-07 17:47:51 +0200 | |
commit | ded0b9889dee769fcb8e767932b13afba3e328cb (patch) | |
tree | a2a4d443d4c628b51f2540f46e1aa79067d4f786 | |
parent | import ebuilds: fix manifest creation (diff) | |
download | R_overlay-ded0b9889dee769fcb8e767932b13afba3e328cb.tar.gz R_overlay-ded0b9889dee769fcb8e767932b13afba3e328cb.tar.bz2 R_overlay-ded0b9889dee769fcb8e767932b13afba3e328cb.zip |
distroot: avoid _cleanup() atexit
Do not call _cleanup() at exit if it can be done before. This allows to run
the 'overlay_success'/'db_written' hooks _after_ having cleaned up the
distroot (and with a correct distmap file).
-rw-r--r-- | roverlay/overlay/pkgdir/distroot/distroot.py | 29 | ||||
-rw-r--r-- | roverlay/overlay/pkgdir/distroot/static.py | 70 | ||||
-rw-r--r-- | roverlay/overlay/root.py | 5 |
3 files changed, 63 insertions, 41 deletions
diff --git a/roverlay/overlay/pkgdir/distroot/distroot.py b/roverlay/overlay/pkgdir/distroot/distroot.py index 7c4a18f..609dea3 100644 --- a/roverlay/overlay/pkgdir/distroot/distroot.py +++ b/roverlay/overlay/pkgdir/distroot/distroot.py @@ -61,9 +61,33 @@ class DistrootBase ( object ): os.makedirs ( self._root, 0o755 ) self._prepare() - atexit.register ( self._cleanup ) + + # python 2's atexit has no unregister() + # using a "guardian" function + a bool + self.finalize_at_exit = True + atexit.register ( self._atexit_run ) # --- end of __init__ (...) --- + def _atexit_run ( self ): + if self.finalize_at_exit: + self.finalize() + # --- end of _atexit_run (...) --- + + def finalize ( self, backup_distmap=True ): + # disable finalize_at_exit first so that exceptions cannot trigger + # _atexit_run()->this function + # + self.logger.info ( "finalizing" ) + self.finalize_at_exit = False + + self._cleanup() + if self.distmap is not None: + if backup_distmap: + self.distmap.backup_and_write ( force=False ) + else: + self.distmap.write ( force=False ) + # --- end of finalize (...) --- + def _add ( self, src, dest ): """Adds src to the distroot. @@ -448,9 +472,6 @@ class PersistentDistroot ( DistrootBase ): if hasattr ( self, '_supported_modes_initial' ): if self._supported_modes_initial & self.USE_SYMLINK: self._remove_broken_symlinks() - - if self.distmap is not None: - self.distmap.write ( force=False ) # --- end of _cleanup (...) --- def _get_int_strategy ( self, strategy ): diff --git a/roverlay/overlay/pkgdir/distroot/static.py b/roverlay/overlay/pkgdir/distroot/static.py index ba153b6..81ab53f 100644 --- a/roverlay/overlay/pkgdir/distroot/static.py +++ b/roverlay/overlay/pkgdir/distroot/static.py @@ -8,54 +8,54 @@ __all__ = [ 'get_configured', 'get_distdir', ] import threading -import roverlay.recipe.distmap import roverlay.config - +import roverlay.recipe.distmap import roverlay.overlay.pkgdir.distroot.distroot _distroot_instance = None _instance_lock = threading.Lock() -def get_configured ( static=True ): +def access(): + return _distroot_instance +# --- end of access (...) --- + +def get_new_configured(): + """Returns a new distroot instance that uses config values.""" + distdir_strategy = roverlay.config.get_or_fail ( + 'OVERLAY.DISTDIR.strategy' + ) + if distdir_strategy [-1] == 'tmpdir': + return roverlay.overlay.pkgdir.distroot.distroot.TemporaryDistroot() + else: + return roverlay.overlay.pkgdir.distroot.distroot.PersistentDistroot ( + root = roverlay.config.get_or_fail ( 'OVERLAY.DISTDIR.root' ), + # generally, the "flat" distroot/distdir layout is desired as it + # can serve as package mirror directory, so default to True here + flat = roverlay.config.get ( 'OVERLAY.DISTDIR.flat', True ), + strategy = distdir_strategy, + distmap = roverlay.recipe.distmap.access(), + verify = roverlay.config.get ( 'OVERLAY.DISTDIR.verify', False ), + ) +# --- end of get_new_configured (...) --- + +def get_configured(): """Returns a distroot instance that uses config values. arguments: * static -- returns the 'static' instance (and creates it if necessary) """ - def get_new(): - """Returns a new distroot instance that uses config values.""" - distdir_strategy = roverlay.config.get_or_fail ( - 'OVERLAY.DISTDIR.strategy' - ) - if distdir_strategy [-1] == 'tmpdir': - return roverlay.overlay.pkgdir.distroot.distroot.TemporaryDistroot() - else: - return roverlay.overlay.pkgdir.distroot.distroot.PersistentDistroot ( - root = roverlay.config.get_or_fail ( 'OVERLAY.DISTDIR.root' ), - # generally, the "flat" distroot/distdir layout is desired as it - # can serve as package mirror directory, so default to True here - flat = roverlay.config.get ( 'OVERLAY.DISTDIR.flat', True ), - strategy = distdir_strategy, - distmap = roverlay.recipe.distmap.access(), - verify = roverlay.config.get ( 'OVERLAY.DISTDIR.verify', False ), - ) - # --- end of get_new (...) --- - - if static: - global _distroot_instance - - if _distroot_instance is None: - global _instance_lock - with _instance_lock: - if _distroot_instance is None: - _distroot_instance = get_new() - - return _distroot_instance - else: - raise Exception ( "static keyword arg is deprecated" ) + global _distroot_instance + + if _distroot_instance is None: + global _instance_lock + with _instance_lock: + if _distroot_instance is None: + _distroot_instance = get_new_configured() + + return _distroot_instance # --- end of get_configured (...) --- def get_distdir ( ebuild_name ): - return get_configured ( static=True ).get_distdir ( ebuild_name ) + return get_configured().get_distdir ( ebuild_name ) # --- end of get_distdir (...) --- diff --git a/roverlay/overlay/root.py b/roverlay/overlay/root.py index c404813..6e3b1d7 100644 --- a/roverlay/overlay/root.py +++ b/roverlay/overlay/root.py @@ -26,11 +26,11 @@ import threading import roverlay.config import roverlay.util -import roverlay.recipe.distmap import roverlay.overlay.additionsdir import roverlay.overlay.category import roverlay.overlay.header import roverlay.overlay.pkgdir.base +import roverlay.overlay.pkgdir.distroot.static class Overlay ( object ): DEFAULT_USE_DESC = ( @@ -865,7 +865,8 @@ class Overlay ( object ): additions_dir = self.additions_dir.get_obj_subdir ( cat ), ) - roverlay.recipe.distmap.access().backup_and_write() + # assumption: distroot exists + roverlay.overlay.pkgdir.distroot.static.access().finalize() else: # FIXME debug print print ( |