some shell related cleanups
Signed-off-by: Nico Schottelius <nico@bento.schottelius.org>
This commit is contained in:
parent
0eb67a00f5
commit
79fea569b9
2 changed files with 48 additions and 19 deletions
|
@ -127,8 +127,8 @@ class Local(object):
|
||||||
Return the output as a string.
|
Return the output as a string.
|
||||||
|
|
||||||
"""
|
"""
|
||||||
assert isinstance(command, (list, tuple)), "list or tuple argument expected, got: %s" % command
|
|
||||||
self.log.debug("Local run: %s", command)
|
self.log.debug("Local run: %s", command)
|
||||||
|
assert isinstance(command, (list, tuple)), "list or tuple argument expected, got: %s" % command
|
||||||
|
|
||||||
if env is None:
|
if env is None:
|
||||||
env = os.environ.copy()
|
env = os.environ.copy()
|
||||||
|
|
|
@ -23,6 +23,10 @@ import logging
|
||||||
import os
|
import os
|
||||||
import subprocess
|
import subprocess
|
||||||
|
|
||||||
|
# initialise cdist
|
||||||
|
import cdist.context
|
||||||
|
|
||||||
|
|
||||||
# FIXME: only considering config here - enable
|
# FIXME: only considering config here - enable
|
||||||
# command line switch for using install object
|
# command line switch for using install object
|
||||||
# when it is available
|
# when it is available
|
||||||
|
@ -32,29 +36,54 @@ log = logging.getLogger(__name__)
|
||||||
|
|
||||||
class Shell(object):
|
class Shell(object):
|
||||||
|
|
||||||
def __init__(self):
|
def __init__(self, shell=None):
|
||||||
pass
|
|
||||||
|
|
||||||
@classmethod
|
self.shell = shell
|
||||||
def commandline(cls, args):
|
|
||||||
pass
|
|
||||||
# initialise cdist
|
|
||||||
import cdist.context
|
|
||||||
|
|
||||||
context = cdist.context.Context(
|
self.target_host = "cdist-shell-no-target-host"
|
||||||
target_host="cdist-shell-no-target-host",
|
self.context = cdist.context.Context(
|
||||||
|
target_host=self.target_host,
|
||||||
remote_copy=cdist.REMOTE_COPY,
|
remote_copy=cdist.REMOTE_COPY,
|
||||||
remote_exec=cdist.REMOTE_EXEC)
|
remote_exec=cdist.REMOTE_EXEC)
|
||||||
|
|
||||||
config = cdist.config.Config(context)
|
|
||||||
|
|
||||||
# Startup Shell
|
def _init_shell(self):
|
||||||
if args.shell:
|
"""Select shell to execute, if not specified by user"""
|
||||||
shell = [args.shell]
|
|
||||||
elif 'SHELL' in os.environ:
|
if not self.shell:
|
||||||
shell = [os.environ['SHELL']]
|
if 'SHELL' in os.environ:
|
||||||
else:
|
self.shell = os.environ['SHELL']
|
||||||
shell = ["/bin/sh"]
|
else:
|
||||||
|
self.shell = "/bin/sh"
|
||||||
|
|
||||||
|
def _init_files_dirs(self):
|
||||||
|
self.context.local.create_files_dirs()
|
||||||
|
|
||||||
|
def _init_environment(self):
|
||||||
|
self.env = os.environ.copy()
|
||||||
|
additional_env = {
|
||||||
|
'PATH': "%s:%s" % (self.context.local.bin_path, os.environ['PATH']),
|
||||||
|
'__cdist_type_base_path': self.context.local.type_path, # for use in type emulator
|
||||||
|
'__cdist_manifest': "cdist shell",
|
||||||
|
'__global': self.context.local.out_path,
|
||||||
|
'__target_host': self.target_host,
|
||||||
|
'__manifest': self.context.local.manifest_path,
|
||||||
|
'__explorer': self.context.local.global_explorer_path,
|
||||||
|
}
|
||||||
|
|
||||||
|
self.env.update(additional_env)
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self._init_shell()
|
||||||
|
self._init_files_dirs()
|
||||||
|
self._init_environment()
|
||||||
|
|
||||||
log.info("Starting shell...")
|
log.info("Starting shell...")
|
||||||
subprocess.call(shell)
|
self.context.local.run([self.shell], self.env)
|
||||||
|
log.info("Finished shell.")
|
||||||
|
|
||||||
|
@classmethod
|
||||||
|
def commandline(cls, args):
|
||||||
|
print(os.environ['PYTHONPATH'])
|
||||||
|
shell = cls(args.shell)
|
||||||
|
shell.run()
|
||||||
|
|
Loading…
Reference in a new issue