From c793825edb03f83e2bd9c43c4fcee9032e6adef0 Mon Sep 17 00:00:00 2001 From: Nico Schottelius Date: Wed, 7 Aug 2013 17:52:34 +0200 Subject: [PATCH] re-arrange REMOTE_COPY/EXEC for Shell use Signed-off-by: Nico Schottelius --- cdist/__init__.py | 3 +++ cdist/shell.py | 28 ++++++++++++++++++++++++---- scripts/cdist | 6 ++++-- 3 files changed, 31 insertions(+), 6 deletions(-) diff --git a/cdist/__init__.py b/cdist/__init__.py index bd45e740..20c76b31 100644 --- a/cdist/__init__.py +++ b/cdist/__init__.py @@ -40,8 +40,11 @@ BANNER = """ "8888P' `"888*"" R888" ` ^"F 'Y" "P' "" "" """ + DOT_CDIST = ".cdist" +REMOTE_COPY = "scp -o User=root -q" +REMOTE_EXEC = "ssh -o User=root -q" class Error(Exception): """Base exception class for this project""" diff --git a/cdist/shell.py b/cdist/shell.py index f68a47ed..bc2c1ee9 100644 --- a/cdist/shell.py +++ b/cdist/shell.py @@ -20,9 +20,13 @@ # import logging -import sys +import os +import subprocess -import cdist +# FIXME: only considering config here - enable +# command line switch for using install object +# when it is available +import cdist.config log = logging.getLogger(__name__) @@ -32,9 +36,25 @@ class Shell(object): pass @classmethod - def commandline(cls): + def commandline(cls, args): pass # initialise cdist + import cdist.context + + context = cdist.context.Context( + target_host="cdist-shell-no-target-host", + remote_copy=cdist.REMOTE_COPY, + remote_exec=cdist.REMOTE_EXEC) + + config = cdist.config.Config(context) + # Startup Shell + if args.shell: + shell = [args.shell] + elif 'SHELL' in os.environ: + shell = [os.environ['SHELL']] + else: + shell = ["/bin/sh"] - + log.info("Starting shell...") + subprocess.call(shell) diff --git a/scripts/cdist b/scripts/cdist index 79a89a7c..935e9096 100755 --- a/scripts/cdist +++ b/scripts/cdist @@ -75,11 +75,11 @@ def commandline(): parser['configinstall'].add_argument('--remote-copy', help='Command to use for remote copy (should behave like scp)', action='store', dest='remote_copy', - default="scp -o User=root -q") + default=cdist.REMOTE_COPY) parser['configinstall'].add_argument('--remote-exec', help='Command to use for remote execution (should behave like ssh)', action='store', dest='remote_exec', - default="ssh -o User=root -q") + default=cdist.REMOTE_EXEC) # Config parser['config'] = parser['sub'].add_parser('config', @@ -89,6 +89,8 @@ def commandline(): # Shell parser['shell'] = parser['sub'].add_parser('shell', parents=[parser['loglevel']]) + parser['shell'].add_argument('-s', '--shell', + help='Select shell to use, defaults to current shell') parser['shell'].set_defaults(func=cdist.shell.Shell.commandline)