public inbox for gentoo-commits@lists.gentoo.org
 help / color / mirror / Atom feed
* [gentoo-commits] proj/R_overlay:gsoc13/next commit in: files/shlib/, roverlay/tools/, roverlay/config/, roverlay/, files/hooks/
  2013-06-22 15:24 [gentoo-commits] proj/R_overlay:master commit in: files/shlib/, roverlay/tools/, roverlay/config/, roverlay/, files/hooks/ André Erdmann
@ 2013-06-21 18:16 ` André Erdmann
  0 siblings, 0 replies; 2+ messages in thread
From: André Erdmann @ 2013-06-21 18:16 UTC (permalink / raw
  To: gentoo-commits

commit:     14c25678f12b4b7be68fcd5be2181f8a65d60fa9
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Jun 21 18:13:28 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Jun 21 18:13:28 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=14c25678

roverlay, hooks: fixup, create git commit message

---
 .../{git-snapshot.sh => git-commit-overlay.sh}     | 67 ++++++++++++-------
 files/hooks/mux.sh                                 |  7 +-
 files/shlib/git.sh                                 | 15 +++--
 roverlay/config/entrymap.py                        | 18 ++++--
 roverlay/main.py                                   | 30 +--------
 roverlay/tools/shenv.py                            | 75 ++++++++++++++--------
 6 files changed, 121 insertions(+), 91 deletions(-)

diff --git a/files/hooks/git-snapshot.sh b/files/hooks/git-commit-overlay.sh
similarity index 56%
rename from files/hooks/git-snapshot.sh
rename to files/hooks/git-commit-overlay.sh
index cc3b2df..43060ab 100644
--- a/files/hooks/git-snapshot.sh
+++ b/files/hooks/git-commit-overlay.sh
@@ -7,10 +7,17 @@
 # * check whether the git repo exists, else create it
 # * check whether a clean commit can be made, that is (a) there are changes
 #   to commit and (b) the git index does not contain uncommitted changes
-# * then, add/commit changes
+# * then, add changes, create a commit message and finally commit
 #
 set -u
 
+# TODO:
+#
+# create meaningful commit messages
+# * include package list in the message body
+# -> git status --porcelain
+# -> 78/80 chars per line
+
 ## load core functions
 . "${FUNCTIONS?}" || exit
 #dont_run_as_root
@@ -21,9 +28,11 @@ $lf git
 
 ## "config" for this script
 # FIXME/TODO: remove config here?
-GIT_COMMIT_AUTHOR='undef undef@undef.org'
+GIT_COMMIT_AUTHOR='undef undef undef@undef.org'
 GIT_COMMIT_MESSAGE='roverlay updates'
 
+GIT_COMMIT_MAX_LINE_WIDTH=79
+
 
 ## other vars
 EX_ADD_ERR=2
@@ -40,13 +49,18 @@ git_try_rollback() {
    # release trap
    trap - INT TERM EXIT
    run_command_logged ${GIT} reset --mixed --quiet || true
+   if [ -n "${COMMIT_MSG_FILE-}" ]; then
+      rm -f "${COMMIT_MSG_FILE}"
+   fi
 }
 
-# int git_create_snapshot()
+# int git_commit()
 #
 #  Adds changes and creates a commit.
 #
-git_create_snapshot() {
+git_commit() {
+   local f="${T}/git_commit_message_$$"
+   local COMMIT_MSG_FILE
    trap git_try_rollback INT TERM EXIT
 
    # add changes
@@ -56,14 +70,23 @@ git_create_snapshot() {
       return ${EX_ADD_ERR}
    fi
 
+   # create a commit message (file)
+   {
+      echo "${GIT_COMMIT_MESSAGE}" && \
+      echo && \
+      ${GIT} status \
+         --porcelain --untracked-files=no --ignore-submodules | \
+            sed -n -e 's,^[MADRC].[[:blank:]]\(.*\)\/..*[.]ebuild$,\1,p' | \
+               sort -u | xargs echo | fold -s -w ${GIT_COMMIT_MAX_LINE_WIDTH}
+   } > "${f}" || die
+   COMMIT_MSG_FILE="${f}"
+
    # commit
-   # FIXME:
-   #  --author=?
-   #  --file=? or --message=?
    if run_command_logged \
       ${GIT} commit --quiet --no-edit \
-      --message="${GIT_COMMIT_MESSAGE}" --author="${GIT_COMMIT_AUTHOR}"
+         --file "${COMMIT_MSG_FILE}" --author="${GIT_COMMIT_AUTHOR}"
    then
+      rm "${COMMIT_MSG_FILE-}" && COMMIT_MSG_FILE=
       trap - INT TERM EXIT
       return 0
    else
@@ -76,28 +99,24 @@ git_create_snapshot() {
 ## main
 
 # $GIT_DIR, $S/.git, $HOME/.git, ...?
-if [ -d "${S}/.git" ]; then
-   true
 if [ ! -e "${S}/.git" ]; then
    einfo "Creating git repo"
    # FIXME: --shared OK?
    autodie ${GIT} init --quiet --shared=group "${S}"
-else
-   die "'${S}/.git should be a directory."
-fi
 
+   # assume that there are changes,
+   #  git_has_changes() does not work for new repos
+elif ! git_has_changes; then
+   veinfo "${SCRIPT_NAME}: nothing to do."
+   exit 0
+fi
 
-if git_has_changes; then
 
-   autodie git_create_snapshot
 
-   ##push changes to local repo?
-   ##
-   ##if ! yesno ${NOSYNC}; then
-   ##   #push changes to remote?
-   ##fi
+autodie git_commit
 
-else
-   veinfo "${SCRIPT_NAME}: nothing to do."
-   exit 0
-fi
+##push changes to local repo?
+##
+##if ! yesno ${NOSYNC}; then
+##   #push changes to remote?
+##fi

diff --git a/files/hooks/mux.sh b/files/hooks/mux.sh
index 0764b4d..c114db5 100755
--- a/files/hooks/mux.sh
+++ b/files/hooks/mux.sh
@@ -8,7 +8,6 @@ set -u
 . "${FUNCTIONS?}" || exit
 #dont_run_as_root
 
-
 for hookfile in \
    ${FILESDIR}/hooks/${ROVERLAY_PHASE}/?*.sh \
    ${FILESDIR}/hooks/?*.${ROVERLAY_PHASE}
@@ -17,9 +16,13 @@ do
       #subshell?
       #( . "${hookfile}"; ) || ...
 
-      # initial directory should always be $S
+      veinfo "Running hook '${hookfile##*/}'"
 
+      # initial directory should always be $S
       cd "${S}" && . "${hookfile}" || \
          die "errors occured while running hook '${hookfile}'"
+
+      # restore signals
+      trap - INT TERM EXIT
    fi
 done

diff --git a/files/shlib/git.sh b/files/shlib/git.sh
index 89c78ce..2d0551f 100644
--- a/files/shlib/git.sh
+++ b/files/shlib/git.sh
@@ -50,13 +50,20 @@ git_has_changes() {
       ${GIT} update-index -q --ignore-submodules --refresh -- "$@"
 
    local has_changes
-   if ${GIT} diff-files ${__GIT_DIFF_OPTS} "$@"; then
+   if ! ${GIT} diff-files ${__GIT_DIFF_OPTS} "$@"; then
       ## return value of zero means no changes
-      veinfo "git index: no changes found"
-      has_changes=1
-   else
       veinfo "git index: changes found"
       has_changes=0
+   elif \
+      [ -n "$( ${GIT} ls-files --exclude-standard -o -- $@ | head -n 1)" ]
+   then
+      # untracked files
+      ## any better way to find them?
+      veinfo "git index: changes found (untracked files)"
+      has_changes=0
+   else
+      veinfo "git index: no changes found"
+      has_changes=1
    fi
 
    if ${GIT} diff-index --cached ${__GIT_DIFF_OPTS} HEAD -- "$@"; then

diff --git a/roverlay/config/entrymap.py b/roverlay/config/entrymap.py
index 5ae7b78..0176964 100644
--- a/roverlay/config/entrymap.py
+++ b/roverlay/config/entrymap.py
@@ -437,12 +437,22 @@ CONFIG_ENTRY_MAP = dict (
 
    # == hooks / scripts ==
 
-   hook_overlay_success = dict (
-      path        = [ 'HOOK', 'OVERLAY', 'success', ],
-      value_type  = 'fs_file',
-      description = "script that is run just before exiting normally",
+   filter_shell_env = dict (
+      path        = [ 'SHELL_ENV', 'filter_env', ],
+      value_type  = yesno,
+      description = 'filter shell env',
+   ),
+
+   hook_script = dict (
+      path = [ 'SHELL_ENV', 'hook', ],
+      value_type = 'fs_file',
+      description = 'script that is run on certain events, e.g. overlay_success',
    ),
 
+   # * alias
+   hook = 'hook_script',
+
+
    # == other ==
 
    cachedir = dict (

diff --git a/roverlay/main.py b/roverlay/main.py
index 207bea6..901cbcf 100644
--- a/roverlay/main.py
+++ b/roverlay/main.py
@@ -81,34 +81,6 @@ def main (
          return call ( *args, **kw )
    # --- end of optionally (...) ---
 
-   def run_hook ( hook_key, phase ):
-      print ( "RUN_HOOK?", hook_key, phase )
-      script = roverlay.config.get ( hook_key, None )
-      if script:
-         print ( "YES.", str ( script ) )
-         return roverlay.tools.shenv.run_script (
-            script, phase.lower(), return_success=True
-         )
-      else:
-         print ( "NO." )
-         # nop
-         return True
-   # --- end of run_hook (...) ---
-
-   def run_hook_lazy ( phase ):
-      crelpath, sepa, ckey = phase.rpartition ( '_' )
-      if sepa:
-         # HOOK.~phase
-         cpath = (
-            'HOOK.' + crelpath.replace ( '_', '.' ).upper()
-            + '.' + ckey.lower()
-         )
-
-         return run_hook ( cpath, phase )
-      else:
-         raise Exception ( "cannot parse phase {!r}".format ( phase ) )
-   # --- end of run_hook_lazy (...) ---
-
    def run_sync():
       if "sync" in actions_done: return
       try:
@@ -317,7 +289,7 @@ def main (
          #  this hook should be called _after_ verifying the overlay
          #  (verification is not implemented yet)
          #
-         if not run_hook_lazy ( 'overlay_success' ):
+         if not roverlay.tools.shenv.run_hook ( 'overlay_success' ):
             die ( "overlay_success hook returned non-zero", DIE.OV_CREATE )
 
          set_action_done ( "create" )

diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py
index 7200851..85644d4 100644
--- a/roverlay/tools/shenv.py
+++ b/roverlay/tools/shenv.py
@@ -18,14 +18,17 @@ 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' )
 
+NULL_PHASE = 'null'
+
 
 # shell env dict quickref
 #  TODO: move this to doc/
 #
-# $PATH, $LOGNAME, $SHLVL, $TERM, [$PWD]
+# $PATH, $LOGNAME, $SHLVL, $TERM, [$PWD], $HOME
 #
 #  taken from os.environ
 #
@@ -33,7 +36,7 @@ LOGGER       = logging.getLogger ( 'shenv' )
 #
 #  hook phase (set in run_script())
 #
-# $OVERLAY == $S (== $HOME)
+# $OVERLAY == $S
 #
 #  overlay directory (depends on config value), initial directory for scripts
 #
@@ -105,6 +108,7 @@ def setup_env():
          'LOGNAME',
          'SHLVL',
          'TERM',
+         'HOME',
          # what else?
       )
       #
@@ -134,7 +138,7 @@ def setup_env():
    # str $ROVERLAY_PHASE
    #  properly defined in shenv_run()
    #
-   setup ( 'ROVERLAY_PHASE', 'null' )
+   setup ( 'ROVERLAY_PHASE', NULL_PHASE )
 
    # str::dirpath $OVERLAY
    setup_conf ( 'OVERLAY', 'OVERLAY.dir' )
@@ -147,7 +151,7 @@ def setup_env():
    #  FIXME: this should/could be the parent dir of $OVERLAY
    #  FIXME: git wants to read $HOME/.gitconfig
    #
-   setup_self ( 'HOME', 'OVERLAY' )
+   ##setup_self ( 'HOME', 'OVERLAY' )
 
    # str::dirpath $DISTROOT
    setup_conf ( 'DISTROOT', 'OVERLAY.DISTDIR.root' )
@@ -173,7 +177,7 @@ def setup_env():
    additions_dir = roverlay.config.get ( 'OVERLAY.additions_dir', None )
    if additions_dir:
       setup ( 'ADDITIONS_DIR', additions_dir )
-      setup_self ( 'FILESDIR', 'ADDITIONSDIR' )
+      setup_self ( 'FILESDIR', 'ADDITIONS_DIR' )
 
       shlib_root      = additions_dir + os.sep + 'shlib'
       shlib_file      = None
@@ -264,46 +268,49 @@ def run_script ( script, phase, return_success=False, logger=None ):
    my_logger = logger or LOGGER
    if phase:
       my_env = get_env ( copy=True )
-      my_env ['ROVERLAY_PHASE'] = str ( phase )
+      my_env ['ROVERLAY_PHASE'] = str ( phase ).lower()
    else:
       # ref
       my_env = get_env()
    # -- end if phase;
 
-   script_call = subprocess.Popen (
-#      ( _SHELL_INTPR, script, my_env ['ROVERLAY_PHASE'], ),
-      ( script, my_env ['ROVERLAY_PHASE'], ),
-      stdin  = None,
-      stdout = subprocess.PIPE,
-      stderr = subprocess.PIPE,
-      cwd    = my_env ['S'],
-      env    = my_env,
-   )
+   try:
+      script_call = subprocess.Popen (
+         # ( _SHELL_INTPR, script, ),
+         ( script, ),
+         stdin      = None,
+         stdout     = subprocess.PIPE,
+         stderr     = subprocess.PIPE,
+         cwd        = my_env ['S'],
+         env        = my_env,
+      )
+
+      output = script_call.communicate()
+   except:
+      script_call.kill()
+      raise
 
-   output = script_call.communicate()
+
+   log_snip_here = (
+      '--- {{}} for script {s!r}, phase {p!r} ---'.format (
+         s=script, p=my_env ['ROVERLAY_PHASE']
+      )
+   )
 
    # log stdout
    if output[0] and my_logger.isEnabledFor ( logging.INFO ):
-      my_logger.info (
-         '--- stdout for script {!r} ---'.format ( script )
-      )
+      my_logger.info ( log_snip_here.format ( "stdout" ) )
       for line in roverlay.strutil.pipe_lines ( output[0], use_filter=True ):
          my_logger.info ( line )
-      my_logger.info (
-         '--- end stdout for script {!r} ---'.format ( script )
-      )
+      my_logger.info ( log_snip_here.format ( "end stdoutt" ) )
    # -- end if stdout;
 
    # log stderr
    if output[1] and my_logger.isEnabledFor ( logging.WARNING ):
-      my_logger.warning (
-         '--- stderr for script {!r} ---'.format ( script )
-      )
+      my_logger.warning ( log_snip_here.format ( "stderr" ) )
       for line in roverlay.strutil.pipe_lines ( output[1], use_filter=True ):
          my_logger.warning ( line )
-      my_logger.warning (
-         '--- end stderr for script {!r} ---'.format ( script )
-      )
+      my_logger.warning ( log_snip_here.format ( "end stderr" ) )
    # --- end if stderr;
 
    if return_success:
@@ -320,3 +327,15 @@ 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 (...) ---


^ permalink raw reply related	[flat|nested] 2+ messages in thread

* [gentoo-commits] proj/R_overlay:master commit in: files/shlib/, roverlay/tools/, roverlay/config/, roverlay/, files/hooks/
@ 2013-06-22 15:24 André Erdmann
  2013-06-21 18:16 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
  0 siblings, 1 reply; 2+ messages in thread
From: André Erdmann @ 2013-06-22 15:24 UTC (permalink / raw
  To: gentoo-commits

commit:     14c25678f12b4b7be68fcd5be2181f8a65d60fa9
Author:     André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Jun 21 18:13:28 2013 +0000
Commit:     André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Jun 21 18:13:28 2013 +0000
URL:        http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=14c25678

roverlay, hooks: fixup, create git commit message

---
 .../{git-snapshot.sh => git-commit-overlay.sh}     | 67 ++++++++++++-------
 files/hooks/mux.sh                                 |  7 +-
 files/shlib/git.sh                                 | 15 +++--
 roverlay/config/entrymap.py                        | 18 ++++--
 roverlay/main.py                                   | 30 +--------
 roverlay/tools/shenv.py                            | 75 ++++++++++++++--------
 6 files changed, 121 insertions(+), 91 deletions(-)

diff --git a/files/hooks/git-snapshot.sh b/files/hooks/git-commit-overlay.sh
similarity index 56%
rename from files/hooks/git-snapshot.sh
rename to files/hooks/git-commit-overlay.sh
index cc3b2df..43060ab 100644
--- a/files/hooks/git-snapshot.sh
+++ b/files/hooks/git-commit-overlay.sh
@@ -7,10 +7,17 @@
 # * check whether the git repo exists, else create it
 # * check whether a clean commit can be made, that is (a) there are changes
 #   to commit and (b) the git index does not contain uncommitted changes
-# * then, add/commit changes
+# * then, add changes, create a commit message and finally commit
 #
 set -u
 
+# TODO:
+#
+# create meaningful commit messages
+# * include package list in the message body
+# -> git status --porcelain
+# -> 78/80 chars per line
+
 ## load core functions
 . "${FUNCTIONS?}" || exit
 #dont_run_as_root
@@ -21,9 +28,11 @@ $lf git
 
 ## "config" for this script
 # FIXME/TODO: remove config here?
-GIT_COMMIT_AUTHOR='undef undef@undef.org'
+GIT_COMMIT_AUTHOR='undef undef undef@undef.org'
 GIT_COMMIT_MESSAGE='roverlay updates'
 
+GIT_COMMIT_MAX_LINE_WIDTH=79
+
 
 ## other vars
 EX_ADD_ERR=2
@@ -40,13 +49,18 @@ git_try_rollback() {
    # release trap
    trap - INT TERM EXIT
    run_command_logged ${GIT} reset --mixed --quiet || true
+   if [ -n "${COMMIT_MSG_FILE-}" ]; then
+      rm -f "${COMMIT_MSG_FILE}"
+   fi
 }
 
-# int git_create_snapshot()
+# int git_commit()
 #
 #  Adds changes and creates a commit.
 #
-git_create_snapshot() {
+git_commit() {
+   local f="${T}/git_commit_message_$$"
+   local COMMIT_MSG_FILE
    trap git_try_rollback INT TERM EXIT
 
    # add changes
@@ -56,14 +70,23 @@ git_create_snapshot() {
       return ${EX_ADD_ERR}
    fi
 
+   # create a commit message (file)
+   {
+      echo "${GIT_COMMIT_MESSAGE}" && \
+      echo && \
+      ${GIT} status \
+         --porcelain --untracked-files=no --ignore-submodules | \
+            sed -n -e 's,^[MADRC].[[:blank:]]\(.*\)\/..*[.]ebuild$,\1,p' | \
+               sort -u | xargs echo | fold -s -w ${GIT_COMMIT_MAX_LINE_WIDTH}
+   } > "${f}" || die
+   COMMIT_MSG_FILE="${f}"
+
    # commit
-   # FIXME:
-   #  --author=?
-   #  --file=? or --message=?
    if run_command_logged \
       ${GIT} commit --quiet --no-edit \
-      --message="${GIT_COMMIT_MESSAGE}" --author="${GIT_COMMIT_AUTHOR}"
+         --file "${COMMIT_MSG_FILE}" --author="${GIT_COMMIT_AUTHOR}"
    then
+      rm "${COMMIT_MSG_FILE-}" && COMMIT_MSG_FILE=
       trap - INT TERM EXIT
       return 0
    else
@@ -76,28 +99,24 @@ git_create_snapshot() {
 ## main
 
 # $GIT_DIR, $S/.git, $HOME/.git, ...?
-if [ -d "${S}/.git" ]; then
-   true
 if [ ! -e "${S}/.git" ]; then
    einfo "Creating git repo"
    # FIXME: --shared OK?
    autodie ${GIT} init --quiet --shared=group "${S}"
-else
-   die "'${S}/.git should be a directory."
-fi
 
+   # assume that there are changes,
+   #  git_has_changes() does not work for new repos
+elif ! git_has_changes; then
+   veinfo "${SCRIPT_NAME}: nothing to do."
+   exit 0
+fi
 
-if git_has_changes; then
 
-   autodie git_create_snapshot
 
-   ##push changes to local repo?
-   ##
-   ##if ! yesno ${NOSYNC}; then
-   ##   #push changes to remote?
-   ##fi
+autodie git_commit
 
-else
-   veinfo "${SCRIPT_NAME}: nothing to do."
-   exit 0
-fi
+##push changes to local repo?
+##
+##if ! yesno ${NOSYNC}; then
+##   #push changes to remote?
+##fi

diff --git a/files/hooks/mux.sh b/files/hooks/mux.sh
index 0764b4d..c114db5 100755
--- a/files/hooks/mux.sh
+++ b/files/hooks/mux.sh
@@ -8,7 +8,6 @@ set -u
 . "${FUNCTIONS?}" || exit
 #dont_run_as_root
 
-
 for hookfile in \
    ${FILESDIR}/hooks/${ROVERLAY_PHASE}/?*.sh \
    ${FILESDIR}/hooks/?*.${ROVERLAY_PHASE}
@@ -17,9 +16,13 @@ do
       #subshell?
       #( . "${hookfile}"; ) || ...
 
-      # initial directory should always be $S
+      veinfo "Running hook '${hookfile##*/}'"
 
+      # initial directory should always be $S
       cd "${S}" && . "${hookfile}" || \
          die "errors occured while running hook '${hookfile}'"
+
+      # restore signals
+      trap - INT TERM EXIT
    fi
 done

diff --git a/files/shlib/git.sh b/files/shlib/git.sh
index 89c78ce..2d0551f 100644
--- a/files/shlib/git.sh
+++ b/files/shlib/git.sh
@@ -50,13 +50,20 @@ git_has_changes() {
       ${GIT} update-index -q --ignore-submodules --refresh -- "$@"
 
    local has_changes
-   if ${GIT} diff-files ${__GIT_DIFF_OPTS} "$@"; then
+   if ! ${GIT} diff-files ${__GIT_DIFF_OPTS} "$@"; then
       ## return value of zero means no changes
-      veinfo "git index: no changes found"
-      has_changes=1
-   else
       veinfo "git index: changes found"
       has_changes=0
+   elif \
+      [ -n "$( ${GIT} ls-files --exclude-standard -o -- $@ | head -n 1)" ]
+   then
+      # untracked files
+      ## any better way to find them?
+      veinfo "git index: changes found (untracked files)"
+      has_changes=0
+   else
+      veinfo "git index: no changes found"
+      has_changes=1
    fi
 
    if ${GIT} diff-index --cached ${__GIT_DIFF_OPTS} HEAD -- "$@"; then

diff --git a/roverlay/config/entrymap.py b/roverlay/config/entrymap.py
index 5ae7b78..0176964 100644
--- a/roverlay/config/entrymap.py
+++ b/roverlay/config/entrymap.py
@@ -437,12 +437,22 @@ CONFIG_ENTRY_MAP = dict (
 
    # == hooks / scripts ==
 
-   hook_overlay_success = dict (
-      path        = [ 'HOOK', 'OVERLAY', 'success', ],
-      value_type  = 'fs_file',
-      description = "script that is run just before exiting normally",
+   filter_shell_env = dict (
+      path        = [ 'SHELL_ENV', 'filter_env', ],
+      value_type  = yesno,
+      description = 'filter shell env',
+   ),
+
+   hook_script = dict (
+      path = [ 'SHELL_ENV', 'hook', ],
+      value_type = 'fs_file',
+      description = 'script that is run on certain events, e.g. overlay_success',
    ),
 
+   # * alias
+   hook = 'hook_script',
+
+
    # == other ==
 
    cachedir = dict (

diff --git a/roverlay/main.py b/roverlay/main.py
index 207bea6..901cbcf 100644
--- a/roverlay/main.py
+++ b/roverlay/main.py
@@ -81,34 +81,6 @@ def main (
          return call ( *args, **kw )
    # --- end of optionally (...) ---
 
-   def run_hook ( hook_key, phase ):
-      print ( "RUN_HOOK?", hook_key, phase )
-      script = roverlay.config.get ( hook_key, None )
-      if script:
-         print ( "YES.", str ( script ) )
-         return roverlay.tools.shenv.run_script (
-            script, phase.lower(), return_success=True
-         )
-      else:
-         print ( "NO." )
-         # nop
-         return True
-   # --- end of run_hook (...) ---
-
-   def run_hook_lazy ( phase ):
-      crelpath, sepa, ckey = phase.rpartition ( '_' )
-      if sepa:
-         # HOOK.~phase
-         cpath = (
-            'HOOK.' + crelpath.replace ( '_', '.' ).upper()
-            + '.' + ckey.lower()
-         )
-
-         return run_hook ( cpath, phase )
-      else:
-         raise Exception ( "cannot parse phase {!r}".format ( phase ) )
-   # --- end of run_hook_lazy (...) ---
-
    def run_sync():
       if "sync" in actions_done: return
       try:
@@ -317,7 +289,7 @@ def main (
          #  this hook should be called _after_ verifying the overlay
          #  (verification is not implemented yet)
          #
-         if not run_hook_lazy ( 'overlay_success' ):
+         if not roverlay.tools.shenv.run_hook ( 'overlay_success' ):
             die ( "overlay_success hook returned non-zero", DIE.OV_CREATE )
 
          set_action_done ( "create" )

diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py
index 7200851..85644d4 100644
--- a/roverlay/tools/shenv.py
+++ b/roverlay/tools/shenv.py
@@ -18,14 +18,17 @@ 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' )
 
+NULL_PHASE = 'null'
+
 
 # shell env dict quickref
 #  TODO: move this to doc/
 #
-# $PATH, $LOGNAME, $SHLVL, $TERM, [$PWD]
+# $PATH, $LOGNAME, $SHLVL, $TERM, [$PWD], $HOME
 #
 #  taken from os.environ
 #
@@ -33,7 +36,7 @@ LOGGER       = logging.getLogger ( 'shenv' )
 #
 #  hook phase (set in run_script())
 #
-# $OVERLAY == $S (== $HOME)
+# $OVERLAY == $S
 #
 #  overlay directory (depends on config value), initial directory for scripts
 #
@@ -105,6 +108,7 @@ def setup_env():
          'LOGNAME',
          'SHLVL',
          'TERM',
+         'HOME',
          # what else?
       )
       #
@@ -134,7 +138,7 @@ def setup_env():
    # str $ROVERLAY_PHASE
    #  properly defined in shenv_run()
    #
-   setup ( 'ROVERLAY_PHASE', 'null' )
+   setup ( 'ROVERLAY_PHASE', NULL_PHASE )
 
    # str::dirpath $OVERLAY
    setup_conf ( 'OVERLAY', 'OVERLAY.dir' )
@@ -147,7 +151,7 @@ def setup_env():
    #  FIXME: this should/could be the parent dir of $OVERLAY
    #  FIXME: git wants to read $HOME/.gitconfig
    #
-   setup_self ( 'HOME', 'OVERLAY' )
+   ##setup_self ( 'HOME', 'OVERLAY' )
 
    # str::dirpath $DISTROOT
    setup_conf ( 'DISTROOT', 'OVERLAY.DISTDIR.root' )
@@ -173,7 +177,7 @@ def setup_env():
    additions_dir = roverlay.config.get ( 'OVERLAY.additions_dir', None )
    if additions_dir:
       setup ( 'ADDITIONS_DIR', additions_dir )
-      setup_self ( 'FILESDIR', 'ADDITIONSDIR' )
+      setup_self ( 'FILESDIR', 'ADDITIONS_DIR' )
 
       shlib_root      = additions_dir + os.sep + 'shlib'
       shlib_file      = None
@@ -264,46 +268,49 @@ def run_script ( script, phase, return_success=False, logger=None ):
    my_logger = logger or LOGGER
    if phase:
       my_env = get_env ( copy=True )
-      my_env ['ROVERLAY_PHASE'] = str ( phase )
+      my_env ['ROVERLAY_PHASE'] = str ( phase ).lower()
    else:
       # ref
       my_env = get_env()
    # -- end if phase;
 
-   script_call = subprocess.Popen (
-#      ( _SHELL_INTPR, script, my_env ['ROVERLAY_PHASE'], ),
-      ( script, my_env ['ROVERLAY_PHASE'], ),
-      stdin  = None,
-      stdout = subprocess.PIPE,
-      stderr = subprocess.PIPE,
-      cwd    = my_env ['S'],
-      env    = my_env,
-   )
+   try:
+      script_call = subprocess.Popen (
+         # ( _SHELL_INTPR, script, ),
+         ( script, ),
+         stdin      = None,
+         stdout     = subprocess.PIPE,
+         stderr     = subprocess.PIPE,
+         cwd        = my_env ['S'],
+         env        = my_env,
+      )
+
+      output = script_call.communicate()
+   except:
+      script_call.kill()
+      raise
 
-   output = script_call.communicate()
+
+   log_snip_here = (
+      '--- {{}} for script {s!r}, phase {p!r} ---'.format (
+         s=script, p=my_env ['ROVERLAY_PHASE']
+      )
+   )
 
    # log stdout
    if output[0] and my_logger.isEnabledFor ( logging.INFO ):
-      my_logger.info (
-         '--- stdout for script {!r} ---'.format ( script )
-      )
+      my_logger.info ( log_snip_here.format ( "stdout" ) )
       for line in roverlay.strutil.pipe_lines ( output[0], use_filter=True ):
          my_logger.info ( line )
-      my_logger.info (
-         '--- end stdout for script {!r} ---'.format ( script )
-      )
+      my_logger.info ( log_snip_here.format ( "end stdoutt" ) )
    # -- end if stdout;
 
    # log stderr
    if output[1] and my_logger.isEnabledFor ( logging.WARNING ):
-      my_logger.warning (
-         '--- stderr for script {!r} ---'.format ( script )
-      )
+      my_logger.warning ( log_snip_here.format ( "stderr" ) )
       for line in roverlay.strutil.pipe_lines ( output[1], use_filter=True ):
          my_logger.warning ( line )
-      my_logger.warning (
-         '--- end stderr for script {!r} ---'.format ( script )
-      )
+      my_logger.warning ( log_snip_here.format ( "end stderr" ) )
    # --- end if stderr;
 
    if return_success:
@@ -320,3 +327,15 @@ 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 (...) ---


^ permalink raw reply related	[flat|nested] 2+ messages in thread

end of thread, other threads:[~2013-06-22 15:24 UTC | newest]

Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-06-22 15:24 [gentoo-commits] proj/R_overlay:master commit in: files/shlib/, roverlay/tools/, roverlay/config/, roverlay/, files/hooks/ André Erdmann
2013-06-21 18:16 ` [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox