]> scripts.mit.edu Git - wizard.git/blobdiff - wizard/shell.py
Add "global style" options after command options.
[wizard.git] / wizard / shell.py
index 43a4468159db5d53b96f06b588577ac287994ea4..94fe3cdc6242c58b6045e647189465b70510a076 100644 (file)
@@ -6,24 +6,10 @@ import os
 import wizard as _wizard
 from wizard import util
 
+"""This is the path to the wizard executable as specified
+by the caller; it lets us recursively invoke wizard"""
 wizard = sys.argv[0]
 
-class CallError(_wizard.Error):
-    def __init__(self, code, args, stdout, stderr):
-        self.code = code
-        self.args = args
-        self.stdout = stdout
-        self.stderr = stderr
-    def __str__(self):
-        return "CallError [%d]" % self.code
-
-class PythonCallError(CallError):
-    def __init__(self, code, args, stdout, stderr):
-        self.name = util.get_exception_name(stderr)
-        CallError.__init__(self, code, args, stdout, stderr)
-    def __str__(self):
-        return "PythonCallError [%s]" % self.name
-
 def is_python(args):
     return args[0] == "python" or args[0] == wizard
 
@@ -69,7 +55,10 @@ class Shell(object):
         uid = kwargs.pop("uid", None)
         kwargs.setdefault("python", is_python(args))
         if not user and not uid: return self.call(*args, **kwargs)
-        if uid: return self.call("sudo", "-u", "#" + uid, *args, **kwargs)
+        if util.get_operator_name():
+            # This might be generalized as "preserve some environment"
+            args.insert(0, "SSH_GSSAPI_NAME=" + util.get_operator_name())
+        if uid: return self.call("sudo", "-u", "#" + str(uid), *args, **kwargs)
         if user: return self.call("sudo", "-u", user, *args, **kwargs)
 
 class ParallelShell(Shell):
@@ -121,3 +110,19 @@ class DummyParallelShell(ParallelShell):
     def __init__(self, dry = False):
         super(DummyParallelShell, self).__init__(dry=dry, max=1)
 
+class CallError(_wizard.Error):
+    def __init__(self, code, args, stdout, stderr):
+        self.code = code
+        self.args = args
+        self.stdout = stdout
+        self.stderr = stderr
+    def __str__(self):
+        return "CallError [%d]" % self.code
+
+class PythonCallError(CallError):
+    def __init__(self, code, args, stdout, stderr):
+        self.name = util.get_exception_name(stderr)
+        CallError.__init__(self, code, args, stdout, stderr)
+    def __str__(self):
+        return "PythonCallError [%s]" % self.name
+