Mercurial > python-cmd2
comparison cmd2.py @ 47:927bc07467de
fixed misfind of editor
author | catherine@cordelia |
---|---|
date | Tue, 03 Jun 2008 15:04:40 -0400 |
parents | 27b45b33a574 |
children | 34fb41095451 |
comparison
equal
deleted
inserted
replaced
46:27b45b33a574 | 47:927bc07467de |
---|---|
127 class Cmd(cmd.Cmd): | 127 class Cmd(cmd.Cmd): |
128 caseInsensitive = True | 128 caseInsensitive = True |
129 multilineCommands = [] | 129 multilineCommands = [] |
130 continuationPrompt = '> ' | 130 continuationPrompt = '> ' |
131 shortcuts = {'?': 'help', '!': 'shell', '@': 'load'} | 131 shortcuts = {'?': 'help', '!': 'shell', '@': 'load'} |
132 excludeFromHistory = '''run r list l history hi ed li eof'''.split() | 132 excludeFromHistory = '''run r list l history hi ed edit li eof'''.split() |
133 defaultExtension = 'txt' | 133 defaultExtension = 'txt' |
134 defaultFileName = 'command.txt' | 134 defaultFileName = 'command.txt' |
135 editor = os.environ.get('EDITOR') | 135 editor = os.environ.get('EDITOR') |
136 _STOP_AND_EXIT = 2 | 136 _STOP_AND_EXIT = 2 |
137 if not editor: | 137 if not editor: |
138 if sys.platform[:3] == 'win': | 138 if sys.platform[:3] == 'win': |
139 editor = 'notepad' | 139 editor = 'notepad' |
140 else: | 140 else: |
141 for editor in ['gedit', 'kate', 'vim', 'emacs', 'nano', 'pico']: | 141 for editor in ['gedit', 'kate', 'vim', 'emacs', 'nano', 'pico']: |
142 if os.system('which %s' % (editor)): | 142 if not os.system('which %s' % (editor)): |
143 break | 143 break |
144 | 144 |
145 settable = ['prompt', 'continuationPrompt', 'defaultFileName', 'editor', 'caseInsensitive'] | 145 settable = ['prompt', 'continuationPrompt', 'defaultFileName', 'editor', 'caseInsensitive'] |
146 terminators = ';\n' | 146 terminators = ';\n' |
147 _TO_PASTE_BUFFER = 1 | 147 _TO_PASTE_BUFFER = 1 |
178 notAPipe.ignore(pyparsing.sglQuotedString) | 178 notAPipe.ignore(pyparsing.sglQuotedString) |
179 notAPipe.ignore(pyparsing.dblQuotedString) | 179 notAPipe.ignore(pyparsing.dblQuotedString) |
180 pipeFinder = notAPipe + '|' + pyparsing.SkipTo(pyparsing.StringEnd()) | 180 pipeFinder = notAPipe + '|' + pyparsing.SkipTo(pyparsing.StringEnd()) |
181 def findPipe(self, statement): | 181 def findPipe(self, statement): |
182 try: | 182 try: |
183 statement, pipe, destination = pipeFinder.parseString(statement) | 183 statement, pipe, destination = self.pipeFinder.parseString(statement) |
184 return statement, destination | 184 return statement, destination |
185 except pyparsing.ParseException: | 185 except pyparsing.ParseException: |
186 return statement, None | 186 return statement, None |
187 | 187 |
188 legalFileName = re.compile(r'''^[^"'\s]+$''') | 188 legalFileName = re.compile(r'''^[^"'\s]+$''') |
237 statement = ' '.join([command, args]) | 237 statement = ' '.join([command, args]) |
238 if (not assumeComplete) and (command in self.multilineCommands): | 238 if (not assumeComplete) and (command in self.multilineCommands): |
239 statement = self.finishStatement(statement) | 239 statement = self.finishStatement(statement) |
240 statekeeper = None | 240 statekeeper = None |
241 stop = 0 | 241 stop = 0 |
242 statement, redirect = self.pipeFinder(statement) | 242 statement, redirect = self.findPipe(statement) |
243 if redirect: | 243 if redirect: |
244 statekeeper = Statekeeper(self, ('stdout',)) | |
244 redirect = subprocess.Popen(redirect, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE) | 245 redirect = subprocess.Popen(redirect, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE) |
245 redirect.stdin = self.stdout | 246 self.stdout = redirect.stdin |
246 stop = cmd.Cmd.onecmd(self, statement) | 247 stop = cmd.Cmd.onecmd(self, statement) |
248 statekeeper.restore() | |
247 self.stdout.write(redirect.stdout.read()) | 249 self.stdout.write(redirect.stdout.read()) |
248 return stop # didn't record in history | 250 return stop # didn't record in history |
249 else: | 251 else: |
250 statement, redirect, mode = self.parseRedirectors(statement) | 252 statement, redirect, mode = self.parseRedirectors(statement) |
251 if redirect == self._TO_PASTE_BUFFER: | 253 if redirect == self._TO_PASTE_BUFFER: |