* [gentoo-commits] proj/R_overlay:gsoc13/next commit in: /, roverlay/tools/, roverlay/config/, roverlay/
@ 2013-07-18 19:25 André Erdmann
2013-07-23 7:51 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
0 siblings, 1 reply; 2+ messages in thread
From: André Erdmann @ 2013-07-18 19:25 UTC (permalink / raw
To: gentoo-commits
commit: 837524e88553479910588445e2cd71cecd26e5fb
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Jul 18 19:17:51 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Jul 18 19:17:51 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=837524e8
remove --run-script from roverlay, add roverlay-sh
roverlay no longer supports --run-script. Instead "roverlay-sh" can be used to
run shell scripts (e.g. by using a '#!/usr/bin/roverlay-sh' hashbang in the
script).
---
roverlay/argutil.py | 2 ++
roverlay/config/entrymap.py | 5 ++++
roverlay/main.py | 68 ++++++++++++++++++++++++++++-----------------
roverlay/tools/shenv.py | 43 +++++++++++++++++++++++++++-
setup.py | 2 ++
5 files changed, 93 insertions(+), 27 deletions(-)
diff --git a/roverlay/argutil.py b/roverlay/argutil.py
index 3cf4428..df40d34 100644
--- a/roverlay/argutil.py
+++ b/roverlay/argutil.py
@@ -6,6 +6,8 @@
"""provides arg parsing for the roverlay main script"""
+# TODO: remove --run-script here
+
__all__ = [ 'parse_argv', ]
import os
diff --git a/roverlay/config/entrymap.py b/roverlay/config/entrymap.py
index e87a289..5800000 100644
--- a/roverlay/config/entrymap.py
+++ b/roverlay/config/entrymap.py
@@ -491,6 +491,11 @@ CONFIG_ENTRY_MAP = dict (
description = 'filter shell env',
),
+ shell = dict (
+ path = [ 'SHELL_ENV', 'shell', ],
+ description = "default command interpreter (for roverlay-sh etc.)",
+ ),
+
event_hook = dict (
path = [ 'EVENT_HOOK', 'exe', ],
value_type = 'fs_file',
diff --git a/roverlay/main.py b/roverlay/main.py
index 7a88171..31a5ea0 100644
--- a/roverlay/main.py
+++ b/roverlay/main.py
@@ -12,6 +12,9 @@ import os
import sys
import time
+import roverlay
+import roverlay.tools.shenv
+
# roverlay modules will be imported later
DEFAULT_CONFIG_FILE_NAME = "R-overlay.conf"
@@ -85,6 +88,42 @@ def locate_config_file (
return DEFAULT_CONFIG_FILE
# --- end of locate_config_file (...) ---
+def default_helper_setup ( ROVERLAY_INSTALLED ):
+ roverlay.setup_initial_logger()
+ config_file = locate_config_file ( ROVERLAY_INSTALLED=ROVERLAY_INSTALLED )
+
+ config = roverlay.load_config_file (
+ config_file, extraconf={ 'installed': ROVERLAY_INSTALLED, },
+ setup_logger=False, load_main_only=True,
+ )
+ roverlay.tools.shenv.setup_env()
+ return config
+# --- end of default_helper_setup (...) ---
+
+def run_script_main_installed():
+ return run_script_main ( True )
+
+def run_script_main ( ROVERLAY_INSTALLED ):
+ if len ( sys.argv ) < 2 or not sys.argv[0]:
+ die ( "no executable specified.", DIE.USAGE )
+
+ default_helper_setup ( ROVERLAY_INSTALLED )
+ roverlay.tools.shenv.run_script_exec (
+ sys.argv[1], "runscript", sys.argv[1:], use_path=True
+ )
+# --- end of run_script_main (...) ---
+
+def run_shell_main_installed():
+ return run_shell_main ( True )
+
+def run_shell_main ( ROVERLAY_INSTALLED ):
+ config = default_helper_setup ( ROVERLAY_INSTALLED )
+ shell = config.get ( 'SHELL_ENV.shell', '/bin/sh' )
+ roverlay.tools.shenv.run_script_exec (
+ shell, "shell", [ shell, ] + sys.argv [1:], use_path=False
+ )
+# --- end of run_shell_main (...) ---
+
def run_setupdirs ( config, target_uid, target_gid ):
import stat
@@ -439,17 +478,11 @@ def main (
want_logging = True
do_setupdirs = False
- do_runscript = False
if 'sync' in actions and OPTION ( 'nosync' ):
die ( "sync command blocked by --nosync opt.", DIE.ARG )
- elif 'run_script' in extra_opts:
- # add --run-script as command
- actions.add ( "run_script" )
- do_runscript = True
- want_logging = False
- if 'setupdirs' in actions:
+ elif 'setupdirs' in actions:
do_setupdirs = True
want_logging = False
if len ( actions ) > 1:
@@ -481,7 +514,7 @@ def main (
config_file,
extraconf = additional_config,
setup_logger = want_logging,
- load_main_only = ( do_setupdirs or do_runscript ),
+ load_main_only = do_setupdirs,
)
del config_file, additional_config
except:
@@ -495,24 +528,7 @@ def main (
else:
raise
- if do_runscript:
- import roverlay.tools.shenv
- import roverlay.hook
- roverlay.hook.setup ( force=True )
- if roverlay.hook.phase_allowed ( "user" ):
- sys.exit (
- roverlay.tools.shenv.run_script (
- script = extra_opts ['run_script'],
- phase = "user",
- argv = extra_opts ['run_script_args'],
- return_success = False,
- log_output = False,
- initial_dir = os.getcwd(),
- ).returncode
- )
- else:
- die ( "--run-script: 'user' phase is not allowed." )
- elif do_setupdirs:
+ if do_setupdirs:
sys.exit ( run_setupdirs (
conf, extra_opts['target_uid'], extra_opts['target_gid']
) )
diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py
index 084f318..6fcaab3 100644
--- a/roverlay/tools/shenv.py
+++ b/roverlay/tools/shenv.py
@@ -6,6 +6,7 @@
import logging
import os
+import sys
import subprocess
import tempfile
import time
@@ -56,6 +57,10 @@ NULL_PHASE = 'null'
#
# depends on config value
#
+# $WORKDIR
+#
+# (cachedir.root)
+#
# $SHLIB (optional)
#
# shell functions dir (if found, ${ADDITIONS_DIR}/shlib)
@@ -116,6 +121,10 @@ def setup_env():
'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?
)
#
@@ -142,6 +151,15 @@ def setup_env():
## create shell vars
+ # 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' ):
+ setup ( 'ROVERLAY_EXE', roverlay_exe + '.py' )
+ else:
+ setup ( 'ROVERLAY_EXE', roverlay_exe )
+
# str $ROVERLAY_PHASE
# properly defined in shenv_run()
#
@@ -166,6 +184,8 @@ def setup_env():
# str::dirpath $DISTROOT
setup_conf ( 'DISTROOT', 'OVERLAY.DISTDIR.root' )
+ setup_conf ( 'WORKDIR', 'CACHEDIR.root' )
+
# str::dirpath $TMPDIR := <default>
setup (
'TMPDIR',
@@ -287,10 +307,31 @@ def update_env ( **info ):
return _SHELL_ENV
# --- end of update_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;
+
+ if initial_dir:
+ os.chdir ( initial_dir )
+
+ if use_path:
+ os.execvpe ( script, argv, my_env )
+ else:
+ os.execve ( script, argv, my_env )
+ raise Exception ( "exec? (unreachable code)" )
+# --- end of run_script_exec (...) ---
+
def run_script (
script, phase, argv=(), return_success=False, logger=None,
- log_output=True, initial_dir=None,
+ log_output=True, initial_dir=None
):
# global _SHELL_INTPR
# if _SHELL_INTPR is None:
diff --git a/setup.py b/setup.py
index d94e237..e139559 100755
--- a/setup.py
+++ b/setup.py
@@ -15,6 +15,8 @@ setup (
'console_scripts': [
'roverlay = roverlay.main:main_installed',
'roverlay-mkconfig = roverlay.config.mkconfig:make_config',
+ 'roverlay-sh = roverlay.main:run_shell_main_installed',
+ #'roverlay-exec = roverlay.main:run_script_main_installed',
]
},
packages = find_packages ( exclude=[ 'tests', 'tests.*' ] ),
^ permalink raw reply related [flat|nested] 2+ messages in thread
* [gentoo-commits] proj/R_overlay:master commit in: /, roverlay/tools/, roverlay/config/, roverlay/
2013-07-18 19:25 [gentoo-commits] proj/R_overlay:gsoc13/next commit in: /, roverlay/tools/, roverlay/config/, roverlay/ André Erdmann
@ 2013-07-23 7:51 ` André Erdmann
0 siblings, 0 replies; 2+ messages in thread
From: André Erdmann @ 2013-07-23 7:51 UTC (permalink / raw
To: gentoo-commits
commit: 837524e88553479910588445e2cd71cecd26e5fb
Author: André Erdmann <dywi <AT> mailerd <DOT> de>
AuthorDate: Thu Jul 18 19:17:51 2013 +0000
Commit: André Erdmann <dywi <AT> mailerd <DOT> de>
CommitDate: Thu Jul 18 19:17:51 2013 +0000
URL: http://git.overlays.gentoo.org/gitweb/?p=proj/R_overlay.git;a=commit;h=837524e8
remove --run-script from roverlay, add roverlay-sh
roverlay no longer supports --run-script. Instead "roverlay-sh" can be used to
run shell scripts (e.g. by using a '#!/usr/bin/roverlay-sh' hashbang in the
script).
---
roverlay/argutil.py | 2 ++
roverlay/config/entrymap.py | 5 ++++
roverlay/main.py | 68 ++++++++++++++++++++++++++++-----------------
roverlay/tools/shenv.py | 43 +++++++++++++++++++++++++++-
setup.py | 2 ++
5 files changed, 93 insertions(+), 27 deletions(-)
diff --git a/roverlay/argutil.py b/roverlay/argutil.py
index 3cf4428..df40d34 100644
--- a/roverlay/argutil.py
+++ b/roverlay/argutil.py
@@ -6,6 +6,8 @@
"""provides arg parsing for the roverlay main script"""
+# TODO: remove --run-script here
+
__all__ = [ 'parse_argv', ]
import os
diff --git a/roverlay/config/entrymap.py b/roverlay/config/entrymap.py
index e87a289..5800000 100644
--- a/roverlay/config/entrymap.py
+++ b/roverlay/config/entrymap.py
@@ -491,6 +491,11 @@ CONFIG_ENTRY_MAP = dict (
description = 'filter shell env',
),
+ shell = dict (
+ path = [ 'SHELL_ENV', 'shell', ],
+ description = "default command interpreter (for roverlay-sh etc.)",
+ ),
+
event_hook = dict (
path = [ 'EVENT_HOOK', 'exe', ],
value_type = 'fs_file',
diff --git a/roverlay/main.py b/roverlay/main.py
index 7a88171..31a5ea0 100644
--- a/roverlay/main.py
+++ b/roverlay/main.py
@@ -12,6 +12,9 @@ import os
import sys
import time
+import roverlay
+import roverlay.tools.shenv
+
# roverlay modules will be imported later
DEFAULT_CONFIG_FILE_NAME = "R-overlay.conf"
@@ -85,6 +88,42 @@ def locate_config_file (
return DEFAULT_CONFIG_FILE
# --- end of locate_config_file (...) ---
+def default_helper_setup ( ROVERLAY_INSTALLED ):
+ roverlay.setup_initial_logger()
+ config_file = locate_config_file ( ROVERLAY_INSTALLED=ROVERLAY_INSTALLED )
+
+ config = roverlay.load_config_file (
+ config_file, extraconf={ 'installed': ROVERLAY_INSTALLED, },
+ setup_logger=False, load_main_only=True,
+ )
+ roverlay.tools.shenv.setup_env()
+ return config
+# --- end of default_helper_setup (...) ---
+
+def run_script_main_installed():
+ return run_script_main ( True )
+
+def run_script_main ( ROVERLAY_INSTALLED ):
+ if len ( sys.argv ) < 2 or not sys.argv[0]:
+ die ( "no executable specified.", DIE.USAGE )
+
+ default_helper_setup ( ROVERLAY_INSTALLED )
+ roverlay.tools.shenv.run_script_exec (
+ sys.argv[1], "runscript", sys.argv[1:], use_path=True
+ )
+# --- end of run_script_main (...) ---
+
+def run_shell_main_installed():
+ return run_shell_main ( True )
+
+def run_shell_main ( ROVERLAY_INSTALLED ):
+ config = default_helper_setup ( ROVERLAY_INSTALLED )
+ shell = config.get ( 'SHELL_ENV.shell', '/bin/sh' )
+ roverlay.tools.shenv.run_script_exec (
+ shell, "shell", [ shell, ] + sys.argv [1:], use_path=False
+ )
+# --- end of run_shell_main (...) ---
+
def run_setupdirs ( config, target_uid, target_gid ):
import stat
@@ -439,17 +478,11 @@ def main (
want_logging = True
do_setupdirs = False
- do_runscript = False
if 'sync' in actions and OPTION ( 'nosync' ):
die ( "sync command blocked by --nosync opt.", DIE.ARG )
- elif 'run_script' in extra_opts:
- # add --run-script as command
- actions.add ( "run_script" )
- do_runscript = True
- want_logging = False
- if 'setupdirs' in actions:
+ elif 'setupdirs' in actions:
do_setupdirs = True
want_logging = False
if len ( actions ) > 1:
@@ -481,7 +514,7 @@ def main (
config_file,
extraconf = additional_config,
setup_logger = want_logging,
- load_main_only = ( do_setupdirs or do_runscript ),
+ load_main_only = do_setupdirs,
)
del config_file, additional_config
except:
@@ -495,24 +528,7 @@ def main (
else:
raise
- if do_runscript:
- import roverlay.tools.shenv
- import roverlay.hook
- roverlay.hook.setup ( force=True )
- if roverlay.hook.phase_allowed ( "user" ):
- sys.exit (
- roverlay.tools.shenv.run_script (
- script = extra_opts ['run_script'],
- phase = "user",
- argv = extra_opts ['run_script_args'],
- return_success = False,
- log_output = False,
- initial_dir = os.getcwd(),
- ).returncode
- )
- else:
- die ( "--run-script: 'user' phase is not allowed." )
- elif do_setupdirs:
+ if do_setupdirs:
sys.exit ( run_setupdirs (
conf, extra_opts['target_uid'], extra_opts['target_gid']
) )
diff --git a/roverlay/tools/shenv.py b/roverlay/tools/shenv.py
index 084f318..6fcaab3 100644
--- a/roverlay/tools/shenv.py
+++ b/roverlay/tools/shenv.py
@@ -6,6 +6,7 @@
import logging
import os
+import sys
import subprocess
import tempfile
import time
@@ -56,6 +57,10 @@ NULL_PHASE = 'null'
#
# depends on config value
#
+# $WORKDIR
+#
+# (cachedir.root)
+#
# $SHLIB (optional)
#
# shell functions dir (if found, ${ADDITIONS_DIR}/shlib)
@@ -116,6 +121,10 @@ def setup_env():
'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?
)
#
@@ -142,6 +151,15 @@ def setup_env():
## create shell vars
+ # 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' ):
+ setup ( 'ROVERLAY_EXE', roverlay_exe + '.py' )
+ else:
+ setup ( 'ROVERLAY_EXE', roverlay_exe )
+
# str $ROVERLAY_PHASE
# properly defined in shenv_run()
#
@@ -166,6 +184,8 @@ def setup_env():
# str::dirpath $DISTROOT
setup_conf ( 'DISTROOT', 'OVERLAY.DISTDIR.root' )
+ setup_conf ( 'WORKDIR', 'CACHEDIR.root' )
+
# str::dirpath $TMPDIR := <default>
setup (
'TMPDIR',
@@ -287,10 +307,31 @@ def update_env ( **info ):
return _SHELL_ENV
# --- end of update_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;
+
+ if initial_dir:
+ os.chdir ( initial_dir )
+
+ if use_path:
+ os.execvpe ( script, argv, my_env )
+ else:
+ os.execve ( script, argv, my_env )
+ raise Exception ( "exec? (unreachable code)" )
+# --- end of run_script_exec (...) ---
+
def run_script (
script, phase, argv=(), return_success=False, logger=None,
- log_output=True, initial_dir=None,
+ log_output=True, initial_dir=None
):
# global _SHELL_INTPR
# if _SHELL_INTPR is None:
diff --git a/setup.py b/setup.py
index d94e237..e139559 100755
--- a/setup.py
+++ b/setup.py
@@ -15,6 +15,8 @@ setup (
'console_scripts': [
'roverlay = roverlay.main:main_installed',
'roverlay-mkconfig = roverlay.config.mkconfig:make_config',
+ 'roverlay-sh = roverlay.main:run_shell_main_installed',
+ #'roverlay-exec = roverlay.main:run_script_main_installed',
]
},
packages = find_packages ( exclude=[ 'tests', 'tests.*' ] ),
^ permalink raw reply related [flat|nested] 2+ messages in thread
end of thread, other threads:[~2013-07-23 7:51 UTC | newest]
Thread overview: 2+ messages (download: mbox.gz follow: Atom feed
-- links below jump to the message on this page --
2013-07-18 19:25 [gentoo-commits] proj/R_overlay:gsoc13/next commit in: /, roverlay/tools/, roverlay/config/, roverlay/ André Erdmann
2013-07-23 7:51 ` [gentoo-commits] proj/R_overlay:master " André Erdmann
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox