* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
@ 2013-06-22 15:24 André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2013-06-22 15:24 UTC (permalink / raw
To: gentoo-commits
commit: deafef91dfcc33fd8b491ce4fa6c0709f4afa7a1
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Jun 20 23:36:40 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Jun 20 23:36:40 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=deafef91
roverlay/tools/shenv: run shell scripts
This commit adds support for running shell script files ("hooks") in an
environment that contains roverlay variables like $OVERLAY and $DISTROOT.
---
roverlay/tools/shenv.py | 322 ++++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 322 insertions(+)
diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py
new file mode 100644
index 0000000..7200851
--- /dev/null
+++ b/roverlay/tools/shenv.py
@@ -0,0 +1,322 @@
+# R overlay -- tools, run roverlay hooks (shell scripts)
+# -*- coding: utf-8 -*-
+# Copyright (C) 2013 André Erdmann <dywi@mailerd.de>
+# Distributed under the terms of the GNU General Public License;
+# either version 2 of the License, or (at your option) any later version.
+
+import logging
+import os
+import subprocess
+import tempfile
+
+
+import roverlay.config
+import roverlay.strutil
+import roverlay.util
+
+
+# _SHELL_ENV, _SHELL_INTPR are created when calling run_script()
+#
+_SHELL_ENV = None
+#_SHELL_INTPR = None
+LOGGER = logging.getLogger ( 'shenv' )
+
+
+# shell env dict quickref
+# TODO: move this to doc/
+#
+# $PATH, $LOGNAME, $SHLVL, $TERM, [$PWD]
+#
+# taken from os.environ
+#
+# $ROVERLAY_PHASE
+#
+# hook phase (set in run_script())
+#
+# $OVERLAY == $S (== $HOME)
+#
+# overlay directory (depends on config value), initial directory for scripts
+#
+#
+# $DISTROOT
+#
+# mirror directory (depends on config value)
+#
+# $TMPDIR == $T
+#
+# depends on config value (+fallback)
+#
+# $ADDITIONS_DIR == $FILESDIR (optional)
+#
+# depends on config value
+#
+# $SHLIB (optional)
+#
+# shell functions dir (if found, ${ADDITIONS_DIR}/shlib)
+#
+# $FUNCTIONS (optional)
+#
+# core functions file (if found, ${ADDITIONS_DIR}/{shlib,}/functions.sh)
+#
+# $EBUILD
+#
+# ebuild executable, depends on config value
+#
+# $GIT_EDITOR
+# $GIT_ASKPASS
+#
+# set to /bin/false
+#
+# $NOSYNC
+#
+# depends on config value
+#
+# $NO_COLOR
+#
+# alway false ('n')
+#
+# $DEBUG
+# $VERBOSE
+# $QUIET
+#
+# shbools that indicate whether debug/verbose/quiet ouput is desired,
+# depends on log level
+#
+
+
+def setup_env():
+ """Returns a 'well-defined' env dict for running scripts."""
+
+ # @typedef shbool is SH_TRUE|SH_FALSE, where:
+ SH_TRUE = 'y'
+ SH_FALSE = 'n'
+
+ def shbool ( value ):
+ """Converts value into a shbool."""
+ return SH_TRUE if value else SH_FALSE
+ # --- end of shbool (...) ---
+
+ # import os.environ
+ if roverlay.config.get ( "SHELL_ENV.filter_env", True ):
+ # (keepenv does not support wildcars)
+ env = roverlay.util.keepenv (
+ ( 'PATH', '/usr/local/bin:/usr/bin:/bin' ),
+ 'PWD',
+ 'LOGNAME',
+ 'SHLVL',
+ 'TERM',
+ # what else?
+ )
+ #
+ # LANG, LC_ALL, LC_COLLATE, ...
+ #
+ # GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL,
+ # GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL, ...
+ #
+ # GIT_EDITOR and GIT_ASKPASS are set to /bin/false here
+ #
+
+ else:
+ env = dict ( os.environ )
+
+ # setup* functions
+ def setup ( k, v ):
+ env [k] = v
+
+ def setup_conf ( k, c ):
+ env [k] = roverlay.config.get_or_fail ( c )
+
+ def setup_self ( k, c ):
+ env[k] = env[c]
+
+ ## create shell vars
+
+ # str $ROVERLAY_PHASE
+ # properly defined in shenv_run()
+ #
+ setup ( 'ROVERLAY_PHASE', 'null' )
+
+ # str::dirpath $OVERLAY
+ setup_conf ( 'OVERLAY', 'OVERLAY.dir' )
+
+ # str::dirpath $S renames $OVERLAY
+ setup_self ( 'S', 'OVERLAY' )
+
+ # str::dirpath $HOME renames $OVERLAY
+ #
+ # FIXME: this should/could be the parent dir of $OVERLAY
+ # FIXME: git wants to read $HOME/.gitconfig
+ #
+ setup_self ( 'HOME', 'OVERLAY' )
+
+ # str::dirpath $DISTROOT
+ setup_conf ( 'DISTROOT', 'OVERLAY.DISTDIR.root' )
+
+ # str::dirpath $TMPDIR := <default>
+ setup (
+ 'TMPDIR',
+ roverlay.config.get ( 'OVERLAY.TMPDIR.root' ) or tempfile.gettempdir()
+ )
+
+ # str::dirpath $T renames $TMPDIR
+ setup_self ( 'T', 'TMPDIR' )
+
+ # @optional str::dirpath $ADDITIONS_DIR
+ # @optional str::dirpath $FILESDIR renames $ADDITIONS_DIR
+ #
+ # @optional str::dirpath $SHLIB is ${ADDITIONS_DIR}/shlib
+ # directory with shell function files
+ #
+ # @optional str::filepath $FUNCTIONS is <see below>
+ # shell file with "core" functions
+ #
+ additions_dir = roverlay.config.get ( 'OVERLAY.additions_dir', None )
+ if additions_dir:
+ setup ( 'ADDITIONS_DIR', additions_dir )
+ setup_self ( 'FILESDIR', 'ADDITIONSDIR' )
+
+ shlib_root = additions_dir + os.sep + 'shlib'
+ shlib_file = None
+ SHFUNC_FILENAME = 'functions.sh'
+
+ if os.path.isdir ( shlib_root ):
+ setup ( 'SHLIB', shlib_root )
+ shlib_file = shlib_root + os.sep + SHFUNC_FILENAME
+
+ if os.path.isfile ( shlib_file ):
+ setup ( 'FUNCTIONS', shlib_file )
+ else:
+ shlib_file = None
+ # -- end if shlib_root;
+
+ if not shlib_file:
+ shlib_file = additions_dir + os.sep + SHFUNC_FILENAME
+ if os.path.isfile ( shlib_file ):
+ setup ( 'FUNCTIONS', shlib_file )
+ # -- end if additions_dir;
+
+ # str::exe $EBUILD
+ setup_conf ( 'EBUILD', 'TOOLS.EBUILD.exe' )
+
+ # str::exe $GIT_EDITOR = <disable>
+ #
+ # It's not that funny if the program waits for user interaction.
+ #
+ setup ( 'GIT_EDITOR', roverlay.util.sysnop ( False )[0] )
+
+ # str::exe $GIT_ASKPASS copies $GIT_EDITOR
+ setup_self ( 'GIT_ASKPASS', 'GIT_EDITOR' )
+
+ # shbool $NOSYNC
+ setup ( 'NOSYNC', shbool ( roverlay.config.get_or_fail ( 'nosync' ) ) )
+
+ # shbool $NO_COLOR
+ #
+ # stdout/stderr are logged, so colored output should be avoided
+ #
+ setup ( 'NO_COLOR', SH_TRUE )
+
+ # shbool $DEBUG, $VERBOSE, $QUIET
+ if LOGGER.isEnabledFor ( logging.DEBUG ):
+ setup ( 'DEBUG', SH_TRUE )
+ setup ( 'QUIET', SH_FALSE )
+ setup ( 'VERBOSE', SH_TRUE )
+ elif LOGGER.isEnabledFor ( logging.INFO ):
+ setup ( 'DEBUG', SH_FALSE )
+ setup ( 'QUIET', SH_FALSE )
+ setup ( 'VERBOSE', SH_TRUE )
+ elif LOGGER.isEnabledFor ( logging.WARNING ):
+ setup ( 'DEBUG', SH_FALSE )
+ setup ( 'VERBOSE', SH_FALSE )
+ setup ( 'QUIET', SH_FALSE )
+ else:
+ setup ( 'DEBUG', SH_FALSE )
+ setup ( 'VERBOSE', SH_FALSE )
+ setup ( 'QUIET', SH_TRUE )
+ # -- end if
+
+ # done
+ return env
+# --- end of setup_env (...) ---
+
+def get_env ( copy=False ):
+ global _SHELL_ENV
+ if _SHELL_ENV is None:
+ _SHELL_ENV = setup_env()
+
+ if copy:
+ return dict ( _SHELL_ENV )
+ else:
+ return _SHELL_ENV
+# --- end of get_env (...) ---
+
+def update_env ( **info ):
+ get_env().update ( info )
+ return _SHELL_ENV
+# --- end of update_env (...) ---
+
+
+def run_script ( script, phase, return_success=False, logger=None ):
+# global _SHELL_INTPR
+# if _SHELL_INTPR is None:
+# _SHELL_INTPR = roverlay.config.get ( 'SHELL_ENV.shell', '/bin/sh' )
+
+ my_logger = logger or LOGGER
+ if phase:
+ my_env = get_env ( copy=True )
+ my_env ['ROVERLAY_PHASE'] = str ( phase )
+ 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,
+ )
+
+ output = script_call.communicate()
+
+ # log stdout
+ if output[0] and my_logger.isEnabledFor ( logging.INFO ):
+ my_logger.info (
+ '--- stdout for script {!r} ---'.format ( script )
+ )
+ 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 )
+ )
+ # -- end if stdout;
+
+ # log stderr
+ if output[1] and my_logger.isEnabledFor ( logging.WARNING ):
+ my_logger.warning (
+ '--- stderr for script {!r} ---'.format ( script )
+ )
+ 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 )
+ )
+ # --- end if stderr;
+
+ if return_success:
+ if script_call.returncode == os.EX_OK:
+ my_logger.debug ( "script {!r}: success".format ( script ) )
+ return True
+ else:
+ my_logger.warning (
+ "script {!r} returned {}".format (
+ script, script_call.returncode
+ )
+ )
+ return False
+ else:
+ return script_call
+# --- end of run_script (...) ---
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
2013-07-10 15:10 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
@ 2013-07-10 16:16 ` André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2013-07-10 16:16 UTC (permalink / raw
To: gentoo-commits
commit: e27a07c62d33a317562f6623600b4ad4b4a4496e
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Jul 10 13:34:51 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Jul 10 13:34:51 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=e27a07c6
roverlay/tools/ebuild: doebuild_fetch_and_manifest
A combined fetch/manifest command which can be used when importing ebuilds.
---
roverlay/tools/ebuild.py | 23 +++++++++++++++++++++--
1 file changed, 21 insertions(+), 2 deletions(-)
diff --git a/roverlay/tools/ebuild.py b/roverlay/tools/ebuild.py
index e8f7e37..0ca0b8a 100644
--- a/roverlay/tools/ebuild.py
+++ b/roverlay/tools/ebuild.py
@@ -20,9 +20,15 @@ _EBUILD_CMDV = (
def doebuild (
ebuild_file, command, logger, env=None, opts=(), return_success=True
):
- logger.debug ( "doebuild: {c}, {e!r}".format ( e=ebuild_file, c=command ) )
+ if isinstance ( command, str ):
+ cmdv = ( _EBUILD_CMDV + opts + ( ebuild_file, command ) )
+ else:
+ cmdv = ( _EBUILD_CMDV + opts + ( ebuild_file, ) + command )
+
+ logger.debug ( "doebuild: {cmdv}".format ( cmdv=cmdv ) )
+
return roverlay.tools.runcmd.run_command (
- cmdv = ( _EBUILD_CMDV + opts + ( ebuild_file, command ) ),
+ cmdv = cmdv,
env = env,
logger = logger,
return_success = return_success
@@ -54,3 +60,16 @@ def doebuild_fetch (
return_success = return_success,
)
# --- end of doebuild_fetch (...) ---
+
+def doebuild_fetch_and_manifest (
+ ebuild_file, logger, env=None, opts=(), return_success=True
+):
+ return doebuild (
+ ebuild_file = ebuild_file,
+ command = ( "fetch", "manifest" ),
+ logger = logger,
+ env = env,
+ opts = opts,
+ return_success = return_success,
+ )
+# --- end of doebuild_fetch_and_manifest (...) ---
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
2013-07-11 16:44 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
@ 2013-07-11 16:29 ` André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2013-07-11 16:29 UTC (permalink / raw
To: gentoo-commits
commit: 6e32c4e171d304149425ab081c0105995160ba17
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Jul 11 16:25:37 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Jul 11 16:25:37 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=6e32c4e1
fix minor typo in roverlay/tools/shenv
---
roverlay/tools/shenv.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py
index f732040..5ae0f25 100644
--- a/roverlay/tools/shenv.py
+++ b/roverlay/tools/shenv.py
@@ -335,7 +335,7 @@ def run_script ( script, phase, return_success=False, logger=None ):
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 ( log_snip_here.format ( "end stdoutt" ) )
+ my_logger.info ( log_snip_here.format ( "end stdout" ) )
# -- end if stdout;
# log stderr
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
@ 2013-07-29 14:56 André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2013-07-29 14:56 UTC (permalink / raw
To: gentoo-commits
commit: bc4fe040fcf71f9f0f74d0f449f85811d23dbeaa
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Mon Jul 29 14:52:34 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Mon Jul 29 14:52:34 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=bc4fe040
shell env: export STATS_DB if set
---
roverlay/tools/shenv.py | 16 ++++++++++++++++
1 file changed, 16 insertions(+)
diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py
index 6fcaab3..e9b1bad 100644
--- a/roverlay/tools/shenv.py
+++ b/roverlay/tools/shenv.py
@@ -146,6 +146,18 @@ def setup_env():
def setup_conf ( k, c ):
env [k] = roverlay.config.get_or_fail ( c )
+ def setup_conf_optional ( k, c, fallback=None ):
+ value = roverlay.config.get ( k )
+ if value is not None:
+ env [k] = value
+ return True
+ elif fallback is not None:
+ env [k] = str ( fallback )
+ return False
+ else:
+ return None
+ # --- end of setup_conf_optional (...) ---
+
def setup_self ( k, c ):
env[k] = env[c]
@@ -184,8 +196,12 @@ def setup_env():
# str::dirpath $DISTROOT
setup_conf ( 'DISTROOT', 'OVERLAY.DISTDIR.root' )
+ # str::dirpath $WORKDIR
setup_conf ( 'WORKDIR', 'CACHEDIR.root' )
+ # str::filepath $STATS_DB (optional)
+ setup_conf_optional ( 'STATS_DB', 'RRD_DB.file' )
+
# str::dirpath $TMPDIR := <default>
setup (
'TMPDIR',
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
@ 2013-08-02 10:34 André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2013-08-02 10:34 UTC (permalink / raw
To: gentoo-commits
commit: e7d0acb0f3de8345a6f84354f7c1a8fa58d245bc
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Fri Aug 2 10:21:01 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Fri Aug 2 10:21:01 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=e7d0acb0
roverlay/tools/shenv: export HAS_CHANGES
---
roverlay/tools/shenv.py | 56 +++++++++++++++++++++++++------------------------
1 file changed, 29 insertions(+), 27 deletions(-)
diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py
index e9b1bad..9ee3af6 100644
--- a/roverlay/tools/shenv.py
+++ b/roverlay/tools/shenv.py
@@ -15,6 +15,7 @@ import time
import roverlay.config
import roverlay.strutil
import roverlay.util
+import roverlay.stats.collector
# _SHELL_ENV, _SHELL_INTPR are created when calling run_script()
@@ -94,6 +95,14 @@ NULL_PHASE = 'null'
# depends on log level
#
+# @typedef shbool is SH_TRUE|SH_FALSE, where:
+SH_TRUE = 'y'
+SH_FALSE = 'n'
+
+def shbool ( value ):
+ """Converts value into a shbool."""
+ return SH_TRUE if value else SH_FALSE
+# --- end of shbool (...) ---
def setup_env():
"""Returns a 'well-defined' env dict for running scripts."""
@@ -102,15 +111,6 @@ def setup_env():
SHLIB_DIRNAME = 'shlib'
SHFUNC_FILENAME = 'functions.sh'
- # @typedef shbool is SH_TRUE|SH_FALSE, where:
- SH_TRUE = 'y'
- SH_FALSE = 'n'
-
- def shbool ( value ):
- """Converts value into a shbool."""
- return SH_TRUE if value else SH_FALSE
- # --- end of shbool (...) ---
-
# import os.environ
if roverlay.config.get ( "SHELL_ENV.filter_env", True ):
# (keepenv does not support wildcars)
@@ -307,7 +307,7 @@ def setup_env():
return env
# --- end of setup_env (...) ---
-def get_env ( copy=False ):
+def make_env ( copy=False ):
global _SHELL_ENV
if _SHELL_ENV is None:
_SHELL_ENV = setup_env()
@@ -316,23 +316,31 @@ def get_env ( copy=False ):
return dict ( _SHELL_ENV )
else:
return _SHELL_ENV
-# --- end of get_env (...) ---
+# --- end of make_env (...) ---
def update_env ( **info ):
- get_env().update ( info )
- return _SHELL_ENV
+ env = make_env()
+ env.update ( info )
+ return env
# --- end of update_env (...) ---
+def get_env ( phase, copy=True ):
+ env = make_env ( copy=copy )
+ if phase:
+ env ['ROVERLAY_PHASE'] = str ( phase ).lower()
+
+ env ['HAS_CHANGES'] = shbool (
+ roverlay.stats.collector.static.overlay_has_any_changes()
+ )
+
+ return env
+# --- end of get_env (...) ---
+
+
def run_script_exec (
script, phase, argv=(), initial_dir=None, use_path=True
):
- if phase:
- my_env = get_env ( copy=True )
- my_env ['ROVERLAY_PHASE'] = str ( phase ).lower()
- else:
- # ref
- my_env = get_env()
- # -- end if phase;
+ my_env = get_env ( phase )
if initial_dir:
os.chdir ( initial_dir )
@@ -354,13 +362,7 @@ def run_script (
# _SHELL_INTPR = roverlay.config.get ( 'SHELL_ENV.shell', '/bin/sh' )
my_logger = logger or LOGGER
- if phase:
- my_env = get_env ( copy=True )
- my_env ['ROVERLAY_PHASE'] = str ( phase ).lower()
- else:
- # ref
- my_env = get_env()
- # -- end if phase;
+ my_env = get_env ( phase )
try:
script_call = subprocess.Popen (
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
@ 2013-08-05 11:44 André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2013-08-05 11:44 UTC (permalink / raw
To: gentoo-commits
commit: 0d8483979f9ee5056a10a3fe016f7b29529440db
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Mon Aug 5 09:08:43 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Mon Aug 5 09:08:43 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=0d848397
roverlay/tools/shenv, run_script_exec(): set env
use DEBUG, VERBOSE, QUIET, NO_COLOR from os.environ
---
roverlay/tools/shenv.py | 36 +++++++++++++++++++++++++++++++++++-
1 file changed, 35 insertions(+), 1 deletion(-)
diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py
index 9ee3af6..326a421 100644
--- a/roverlay/tools/shenv.py
+++ b/roverlay/tools/shenv.py
@@ -104,6 +104,23 @@ def shbool ( value ):
return SH_TRUE if value else SH_FALSE
# --- end of shbool (...) ---
+def get_shbool ( value, empty_is_false=True, undef_is_false=True ):
+ """Converts a string into a shbool."""
+ if not value:
+ return SH_FALSE if empty_is_false else SH_TRUE
+ elif value in { SH_TRUE, SH_FALSE }:
+ return value
+ elif value.lower() in { 'yes', 'on', '1', 'enabled', 'true' }:
+ return SH_TRUE
+ elif undef_is_false:
+ return SH_FALSE
+ elif value.lower() in { 'no', 'off', '0', 'disabled', 'false' }:
+ return SH_FALSE
+ else:
+ return SH_TRUE
+# --- end of get_shbool (...) ---
+
+
def setup_env():
"""Returns a 'well-defined' env dict for running scripts."""
@@ -338,10 +355,27 @@ def get_env ( phase, copy=True ):
def run_script_exec (
- script, phase, argv=(), initial_dir=None, use_path=True
+ script, phase, argv=(), initial_dir=None, use_path=True, extra_env=None,
):
my_env = get_env ( phase )
+ shbool_from_env = (
+ lambda k, x, **kw: get_shbool ( os.environ.get ( k, x ), **kw )
+ )
+
+ # restore DEBUG/VERBOSE/QUIET
+ my_env ['DEBUG'] = shbool_from_env ( 'DEBUG', SH_FALSE )
+ my_env ['VERBOSE'] = shbool_from_env ( 'VERBOSE', SH_TRUE )
+ my_env ['QUIET'] = shbool_from_env ( 'QUIET', SH_FALSE )
+
+ # reset NO_COLOR
+ my_env ['NO_COLOR'] = shbool_from_env (
+ 'NO_COLOR', SH_TRUE, empty_is_false=False
+ )
+
+ if extra_env:
+ my_env.update ( extra_env )
+
if initial_dir:
os.chdir ( initial_dir )
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
@ 2013-08-13 8:56 André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2013-08-13 8:56 UTC (permalink / raw
To: gentoo-commits
commit: 3a58d432faa2cf5a9762dc73b14530fc3cad93fc
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Aug 13 08:36:01 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Aug 13 08:36:01 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=3a58d432
roverlay/tools/runcmd: run command, get output
---
roverlay/tools/runcmd.py | 39 ++++++++++++++++++++++++++-------------
1 file changed, 26 insertions(+), 13 deletions(-)
diff --git a/roverlay/tools/runcmd.py b/roverlay/tools/runcmd.py
index cda41d0..ea76d57 100644
--- a/roverlay/tools/runcmd.py
+++ b/roverlay/tools/runcmd.py
@@ -12,22 +12,35 @@ import roverlay.strutil
DEBUG_TO_CONSOLE = False
-def run_command ( cmdv, env, logger, return_success=False ):
- if DEBUG_TO_CONSOLE:
- cmd_call = subprocess.Popen ( cmdv, stdin=None, env=env )
- else:
- cmd_call = subprocess.Popen (
- cmdv,
- stdin=None,
- stdout=subprocess.PIPE,
- stderr=subprocess.PIPE,
- env=env,
- )
+def run_command_get_output (
+ cmdv, env, debug_to_console=False, use_filter=True, filter_func=None
+):
+
+ # note that debug_to_console breaks calls that want to parse stdout
+ pipe_target = None if debug_to_console else subprocess.PIPE
+
+ cmd_call = subprocess.Popen (
+ cmdv, stdin=None, stdout=pipe_target, stderr=pipe_target, env=env
+ )
+ raw_output = cmd_call.communicate()
- output = cmd_call.communicate()
+ output = [
+ (
+ list ( roverlay.strutil.pipe_lines (
+ stream, use_filter=True, filter_func=None
+ ) )
+ if stream is not None else None
+ ) for stream in raw_output
+ ]
+
+ return ( cmd_call, output )
+# --- end of run_command_get_output (...) ---
+
+def run_command ( cmdv, env, logger, return_success=False ):
+ cmd_call, output = run_command_get_output ( cmdv, env, DEBUG_TO_CONSOLE )
# log stderr
- if output [1] and logger.isEnabledFor ( logging.WARNING ):
+ if output[1] and logger.isEnabledFor ( logging.WARNING ):
for line in roverlay.strutil.pipe_lines ( output [1], use_filter=True ):
logger.warning ( line )
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
@ 2013-08-13 8:56 André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2013-08-13 8:56 UTC (permalink / raw
To: gentoo-commits
commit: 8b28ff444c3126058d746c1329e6854c78d32b1a
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Aug 13 08:36:25 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Aug 13 08:36:25 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=8b28ff44
roverlay/tools/shenv: restore_msg_vars()
break-out of run_script_exec()
---
roverlay/tools/shenv.py | 23 +++++++++++++----------
1 file changed, 13 insertions(+), 10 deletions(-)
diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py
index 326a421..1c481b6 100644
--- a/roverlay/tools/shenv.py
+++ b/roverlay/tools/shenv.py
@@ -353,25 +353,28 @@ def get_env ( phase, copy=True ):
return env
# --- end of get_env (...) ---
-
-def run_script_exec (
- script, phase, argv=(), initial_dir=None, use_path=True, extra_env=None,
-):
- my_env = get_env ( phase )
-
+def restore_msg_vars ( env ):
shbool_from_env = (
lambda k, x, **kw: get_shbool ( os.environ.get ( k, x ), **kw )
)
# restore DEBUG/VERBOSE/QUIET
- my_env ['DEBUG'] = shbool_from_env ( 'DEBUG', SH_FALSE )
- my_env ['VERBOSE'] = shbool_from_env ( 'VERBOSE', SH_TRUE )
- my_env ['QUIET'] = shbool_from_env ( 'QUIET', SH_FALSE )
+ env ['DEBUG'] = shbool_from_env ( 'DEBUG', SH_FALSE )
+ env ['VERBOSE'] = shbool_from_env ( 'VERBOSE', SH_TRUE )
+ env ['QUIET'] = shbool_from_env ( 'QUIET', SH_FALSE )
# reset NO_COLOR
- my_env ['NO_COLOR'] = shbool_from_env (
+ env ['NO_COLOR'] = shbool_from_env (
'NO_COLOR', SH_TRUE, empty_is_false=False
)
+ return None
+# --- end of restore_msg_vars (...) ---
+
+def run_script_exec (
+ script, phase, argv=(), initial_dir=None, use_path=True, extra_env=None,
+):
+ my_env = get_env ( phase )
+ restore_msg_vars ( my_env )
if extra_env:
my_env.update ( extra_env )
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
@ 2013-08-14 14:56 André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2013-08-14 14:56 UTC (permalink / raw
To: gentoo-commits
commit: ee04947562f151429497305a3fce9c3bbb88b125
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Aug 14 14:40:17 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Aug 14 14:40:17 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=ee049475
roverlay/tools/runcmd: get binary stdout
---
roverlay/tools/runcmd.py | 24 +++++++++++++++++-------
1 file changed, 17 insertions(+), 7 deletions(-)
diff --git a/roverlay/tools/runcmd.py b/roverlay/tools/runcmd.py
index ea76d57..5f3a672 100644
--- a/roverlay/tools/runcmd.py
+++ b/roverlay/tools/runcmd.py
@@ -13,7 +13,8 @@ import roverlay.strutil
DEBUG_TO_CONSOLE = False
def run_command_get_output (
- cmdv, env, debug_to_console=False, use_filter=True, filter_func=None
+ cmdv, env, debug_to_console=False, use_filter=True, filter_func=None,
+ binary_stdout=False,
):
# note that debug_to_console breaks calls that want to parse stdout
@@ -24,14 +25,23 @@ def run_command_get_output (
)
raw_output = cmd_call.communicate()
- output = [
- (
+ if binary_stdout:
+ assert len ( raw_output ) == 2
+ output = [
+ raw_output[0],
list ( roverlay.strutil.pipe_lines (
- stream, use_filter=True, filter_func=None
+ raw_output[1], use_filter=use_filter, filter_func=filter_func
) )
- if stream is not None else None
- ) for stream in raw_output
- ]
+ ]
+ else:
+ output = [
+ (
+ list ( roverlay.strutil.pipe_lines (
+ stream, use_filter=use_filter, filter_func=filter_func
+ ) )
+ if stream is not None else None
+ ) for stream in raw_output
+ ]
return ( cmd_call, output )
# --- end of run_command_get_output (...) ---
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
@ 2013-08-21 13:51 André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2013-08-21 13:51 UTC (permalink / raw
To: gentoo-commits
commit: ef790e3c59c8dcd17b17fc684c6568e4fa435d86
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Aug 21 11:03:11 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Aug 21 11:03:11 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=ef790e3c
roverlay/tools/runcmd: don't decode pipe output twice
---
roverlay/tools/runcmd.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/roverlay/tools/runcmd.py b/roverlay/tools/runcmd.py
index 5f3a672..8c38cbd 100644
--- a/roverlay/tools/runcmd.py
+++ b/roverlay/tools/runcmd.py
@@ -47,11 +47,13 @@ def run_command_get_output (
# --- end of run_command_get_output (...) ---
def run_command ( cmdv, env, logger, return_success=False ):
- cmd_call, output = run_command_get_output ( cmdv, env, DEBUG_TO_CONSOLE )
+ cmd_call, output = run_command_get_output (
+ cmdv, env, DEBUG_TO_CONSOLE, use_filter=True
+ )
# log stderr
if output[1] and logger.isEnabledFor ( logging.WARNING ):
- for line in roverlay.strutil.pipe_lines ( output [1], use_filter=True ):
+ for line in output[1]:
logger.warning ( line )
if return_success:
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
@ 2013-09-04 10:16 André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2013-09-04 10:16 UTC (permalink / raw
To: gentoo-commits
commit: 276c823634d7b61a5580dfaae4b7765bf7b89270
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Sep 4 10:14:33 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Sep 4 10:14:33 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=276c8236
roverlay/shenv: fix setup_conf_optional()
+ add $ROVERLAY_HOOKRC to the shell env
---
roverlay/tools/shenv.py | 6 ++++--
1 file changed, 4 insertions(+), 2 deletions(-)
diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py
index 1c481b6..1b06ca9 100644
--- a/roverlay/tools/shenv.py
+++ b/roverlay/tools/shenv.py
@@ -164,7 +164,7 @@ def setup_env():
env [k] = roverlay.config.get_or_fail ( c )
def setup_conf_optional ( k, c, fallback=None ):
- value = roverlay.config.get ( k )
+ value = roverlay.config.get ( c )
if value is not None:
env [k] = value
return True
@@ -180,8 +180,10 @@ def setup_env():
## create shell vars
- # str::filepath $ROVERLAY_EXE
+ # str::filepath $ROVERLAY_HOOKRC (optional)
+ setup_conf_optional ( 'ROVERLAY_HOOKRC', 'EVENT_HOOK.config_file' )
+ # str::filepath $ROVERLAY_EXE
setup ( 'ROVERLAY_HELPER_EXE', sys.argv[0] )
roverlay_exe = ( os.path.dirname ( sys.argv[0] ) + os.sep + 'roverlay' )
if os.path.isfile ( roverlay_exe + '.py' ):
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
@ 2013-11-14 18:24 André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2013-11-14 18:24 UTC (permalink / raw
To: gentoo-commits
commit: 51e381ee1de2db29adcfa9091e85126385d622cd
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Nov 14 17:34:00 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Nov 14 17:34:00 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=51e381ee
roverlay/tools/shenv.py: accept LC_ variables
Transfer/copy all environment variables starting with LC_ from os.environ to the
hook environment.
---
roverlay/tools/shenv.py | 43 ++++++++++++++++++++++++++-----------------
1 file changed, 26 insertions(+), 17 deletions(-)
diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py
index 5587e6d..a669907 100644
--- a/roverlay/tools/shenv.py
+++ b/roverlay/tools/shenv.py
@@ -4,6 +4,7 @@
# Distributed under the terms of the GNU General Public License;
# either version 2 of the License, or (at your option) any later version.
+import fnmatch
import logging
import os
import sys
@@ -26,6 +27,18 @@ LOGGER = logging.getLogger ( 'shenv' )
NULL_PHASE = 'null'
+SHENV_VARS_TO_KEEP = frozenset ({
+ ( 'PATH', '/usr/local/bin:/usr/bin:/bin' ),
+ 'PWD',
+ 'LOGNAME',
+ 'SHLVL',
+ 'TERM',
+ 'HOME',
+ 'LANG',
+})
+
+SHENV_WILDCARD_VARS_TO_KEEP = frozenset ({ 'LC_?*', })
+
# shell env dict quickref
# TODO: move this to doc/
@@ -126,6 +139,7 @@ def get_shbool ( value, empty_is_false=True, undef_is_false=True ):
def setup_env():
"""Returns a 'well-defined' env dict for running scripts."""
+ _fnmatch = fnmatch.fnmatch
ROVERLAY_INSTALLED = roverlay.config.get_or_fail ( 'installed' )
SHLIB_DIRNAME = 'shlib'
SHFUNC_FILENAME = 'functions.sh'
@@ -133,24 +147,19 @@ def setup_env():
# import os.environ
if roverlay.config.get ( "SHELL_ENV.filter_env", True ):
# (keepenv does not support wildcars)
- env = roverlay.util.keepenv (
- ( 'PATH', '/usr/local/bin:/usr/bin:/bin' ),
- 'PWD',
- 'LOGNAME',
- 'SHLVL',
- 'TERM',
- 'HOME',
- 'LANG',
- 'LC_CTYPE', 'LC_NUMERIC', 'LC_TIME', 'LC_COLLATE', 'LC_MONETARY',
- 'LC_MESSAGES', 'LC_PAPER', 'LC_NAME', 'LC_ADDRESS', 'LC_TELEPHONE',
- 'LC_MEASUREMENT', 'LC_IDENTIFICATION', 'LC_ALL'
- # what else?
- )
- #
- # LANG, LC_ALL, LC_COLLATE, ...
+ env = roverlay.util.keepenv ( SHENV_VARS_TO_KEEP )
+
+ for varname, value in os.environ.items():
+ if any (
+ _fnmatch ( varname, pattern )
+ for pattern in SHENV_WILDCARD_VARS_TO_KEEP
+ ):
+ env [varname] = value
+
+ # what else?
#
- # GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL,
- # GIT_COMMITTER_NAME, GIT_COMMITTER_EMAIL, ...
+ # GIT_AUTHOR_NAME, GIT_AUTHOR_EMAIL, GIT_COMMITTER_NAME,
+ # GIT_COMMITTER_EMAIL, ... are set in the hookrc file
#
# GIT_EDITOR and GIT_ASKPASS are set to /bin/false here
#
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
@ 2014-01-18 14:59 André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2014-01-18 14:59 UTC (permalink / raw
To: gentoo-commits
commit: 61ca14c2389bce71ecf177d45f150712445ee81e
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Jan 14 15:39:31 2014 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Jan 14 15:39:31 2014 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=61ca14c2
fix 51e381ee1de2db29adcfa9091e85126385d622cd
Use keepenv_v(), not keepenv().
---
roverlay/tools/shenv.py | 2 +-
1 file changed, 1 insertion(+), 1 deletion(-)
diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py
index a136bc4..c087f7a 100644
--- a/roverlay/tools/shenv.py
+++ b/roverlay/tools/shenv.py
@@ -147,7 +147,7 @@ def setup_env():
# import os.environ
if roverlay.config.get ( "SHELL_ENV.filter_env", True ):
# (keepenv does not support wildcars)
- env = roverlay.util.keepenv ( SHENV_VARS_TO_KEEP )
+ env = roverlay.util.keepenv_v ( SHENV_VARS_TO_KEEP )
for varname, value in os.environ.items():
if any (
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
@ 2015-01-26 17:41 André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2015-01-26 17:41 UTC (permalink / raw
To: gentoo-commits
commit: f195588254e4f1516ec024973ebba3660622c3fa
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Mon Dec 15 23:00:17 2014 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Mon Dec 15 23:00:17 2014 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=f1955882
add subprocess helper module
---
roverlay/tools/subproc.py | 157 ++++++++++++++++++++++++++++++++++++++++++++++
1 file changed, 157 insertions(+)
diff --git a/roverlay/tools/subproc.py b/roverlay/tools/subproc.py
new file mode 100644
index 0000000..a62601f
--- /dev/null
+++ b/roverlay/tools/subproc.py
@@ -0,0 +1,157 @@
+# R overlay -- tools, subprocess helpers
+# -*- coding: utf-8 -*-
+# Copyright (C) 2014 André Erdmann <dywi@mailerd.de>
+# 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
+import subprocess
+import sys
+
+__all__ = [
+ 'get_subproc_devnull',
+ 'subproc_send_term', 'subproc_send_kill',
+ 'stop_subprocess', 'gracefully_stop_subprocess',
+ 'create_subprocess', 'run_subprocess'
+]
+
+# python >= 3.3 has ProcessLookupError, use more generic exception otherwise
+if sys.hexversion >= 0x3030000:
+ _ProcessLookupError = ProcessLookupError
+else:
+ _ProcessLookupError = OSError
+
+# python >= 3.3:
+if hasattr ( subprocess, 'DEVNULL' ):
+ def get_subproc_devnull(mode=None):
+ """Returns a devnull object suitable
+ for passing it as stdin/stdout/stderr to subprocess.Popen().
+
+ Python 3.3 and later variant: uses subprocess.DEVNULL
+
+ arguments:
+ * mode -- ignored
+ """
+ return subprocess.DEVNULL
+else:
+ def get_subproc_devnull(mode='a+'):
+ """Returns a devnull object suitable
+ for passing it as stdin/stdout/stderr to subprocess.Popen().
+
+ Python 3.2 and earlier variant: opens os.devnull
+
+ arguments:
+ * mode -- mode for open(). Defaults to read/append
+ """
+ return open ( os.devnull, mode )
+# --
+
+def _proc_catch_lookup_err ( func ):
+ def wrapped ( proc ):
+ try:
+ func ( proc )
+ except _ProcessLookupError:
+ return False
+ return True
+
+ return wrapped
+
+@_proc_catch_lookup_err
+def subproc_send_term ( proc ):
+ proc.terminate()
+
+@_proc_catch_lookup_err
+def subproc_send_kill ( proc ):
+ proc.kill()
+
+
+def stop_subprocess ( proc, kill_timeout_cs=10 ):
+ """Terminates or kills a subprocess created by subprocess.Popen().
+
+ Sends SIGTERM first and sends SIGKILL if the process is still alive after
+ the given timeout.
+
+ Returns: None
+
+ arguments:
+ * proc -- subprocess
+ * kill_timeout_cs -- max time to wait after terminate() before sending a
+ kill signal (in centiseconds). Should be an int.
+ Defaults to 10 (= 1s).
+ """
+ if not subproc_send_term ( proc ):
+ return
+
+ try:
+ for k in range ( kill_timeout_cs ):
+ if proc.poll() is not None:
+ return
+ time.sleep ( 0.1 )
+ except:
+ subproc_send_kill ( proc )
+ else:
+ subproc_send_kill ( proc )
+# --- end of stop_subprocess (...) ---
+
+def gracefully_stop_subprocess ( proc, **kill_kwargs ):
+ try:
+ if subproc_send_term ( proc ):
+ proc.communicate()
+ except:
+ stop_subprocess ( proc, **kwargs )
+ raise
+
+def create_subprocess ( cmdv, **kwargs ):
+ """subprocess.Popen() wrapper that redirects stdin/stdout/stderr to
+ devnull or to a pipe if set to False/True.
+
+ Returns: subprocess
+
+ arguments:
+ * cmdv --
+ * **kwargs --
+ """
+ devnull_obj = None
+
+ for key in { 'stdin', 'stdout', 'stderr' }:
+ if key not in kwargs:
+ pass
+ elif kwargs [key] is True:
+ kwargs [key] = subprocess.PIPE
+
+ elif kwargs [key] is False:
+ if devnull_obj is None:
+ devnull_obj = get_subproc_devnull()
+ assert devnull_obj is not None
+
+ kwargs [key] = devnull_obj
+ # else don't care
+ # --
+
+ return subprocess.Popen ( cmdv, **kwargs )
+# --- end of create_subprocess (...) ---
+
+def run_subprocess ( cmdv, kill_timeout_cs=10, **kwargs ):
+ """Calls create_subprocess() and waits for the process to exit.
+ Catches exceptions and terminates/kills the process in that case
+
+ Returns: 2-tuple ( subprocess, output )
+
+ arguments:
+ * cmdv --
+ * kill_timeout_cs -- time to wait after SIGTERM before sending SIGKILL
+ (in centiseconds), see stop_subprocess() for details
+ Defaults to 10.
+ * **kwargs --
+ """
+ proc = None
+ try:
+ proc = create_subprocess ( cmdv, **kwargs )
+ output = proc.communicate()
+ except:
+ if proc is not None:
+ stop_subprocess ( proc, kill_timeout_cs=kill_timeout_cs )
+ raise
+
+ return ( proc, output )
+# --- end of run_subprocess (...) ---
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
@ 2015-01-26 17:41 André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2015-01-26 17:41 UTC (permalink / raw
To: gentoo-commits
commit: 60f3c871f6320e3b637d61f319c5960824567c82
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Tue Dec 16 00:17:10 2014 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Tue Dec 16 00:17:10 2014 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=60f3c871
run non-user hooks with /dev/null as stdin
---
roverlay/tools/shenv.py | 10 ++++++++--
1 file changed, 8 insertions(+), 2 deletions(-)
diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py
index 8f2cea2..5670354 100644
--- a/roverlay/tools/shenv.py
+++ b/roverlay/tools/shenv.py
@@ -29,6 +29,8 @@ LOGGER = logging.getLogger ( 'shenv' )
NULL_PHASE = 'null'
+SHENV_PHASES_WITH_STDIN = frozenset ({ 'user', })
+
SHENV_VARS_TO_KEEP = frozenset ({
( 'PATH', '/usr/local/bin:/usr/bin:/bin' ),
'PWD',
@@ -348,7 +350,7 @@ def run_script_exec (
def run_script (
script, phase, argv=(), return_success=False, logger=None,
- log_output=True, initial_dir=None, allow_stdin=True
+ log_output=True, initial_dir=None
):
# global _SHELL_INTPR
# if _SHELL_INTPR is None:
@@ -360,7 +362,11 @@ def run_script (
script_call, output = _run_subprocess (
# ( _SHELL_INTPR, script, ),
( script, ) + argv,
- stdin = None if allow_stdin else False,
+ stdin = (
+ None if (
+ my_env ['ROVERLAY_PHASE'] in SHENV_PHASES_WITH_STDIN
+ ) else False
+ ),
stdout = subprocess.PIPE if log_output else None,
stderr = subprocess.PIPE if log_output else None,
cwd = my_env ['S'] if initial_dir is None else initial_dir,
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
@ 2015-01-26 17:41 André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2015-01-26 17:41 UTC (permalink / raw
To: gentoo-commits
commit: cff8c8dd63384b8b38375168a4859fd0a78f3858
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Mon Dec 15 23:07:40 2014 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Mon Dec 15 23:07:40 2014 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=cff8c8dd
run commands without stdin by default
roverlay.tools->run_command(): let stdin default to /dev/null
---
roverlay/tools/runcmd.py | 6 +++---
1 file changed, 3 insertions(+), 3 deletions(-)
diff --git a/roverlay/tools/runcmd.py b/roverlay/tools/runcmd.py
index 7561669..08e1bda 100644
--- a/roverlay/tools/runcmd.py
+++ b/roverlay/tools/runcmd.py
@@ -16,7 +16,7 @@ DEBUG_TO_CONSOLE = False
def run_command_get_output (
cmdv, env, debug_to_console=False, use_filter=True, filter_func=None,
- binary_stdout=False, stdin=None
+ binary_stdout=False, stdin=False
):
# note that debug_to_console breaks calls that want to parse stdout
pipe_target = None if debug_to_console else subprocess.PIPE
@@ -46,9 +46,9 @@ def run_command_get_output (
return ( cmd_call, output )
# --- end of run_command_get_output (...) ---
-def run_command ( cmdv, env, logger, return_success=False ):
+def run_command ( cmdv, env, logger, return_success=False, **kwargs ):
cmd_call, output = run_command_get_output (
- cmdv, env, DEBUG_TO_CONSOLE, use_filter=True
+ cmdv, env, DEBUG_TO_CONSOLE, use_filter=True, **kwargs
)
# log stderr
^ permalink raw reply related [flat|nested] 17+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/
@ 2015-02-18 2:19 André Erdmann
0 siblings, 0 replies; 17+ messages in thread
From: André Erdmann @ 2015-02-18 2:19 UTC (permalink / raw
To: gentoo-commits
commit: 91474197a0ad11ad8169e8dbf582c9a29ab67cf9
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Wed Feb 18 02:16:07 2015 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Wed Feb 18 02:16:07 2015 +0000
URL: http://sources.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=91474197
fix 8647dac1ec5ad63cd44a8dfc121b8b0942b688ad
add missing module / kwargs=>kill_kwargs typo
---
roverlay/tools/subproc.py | 3 ++-
1 file changed, 2 insertions(+), 1 deletion(-)
diff --git a/roverlay/tools/subproc.py b/roverlay/tools/subproc.py
index a62601f..b5fa476 100644
--- a/roverlay/tools/subproc.py
+++ b/roverlay/tools/subproc.py
@@ -7,6 +7,7 @@
import os
import subprocess
import sys
+import time
__all__ = [
'get_subproc_devnull',
@@ -98,7 +99,7 @@ def gracefully_stop_subprocess ( proc, **kill_kwargs ):
if subproc_send_term ( proc ):
proc.communicate()
except:
- stop_subprocess ( proc, **kwargs )
+ stop_subprocess ( proc, **kill_kwargs )
raise
def create_subprocess ( cmdv, **kwargs ):
^ permalink raw reply related [flat|nested] 17+ messages in thread
end of thread, other threads:[~2015-02-18 2:19 UTC | newest]
Thread overview: 17+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2014-01-18 14:59 [gentoo-commits] proj/R_overlay:master commit in: roverlay/tools/ André Erdmann
-- strict thread matches above, loose matches on Subject: below --
2015-02-18 2:19 André Erdmann
2015-01-26 17:41 André Erdmann
2015-01-26 17:41 André Erdmann
2015-01-26 17:41 André Erdmann
2013-11-14 18:24 André Erdmann
2013-09-04 10:16 André Erdmann
2013-08-21 13:51 André Erdmann
2013-08-14 14:56 André Erdmann
2013-08-13 8:56 André Erdmann
2013-08-13 8:56 André Erdmann
2013-08-05 11:44 André Erdmann
2013-08-02 10:34 André Erdmann
2013-07-29 14:56 André Erdmann
2013-07-11 16:44 [gentoo-commits] proj/R_overlay:gsoc13/next " André Erdmann
2013-07-11 16:29 ` [gentoo-commits] proj/R_overlay:master " 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
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox