comparison cmd2.py @ 31:5e2f6ec2e383

load so close!
author devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil
date Fri, 21 Dec 2007 15:06:13 -0500
parents 2739250177ed
children ebefe2d57e3b
comparison
equal deleted inserted replaced
30:2739250177ed 31:5e2f6ec2e383
10 still to do: 10 still to do:
11 edit 11 edit
12 run 12 run
13 > 13 >
14 """ 14 """
15 import cmd, re, os 15 import cmd, re, os, sys
16 16
17 class Cmd(cmd.Cmd): 17 class Cmd(cmd.Cmd):
18 caseInsensitive = True 18 caseInsensitive = True
19 multilineCommands = [] 19 multilineCommands = []
20 continuationPrompt = '> ' 20 continuationPrompt = '> '
21 shortcuts = {'?': 'help', '!': 'shell', '@': 'load'} 21 shortcuts = {'?': 'help', '!': 'shell', '@': 'load'}
22 excludeFromHistory = '''run r list l history hi ed li eof'''.split() 22 excludeFromHistory = '''run r list l history hi ed li eof'''.split()
23 defaultExtension = 'txt' 23 defaultExtension = 'txt'
24 defaultFileName = 'command.txt' 24 defaultFileName = 'command.txt'
25 editor = os.environ.get('EDITOR') or '' 25 editor = os.environ.get('EDITOR')
26 if not editor:
27 if sys.platform[:3] == 'win':
28 editor = 'notepad'
26 settable = ['prompt', 'continuationPrompt', 'defaultFileName', 'editor', 'caseInsensitive'] 29 settable = ['prompt', 'continuationPrompt', 'defaultFileName', 'editor', 'caseInsensitive']
27 terminators = ';\n' 30 terminators = ';\n'
28 def do_cmdenvironment(self, args): 31 def do_cmdenvironment(self, args):
29 self.stdout.write(""" 32 self.stdout.write("""
30 Commands are %(casesensitive)scase-sensitive. 33 Commands are %(casesensitive)scase-sensitive.
199 'ed [N]: brings up SQL from N commands ago in text editor, and puts result in SQL buffer.' 202 'ed [N]: brings up SQL from N commands ago in text editor, and puts result in SQL buffer.'
200 if not self.editor: 203 if not self.editor:
201 print "please use 'set editor' to specify your text editing program of choice." 204 print "please use 'set editor' to specify your text editing program of choice."
202 return 205 return
203 buffer = self.last_matching(arg) 206 buffer = self.last_matching(arg)
204 if not buffer:
205 print 'Nothing appropriate in buffer to edit.'
206 return
207 f = open(self.defaultFileName, 'w') 207 f = open(self.defaultFileName, 'w')
208 f.write(buffer) 208 f.write(buffer or '')
209 f.close() 209 f.close()
210 os.system('%s %s' % (self.editor, self.defaultFileName)) 210 os.system('%s %s' % (self.editor, self.defaultFileName))
211 self.do_load(self.defaultFileName) 211 self.do_load(self.defaultFileName)
212 do_edit = do_ed 212 do_edit = do_ed
213 213