From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 9F6F51381F3 for ; Sun, 30 Jun 2013 15:58:14 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id 35A6BE0984; Sun, 30 Jun 2013 15:58:14 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 8C3B6E0984 for ; Sun, 30 Jun 2013 15:58:13 +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 6D38633E740 for ; Sun, 30 Jun 2013 15:58:12 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id 12C76E5460 for ; Sun, 30 Jun 2013 15:58:11 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1372194481.df58d07cbadab7bdd5f6a494355c8dac9f840d09.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/, roverlay/config/, roverlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/config/const.py roverlay/config/entrymap.py roverlay/hook.py roverlay/main.py roverlay/tools/shenv.py X-VCS-Directories: roverlay/tools/ roverlay/config/ roverlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: df58d07cbadab7bdd5f6a494355c8dac9f840d09 X-VCS-Branch: master Date: Sun, 30 Jun 2013 15:58:11 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: 93e72dd1-c9c3-4ed7-b80f-382ba84622af X-Archives-Hash: f253cc35ecda562a5d94fb22c794139b commit: df58d07cbadab7bdd5f6a494355c8dac9f840d09 Author: André Erdmann mailerd de> AuthorDate: Tue Jun 25 21:08:01 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Tue Jun 25 21:08:01 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=df58d07c EVENT_HOOK_RESTRICT, roverlay.hook --- roverlay/config/const.py | 4 ++ roverlay/config/entrymap.py | 29 +++++--- roverlay/hook.py | 169 ++++++++++++++++++++++++++++++++++++++++++++ roverlay/main.py | 7 +- roverlay/tools/shenv.py | 22 ++---- 5 files changed, 204 insertions(+), 27 deletions(-) diff --git a/roverlay/config/const.py b/roverlay/config/const.py index 4ee9d45..f9a2e14 100644 --- a/roverlay/config/const.py +++ b/roverlay/config/const.py @@ -78,6 +78,10 @@ _CONSTANTS = dict ( manifest_implementation = 'default', ), + EVENT_HOOK = dict ( + default_exe_relpath = [ 'hooks', 'mux.sh' ], + ), + TOOLS = dict ( EBUILD = dict ( exe = "/usr/bin/ebuild", diff --git a/roverlay/config/entrymap.py b/roverlay/config/entrymap.py index 136b4b5..6a282d9 100644 --- a/roverlay/config/entrymap.py +++ b/roverlay/config/entrymap.py @@ -306,6 +306,12 @@ CONFIG_ENTRY_MAP = dict ( value_type = yesno, ), + overlay_distmap_file = dict ( + path = [ 'OVERLAY', 'DISTMAP', 'dbfile', ] + value_type = 'fs_file', + description = 'distmap file', + ), + # * alias backup_desc = 'overlay_backup_desc', eclass = 'overlay_eclass', @@ -316,6 +322,7 @@ CONFIG_ENTRY_MAP = dict ( distdir_strategy = 'overlay_distdir_strategy', distdir_flat = 'overlay_distdir_flat', distdir_verify = 'overlay_distdir_verify', + distmap_file = 'overlay_distmap_file', # --- overlay @@ -449,14 +456,22 @@ CONFIG_ENTRY_MAP = dict ( description = 'filter shell env', ), - hook_script = dict ( - path = [ 'SHELL_ENV', 'hook', ], - value_type = 'fs_file', + event_hook = dict ( + path = [ 'EVENT_HOOK', 'exe', ], + value_type = 'fs_file', description = 'script that is run on certain events, e.g. overlay_success', ), + event_hook_restrict = dict ( + path = [ 'EVENT_HOOK', 'restrict', ], + value_type = 'list:str', + description = 'mask for running hooks', + ), + + # * alias - hook = 'hook_script', + hook = 'event_hook', + hook_restrict = 'event_hook_restrict', # == other == @@ -467,12 +482,6 @@ CONFIG_ENTRY_MAP = dict ( description = 'directory for cache data', ), - tmpdir = dict ( - path = [ 'TMPDIR', 'root', ], - value_type = 'fs_dir', - description = 'directory for temporary data', - ), - nosync = dict ( value_type = yesno, description = 'forbid/allow syncing with remotes', diff --git a/roverlay/hook.py b/roverlay/hook.py new file mode 100644 index 0000000..3b13315 --- /dev/null +++ b/roverlay/hook.py @@ -0,0 +1,169 @@ +# R overlay -- run roverlay hooks (shell scripts) +# -*- coding: utf-8 -*- +# Copyright (C) 2013 André Erdmann +# Distributed under the terms of the GNU General Public License; +# either version 2 of the License, or (at your option) any later version. + +import os.path +import logging + +import roverlay.config +import roverlay.tools.shenv + +__all__ = [ 'run_hook', 'phase_allowed', ] + +LOGGER = logging.getLogger ( 'event_hook' ) + + +_EVENT_SCRIPT = None + +# None|iterable _EVENT_RESTRICT +_EVENT_RESTRICT = None + +# int _EVENT_POLICY +# -1: no policy (allow all) +# 0: not configured +# 1: allow unless in _EVENT_RESTRICT (blacklist) +# 2: deny unless in _EVENT_RESTRICT (whitelist) +# 4: deny all +_EVENT_POLICY = 0 + +def setup(): + global _EVENT_SCRIPT + global _EVENT_POLICY + global _EVENT_RESTRICT + + _EVENT_SCRIPT = roverlay.config.get ( 'EVENT_HOOK.exe', False ) + if _EVENT_SCRIPT is False: + a_dir = roverlay.config.get ( 'OVERLAY.additions_dir', None ) + if a_dir: + s = os.path.join ( + a_dir, + *roverlay.config.get_or_fail ( 'EVENT_HOOK.default_exe_relpath' ) + ) + if os.path.isfile ( s ): + _EVENT_SCRIPT = s + # -- end if _EVENT_SCRIPT + + conf_restrict = roverlay.config.get ( 'EVENT_HOOK.restrict', False ) + + if conf_restrict: + # tristate None,False,True + is_whitelist = None + allow = set() + deny = set() + for p in conf_restrict: + if p == '*': + # "allow all" + is_whitelist = False + elif p == '-*': + # "deny all" + is_whitelist = True + elif p == '-' or p == '+': + # empty + pass + elif p[0] == '-': + # deny + k = p[1:].lower() + deny.add ( k ) + try: + allow.remove ( k ) + except KeyError: + pass + else: + # allow + k = ( p[1:] if p[0] == '+' else p ).lower() + allow.add ( k ) + try: + deny.remove ( k ) + except KeyError: + pass + # -- end for; + + if is_whitelist is None: + # allow is set => is whitelist + # neither allow nor deny are set => deny allow + is_whitelist = bool ( allow or not deny ) + # -- end if is_whitelist #1 + + if is_whitelist: + if allow: + _EVENT_RESTRICT = frozenset ( allow ) + _EVENT_POLICY = 2 + else: + _EVENT_POLICY = 4 + elif deny: + _EVENT_RESTRICT = frozenset ( deny ) + _EVENT_POLICY = 1 + else: + _EVENT_POLICY = -1 + # -- end if is_whitelist #2 + else: + _EVENT_POLICY = -1 + # -- end if conf_restrict +# --- end of setup (...) --- + +def phase_allowed ( phase ): + if _EVENT_POLICY == -1: + return True + elif _EVENT_POLICY == 1: + # allow unless in restrict + if phase not in _EVENT_RESTRICT: + return True + else: + LOGGER.debug ( + "phase {!r} denied by blacklist policy.".format ( phase ) + ) + elif _EVENT_POLICY == 2: + # deny unless in restrict + if phase in _EVENT_RESTRICT: + return True + else: + LOGGER.debug ( + "phase {!r} denied by whitelist policy.".format ( phase ) + ) + elif _EVENT_POLICY == 4: + LOGGER.debug ( + "phase {!r} denied by 'deny all' policy".format ( phase ) + ) + else: + LOGGER.warning ( + "phase {!r} denied by undefined policy {} (fix this)".format ( + phase, _EVENT_POLICY + ) + ) + # -- end if _EVENT_POLICY + + # default return + return False +# --- end of phase_allowed (...) --- + +def phase_allowed_nolog ( phase ): + return ( + _EVENT_POLICY == -1 + ) or ( + _EVENT_POLICY == 1 and phase not in _EVENT_RESTRICT + ) or ( + _EVENT_POLICY == 2 and phase in _EVENT_RESTRICT + ) +# --- end of phase_allowed_nolog (...) --- + +def run ( phase ): + if _EVENT_SCRIPT is None: + LOGGER.warning ( + "hook module not initialized - doing that now (FIXME!)" + ) + setup() + + + + if _EVENT_SCRIPT and phase_allowed ( phase ): + return roverlay.tools.shenv.run_script ( + _EVENT_SCRIPT, phase, return_success=True + ) + else: + # nop + return True +# --- end of run (...) --- + +run_hook = run diff --git a/roverlay/main.py b/roverlay/main.py index 901cbcf..4822e21 100644 --- a/roverlay/main.py +++ b/roverlay/main.py @@ -289,7 +289,7 @@ def main ( # this hook should be called _after_ verifying the overlay # (verification is not implemented yet) # - if not roverlay.tools.shenv.run_hook ( 'overlay_success' ): + if not roverlay.hook.run ( 'overlay_success' ): die ( "overlay_success hook returned non-zero", DIE.OV_CREATE ) set_action_done ( "create" ) @@ -476,7 +476,7 @@ def main ( from roverlay.overlay.creator import OverlayCreator import roverlay.config - import roverlay.tools.shenv + import roverlay.hook except ImportError: if HIDE_EXCEPTIONS: die ( "Cannot import roverlay modules!", DIE.IMPORT ) @@ -491,6 +491,9 @@ def main ( # -- run + # initialize roverlay.hook + roverlay.hook.setup() + # always run sync 'cause commands = {create,sync,apply_rules} # and create,apply_rules implies (no)sync run_sync() diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py index 85644d4..f0c054b 100644 --- a/roverlay/tools/shenv.py +++ b/roverlay/tools/shenv.py @@ -1,4 +1,4 @@ -# R overlay -- tools, run roverlay hooks (shell scripts) +# R overlay -- tools, shell script environment # -*- coding: utf-8 -*- # Copyright (C) 2013 André Erdmann # Distributed under the terms of the GNU General Public License; @@ -8,6 +8,7 @@ import logging import os import subprocess import tempfile +import time import roverlay.config @@ -18,7 +19,6 @@ import roverlay.util # _SHELL_ENV, _SHELL_INTPR are created when calling run_script() # _SHELL_ENV = None -_SHELL_ENV_SCRIPT = None #_SHELL_INTPR = None LOGGER = logging.getLogger ( 'shenv' ) @@ -287,7 +287,11 @@ def run_script ( script, phase, return_success=False, logger=None ): output = script_call.communicate() except: - script_call.kill() + try: + script_call.terminate() + time.sleep ( 1 ) + finally: + script_call.kill() raise @@ -327,15 +331,3 @@ def run_script ( script, phase, return_success=False, logger=None ): else: return script_call # --- end of run_script (...) --- - -def run_hook ( phase ): - global _SHELL_ENV_SCRIPT - if _SHELL_ENV_SCRIPT is None: - _SHELL_ENV_SCRIPT = roverlay.config.get ( 'SHELL_ENV.hook', False ) - - if _SHELL_ENV_SCRIPT: - return run_script ( _SHELL_ENV_SCRIPT, phase, return_success=True ) - else: - # nop - return True -# --- end of run_hook (...) --- From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from lists.gentoo.org (pigeon.gentoo.org [208.92.234.80]) by finch.gentoo.org (Postfix) with ESMTP id 9FE791381F3 for ; Tue, 25 Jun 2013 21:10:41 +0000 (UTC) Received: from pigeon.gentoo.org (localhost [127.0.0.1]) by pigeon.gentoo.org (Postfix) with SMTP id D4570E095D; Tue, 25 Jun 2013 21:10:38 +0000 (UTC) Received: from smtp.gentoo.org (smtp.gentoo.org [140.211.166.183]) (using TLSv1 with cipher AECDH-AES256-SHA (256/256 bits)) (No client certificate requested) by pigeon.gentoo.org (Postfix) with ESMTPS id 51EF2E095D for ; Tue, 25 Jun 2013 21:10:38 +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 34D7633E71E for ; Tue, 25 Jun 2013 21:10:37 +0000 (UTC) Received: from localhost.localdomain (localhost [127.0.0.1]) by hornbill.gentoo.org (Postfix) with ESMTP id CAA13E545E for ; Tue, 25 Jun 2013 21:10:35 +0000 (UTC) From: "André Erdmann" To: gentoo-commits@lists.gentoo.org Content-Transfer-Encoding: 8bit Content-type: text/plain; charset=UTF-8 Reply-To: gentoo-dev@lists.gentoo.org, "André Erdmann" Message-ID: <1372194481.df58d07cbadab7bdd5f6a494355c8dac9f840d09.dywi@gentoo> Subject: [gentoo-commits] proj/R_overlay:gsoc13/next commit in: roverlay/tools/, roverlay/config/, roverlay/ X-VCS-Repository: proj/R_overlay X-VCS-Files: roverlay/config/const.py roverlay/config/entrymap.py roverlay/hook.py roverlay/main.py roverlay/tools/shenv.py X-VCS-Directories: roverlay/tools/ roverlay/config/ roverlay/ X-VCS-Committer: dywi X-VCS-Committer-Name: André Erdmann X-VCS-Revision: df58d07cbadab7bdd5f6a494355c8dac9f840d09 X-VCS-Branch: gsoc13/next Date: Tue, 25 Jun 2013 21:10:35 +0000 (UTC) Precedence: bulk List-Post: List-Help: List-Unsubscribe: List-Subscribe: List-Id: Gentoo Linux mail X-BeenThere: gentoo-commits@lists.gentoo.org X-Archives-Salt: c4df65f0-6875-4444-bdd0-6cb232c6566b X-Archives-Hash: f5443bc4a90a3d77deaa8d199928cc0a Message-ID: <20130625211035.hAGyNPBNH-MbNbJkk45p1UdlI5fLrMkIXBBMuhfQZX0@z> commit: df58d07cbadab7bdd5f6a494355c8dac9f840d09 Author: André Erdmann mailerd de> AuthorDate: Tue Jun 25 21:08:01 2013 +0000 Commit: André Erdmann mailerd de> CommitDate: Tue Jun 25 21:08:01 2013 +0000 URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=df58d07c EVENT_HOOK_RESTRICT, roverlay.hook --- roverlay/config/const.py | 4 ++ roverlay/config/entrymap.py | 29 +++++--- roverlay/hook.py | 169 ++++++++++++++++++++++++++++++++++++++++++++ roverlay/main.py | 7 +- roverlay/tools/shenv.py | 22 ++---- 5 files changed, 204 insertions(+), 27 deletions(-) diff --git a/roverlay/config/const.py b/roverlay/config/const.py index 4ee9d45..f9a2e14 100644 --- a/roverlay/config/const.py +++ b/roverlay/config/const.py @@ -78,6 +78,10 @@ _CONSTANTS = dict ( manifest_implementation = 'default', ), + EVENT_HOOK = dict ( + default_exe_relpath = [ 'hooks', 'mux.sh' ], + ), + TOOLS = dict ( EBUILD = dict ( exe = "/usr/bin/ebuild", diff --git a/roverlay/config/entrymap.py b/roverlay/config/entrymap.py index 136b4b5..6a282d9 100644 --- a/roverlay/config/entrymap.py +++ b/roverlay/config/entrymap.py @@ -306,6 +306,12 @@ CONFIG_ENTRY_MAP = dict ( value_type = yesno, ), + overlay_distmap_file = dict ( + path = [ 'OVERLAY', 'DISTMAP', 'dbfile', ] + value_type = 'fs_file', + description = 'distmap file', + ), + # * alias backup_desc = 'overlay_backup_desc', eclass = 'overlay_eclass', @@ -316,6 +322,7 @@ CONFIG_ENTRY_MAP = dict ( distdir_strategy = 'overlay_distdir_strategy', distdir_flat = 'overlay_distdir_flat', distdir_verify = 'overlay_distdir_verify', + distmap_file = 'overlay_distmap_file', # --- overlay @@ -449,14 +456,22 @@ CONFIG_ENTRY_MAP = dict ( description = 'filter shell env', ), - hook_script = dict ( - path = [ 'SHELL_ENV', 'hook', ], - value_type = 'fs_file', + event_hook = dict ( + path = [ 'EVENT_HOOK', 'exe', ], + value_type = 'fs_file', description = 'script that is run on certain events, e.g. overlay_success', ), + event_hook_restrict = dict ( + path = [ 'EVENT_HOOK', 'restrict', ], + value_type = 'list:str', + description = 'mask for running hooks', + ), + + # * alias - hook = 'hook_script', + hook = 'event_hook', + hook_restrict = 'event_hook_restrict', # == other == @@ -467,12 +482,6 @@ CONFIG_ENTRY_MAP = dict ( description = 'directory for cache data', ), - tmpdir = dict ( - path = [ 'TMPDIR', 'root', ], - value_type = 'fs_dir', - description = 'directory for temporary data', - ), - nosync = dict ( value_type = yesno, description = 'forbid/allow syncing with remotes', diff --git a/roverlay/hook.py b/roverlay/hook.py new file mode 100644 index 0000000..3b13315 --- /dev/null +++ b/roverlay/hook.py @@ -0,0 +1,169 @@ +# R overlay -- run roverlay hooks (shell scripts) +# -*- coding: utf-8 -*- +# Copyright (C) 2013 André Erdmann +# Distributed under the terms of the GNU General Public License; +# either version 2 of the License, or (at your option) any later version. + +import os.path +import logging + +import roverlay.config +import roverlay.tools.shenv + +__all__ = [ 'run_hook', 'phase_allowed', ] + +LOGGER = logging.getLogger ( 'event_hook' ) + + +_EVENT_SCRIPT = None + +# None|iterable _EVENT_RESTRICT +_EVENT_RESTRICT = None + +# int _EVENT_POLICY +# -1: no policy (allow all) +# 0: not configured +# 1: allow unless in _EVENT_RESTRICT (blacklist) +# 2: deny unless in _EVENT_RESTRICT (whitelist) +# 4: deny all +_EVENT_POLICY = 0 + +def setup(): + global _EVENT_SCRIPT + global _EVENT_POLICY + global _EVENT_RESTRICT + + _EVENT_SCRIPT = roverlay.config.get ( 'EVENT_HOOK.exe', False ) + if _EVENT_SCRIPT is False: + a_dir = roverlay.config.get ( 'OVERLAY.additions_dir', None ) + if a_dir: + s = os.path.join ( + a_dir, + *roverlay.config.get_or_fail ( 'EVENT_HOOK.default_exe_relpath' ) + ) + if os.path.isfile ( s ): + _EVENT_SCRIPT = s + # -- end if _EVENT_SCRIPT + + conf_restrict = roverlay.config.get ( 'EVENT_HOOK.restrict', False ) + + if conf_restrict: + # tristate None,False,True + is_whitelist = None + allow = set() + deny = set() + for p in conf_restrict: + if p == '*': + # "allow all" + is_whitelist = False + elif p == '-*': + # "deny all" + is_whitelist = True + elif p == '-' or p == '+': + # empty + pass + elif p[0] == '-': + # deny + k = p[1:].lower() + deny.add ( k ) + try: + allow.remove ( k ) + except KeyError: + pass + else: + # allow + k = ( p[1:] if p[0] == '+' else p ).lower() + allow.add ( k ) + try: + deny.remove ( k ) + except KeyError: + pass + # -- end for; + + if is_whitelist is None: + # allow is set => is whitelist + # neither allow nor deny are set => deny allow + is_whitelist = bool ( allow or not deny ) + # -- end if is_whitelist #1 + + if is_whitelist: + if allow: + _EVENT_RESTRICT = frozenset ( allow ) + _EVENT_POLICY = 2 + else: + _EVENT_POLICY = 4 + elif deny: + _EVENT_RESTRICT = frozenset ( deny ) + _EVENT_POLICY = 1 + else: + _EVENT_POLICY = -1 + # -- end if is_whitelist #2 + else: + _EVENT_POLICY = -1 + # -- end if conf_restrict +# --- end of setup (...) --- + +def phase_allowed ( phase ): + if _EVENT_POLICY == -1: + return True + elif _EVENT_POLICY == 1: + # allow unless in restrict + if phase not in _EVENT_RESTRICT: + return True + else: + LOGGER.debug ( + "phase {!r} denied by blacklist policy.".format ( phase ) + ) + elif _EVENT_POLICY == 2: + # deny unless in restrict + if phase in _EVENT_RESTRICT: + return True + else: + LOGGER.debug ( + "phase {!r} denied by whitelist policy.".format ( phase ) + ) + elif _EVENT_POLICY == 4: + LOGGER.debug ( + "phase {!r} denied by 'deny all' policy".format ( phase ) + ) + else: + LOGGER.warning ( + "phase {!r} denied by undefined policy {} (fix this)".format ( + phase, _EVENT_POLICY + ) + ) + # -- end if _EVENT_POLICY + + # default return + return False +# --- end of phase_allowed (...) --- + +def phase_allowed_nolog ( phase ): + return ( + _EVENT_POLICY == -1 + ) or ( + _EVENT_POLICY == 1 and phase not in _EVENT_RESTRICT + ) or ( + _EVENT_POLICY == 2 and phase in _EVENT_RESTRICT + ) +# --- end of phase_allowed_nolog (...) --- + +def run ( phase ): + if _EVENT_SCRIPT is None: + LOGGER.warning ( + "hook module not initialized - doing that now (FIXME!)" + ) + setup() + + + + if _EVENT_SCRIPT and phase_allowed ( phase ): + return roverlay.tools.shenv.run_script ( + _EVENT_SCRIPT, phase, return_success=True + ) + else: + # nop + return True +# --- end of run (...) --- + +run_hook = run diff --git a/roverlay/main.py b/roverlay/main.py index 901cbcf..4822e21 100644 --- a/roverlay/main.py +++ b/roverlay/main.py @@ -289,7 +289,7 @@ def main ( # this hook should be called _after_ verifying the overlay # (verification is not implemented yet) # - if not roverlay.tools.shenv.run_hook ( 'overlay_success' ): + if not roverlay.hook.run ( 'overlay_success' ): die ( "overlay_success hook returned non-zero", DIE.OV_CREATE ) set_action_done ( "create" ) @@ -476,7 +476,7 @@ def main ( from roverlay.overlay.creator import OverlayCreator import roverlay.config - import roverlay.tools.shenv + import roverlay.hook except ImportError: if HIDE_EXCEPTIONS: die ( "Cannot import roverlay modules!", DIE.IMPORT ) @@ -491,6 +491,9 @@ def main ( # -- run + # initialize roverlay.hook + roverlay.hook.setup() + # always run sync 'cause commands = {create,sync,apply_rules} # and create,apply_rules implies (no)sync run_sync() diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py index 85644d4..f0c054b 100644 --- a/roverlay/tools/shenv.py +++ b/roverlay/tools/shenv.py @@ -1,4 +1,4 @@ -# R overlay -- tools, run roverlay hooks (shell scripts) +# R overlay -- tools, shell script environment # -*- coding: utf-8 -*- # Copyright (C) 2013 André Erdmann # Distributed under the terms of the GNU General Public License; @@ -8,6 +8,7 @@ import logging import os import subprocess import tempfile +import time import roverlay.config @@ -18,7 +19,6 @@ import roverlay.util # _SHELL_ENV, _SHELL_INTPR are created when calling run_script() # _SHELL_ENV = None -_SHELL_ENV_SCRIPT = None #_SHELL_INTPR = None LOGGER = logging.getLogger ( 'shenv' ) @@ -287,7 +287,11 @@ def run_script ( script, phase, return_success=False, logger=None ): output = script_call.communicate() except: - script_call.kill() + try: + script_call.terminate() + time.sleep ( 1 ) + finally: + script_call.kill() raise @@ -327,15 +331,3 @@ def run_script ( script, phase, return_success=False, logger=None ): else: return script_call # --- end of run_script (...) --- - -def run_hook ( phase ): - global _SHELL_ENV_SCRIPT - if _SHELL_ENV_SCRIPT is None: - _SHELL_ENV_SCRIPT = roverlay.config.get ( 'SHELL_ENV.hook', False ) - - if _SHELL_ENV_SCRIPT: - return run_script ( _SHELL_ENV_SCRIPT, phase, return_success=True ) - else: - # nop - return True -# --- end of run_hook (...) ---