changeset 30:2739250177ed

load fixed?
author devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil
date Fri, 21 Dec 2007 14:00:11 -0500
parents a6f68b25ae16
children 5e2f6ec2e383
files cmd2.py testcmd.py
diffstat 2 files changed, 25 insertions(+), 24 deletions(-) [+]
line wrap: on
line diff
--- a/cmd2.py	Fri Dec 21 10:04:26 2007 -0500
+++ b/cmd2.py	Fri Dec 21 14:00:11 2007 -0500
@@ -9,6 +9,7 @@
 
 still to do:
 edit
+run
 >
 """
 import cmd, re, os
@@ -22,7 +23,7 @@
     defaultExtension = 'txt'
     defaultFileName = 'command.txt'
     editor = os.environ.get('EDITOR') or ''
-    settable = ['prompt', 'continuationPrompt', 'defaultFileName', 'editor']
+    settable = ['prompt', 'continuationPrompt', 'defaultFileName', 'editor', 'caseInsensitive']
     terminators = ';\n'
     def do_cmdenvironment(self, args):
 	self.stdout.write("""
@@ -68,7 +69,8 @@
     def finishStatement(self, firstline):
 	statement = firstline
 	while not self.statementHasEnded(statement):
-	    statement = '%s\n%s' % (statement, self.pseudo_raw_input(self.continuationPrompt))
+	    inp = self.pseudo_raw_input(self.continuationPrompt)
+	    statement = '%s\n%s' % (statement, inp)
 	return statement
 	# assembling a list of lines and joining them at the end would be faster, 
 	# but statementHasEnded needs a string arg; anyway, we're getting
@@ -96,7 +98,7 @@
 	return True
     do_eof = do_EOF
     
-    statementEndPattern = re.compile(r'[%s]\s*$' % terminators)	
+    statementEndPattern = re.compile(r'([%s]\s*)|(EOF)$' % terminators)	
     def statementHasEnded(self, lines):
 	return bool(self.statementEndPattern.search(lines))
 	       
@@ -147,7 +149,7 @@
 	    val = cast(currentVal, val.strip(self.terminators))
 	    setattr(self, paramName, val)
 	    self.stdout.write('%s - was: %s\nnow: %s\n' % (paramName, currentVal, val))
-        except (ValueError, AttributeError, NotSettableError):
+        except (ValueError, AttributeError, NotSettableError), e:
             self.do_show(arg)
 		
     def do_shell(self, arg):
@@ -196,7 +198,7 @@
     def do_ed(self, arg):
         'ed [N]: brings up SQL from N commands ago in text editor, and puts result in SQL buffer.'
 	if not self.editor:
-	    self.do_show('editor')
+	    print "please use 'set editor' to specify your text editing program of choice."
 	    return
         buffer = self.last_matching(arg)
         if not buffer:
@@ -206,7 +208,7 @@
         f.write(buffer)
         f.close()
 	os.system('%s %s' % (self.editor, self.defaultFileName))
-        self.load(self.defaultFileName)
+        self.do_load(self.defaultFileName)
     do_edit = do_ed
     
     def do_save(self, fname=None):
@@ -283,31 +285,31 @@
             return [itm for itm in self if isin(itm)]
 
 class NotSettableError(Exception):
-    None    
+    pass
 	
 def cast(current, new):
     """Tries to force a new value into the same type as the current."""
     typ = type(current)
-    print type(new)
     if typ == bool:
-	new = new.lower()    
-	print new
+	try:
+	    return bool(int(new))
+	except ValueError, TypeError:
+	    pass
 	try:
-	    print new == 'on'
-	    if (new=='on') or (new[0] in ('y','t')):
-		return True
-	    try:
-		return bool(int(new))
-	    except ValueError:
-		pass
+	    new = new.lower()    
+	except:
+	    pass
+	if (new=='on') or (new[0] in ('y','t')):
+	    return True
+	if (new=='off') or (new[0] in ('n','f')):
 	    return False
-	except TypeError:
+    else:
+	try:
+	    return typ(new)
+	except:
 	    pass
-    try:
-	return typ(new)
-    except:
-	print "Problem setting parameter (now %s) to %s; incorrect type?" % (current, new)
-	return current
+    print "Problem setting parameter (now %s) to %s; incorrect type?" % (current, new)
+    return current
 	
 class Statekeeper(object):
     def __init__(self, obj, attribs):
--- a/testcmd.py	Fri Dec 21 10:04:26 2007 -0500
+++ b/testcmd.py	Fri Dec 21 14:00:11 2007 -0500
@@ -2,7 +2,6 @@
 
 class test(cmd2.Cmd):
     binarypar = True
-    settable = ['prompt', 'binarypar']
     def do_sing(self, arg):
         '''Sings.