[Author Prev][Author Next][Thread Prev][Thread Next][Author Index][Thread Index]

[minion-cvs] Make "mixminion shell" more bulletproof, and more like ...



Update of /home/minion/cvsroot/src/minion/lib/mixminion
In directory moria.mit.edu:/tmp/cvs-serv654/lib/mixminion

Modified Files:
	Main.py 
Log Message:
Make "mixminion shell" more bulletproof, and more like a real shell

Index: Main.py
===================================================================
RCS file: /home/minion/cvsroot/src/minion/lib/mixminion/Main.py,v
retrieving revision 1.68
retrieving revision 1.69
diff -u -d -r1.68 -r1.69
--- Main.py	21 Feb 2004 00:02:09 -0000	1.68
+++ Main.py	1 Mar 2004 07:02:06 -0000	1.69
@@ -221,6 +221,14 @@
     print "NOTE: This software is for testing only.  The user set is too small"
     print "      to be anonymous, and the code is too alpha to be reliable."
 
+def fixCommandToken(tok):
+    if not tok:
+        return tok
+    elif len(tok) >=2 and tok[0] in ['"', "'"] and tok[-1] == tok[0]:
+        return tok[1:-1]
+    else:
+        return tok
+
 def commandShell(cmd,args):
     # Used to implement a 'mixminion shell' on systems (like windows) with
     # somewhat bogus CLI support.
@@ -231,8 +239,15 @@
         print "Syntax: mixminion shell [options]"
         sys.exit(0)
 
+    if "--debug-shlex" in args:
+        debug = 1
+    else:
+        debug = 0
+
     print "Mixminion version %s" % mixminion.__version__
-    print "Type 'help' for information, and 'exit' to quit."
+    print "Type 'help' for information, or 'exit' to quit."
+
+    uiErrorClass = getUIError()
 
     lexer = shlex.shlex()
     lexer.whitespace = " \t"
@@ -244,11 +259,14 @@
         while 1:
             word = lexer.get_token()
             if word not in ['\r','\n']:
-                words.append(word)
+                words.append(fixCommandToken(word))
             else:
                 break
         if not words:
+            print "Type 'help' for information, or 'exit' to quit."
             continue
+        if debug:
+            print words; continue
         command = words[0]
         args = words[1:]
         if command == 'exit' or command == 'quit':
@@ -258,6 +276,15 @@
             main([sys.argv[0]]+words)
         except SystemExit:
             pass
+        except uiErrorClass, e:
+            e.dump()
+        except KeyboardInterrupt, e:
+            print "Interrupted."
+
+def getUIError():
+    """DOCDOC"""
+    commonModule = __import__('mixminion.Common', {}, {}, ['UIError'])
+    return commonModule.UIError
 
 def main(args,daemon=0):
     "Use <args> to fix path, pick a command and pass it arguments."
@@ -286,8 +313,8 @@
 
     # Read the 'common' module to get the UIError class.  To simplify
     # command implementation code, we catch all UIError exceptions here.
+    uiErrorClass = getUIError()
     commonModule = __import__('mixminion.Common', {}, {}, ['UIError'])
-    uiErrorClass = commonModule.UIError
     filePermissionErrorClass = commonModule.MixFilePermissionError
 
     # Read the module and function.