comparison cmd2.py @ 73:101283b63e1b

hmm, getting hard to split search/do not search
author catherine@Elli.myhome.westell.com
date Wed, 25 Jun 2008 17:09:59 -0400
parents 6031a06bb6d7
children 4e290d75e92e
comparison
equal deleted inserted replaced
72:6031a06bb6d7 73:101283b63e1b
253 see the precmd() and postcmd() methods for useful execution hooks. 253 see the precmd() and postcmd() methods for useful execution hooks.
254 The return value is a flag indicating whether interpretation of 254 The return value is a flag indicating whether interpretation of
255 commands by the interpreter should stop. 255 commands by the interpreter should stop.
256 256
257 """ 257 """
258 statekeeper = None
259 stop = 0
258 command, args = self.extractCommand(line) 260 command, args = self.extractCommand(line)
259 statement = originalStatement = ' '.join([command, args]) 261 statement = originalStatement = ' '.join([command, args])
260 suffix = statement
261 if (not assumeComplete) and (command in self.multilineCommands): 262 if (not assumeComplete) and (command in self.multilineCommands):
262 statement, suffix = self.completedStatement(statement) 263 statement, afterTerminator = self.completedStatement(statement)
263 statekeeper = None 264 inputFrom = self.input_source_finder(afterTerminator)
264 stop = 0 265 if inputFrom:
265 266 statement = "%s %s" % (statement, inputFrom[0])
266 inputFrom = self.input_source_finder(suffix) 267 else:
268 inputFrom = self.input_source_finder(statement)
269 if inputFrom:
270 statement = inputFrom[0]
271
267 if inputFrom: 272 if inputFrom:
268 source = inputFrom[-1] 273 source = inputFrom[-1]
269 if source: 274 if source:
270 statement = '%s %s' % (statement, self.fileimport(statement=statement, source=source)) 275 statement = '%s %s' % (statement, self.fileimport(source=source))
271 else: 276 else:
272 statement = '%s %s' % (statement, getPasteBuffer()) 277 statement = '%sy %s' % (statement, getPasteBuffer())
273 278
274 pipeTo = self.pipe_destination_finder(suffix) 279 pipeTo = self.pipe_destination_finder(afterTerminator)
275 if pipeTo: 280 if pipeTo:
276 pipeTo = pipeTo[-1] 281 pipeTo = pipeTo[-1]
277 statekeeper = Statekeeper(self, ('stdout',)) 282 statekeeper = Statekeeper(self, ('stdout',))
278 pipeTo = subprocess.Popen(pipeTo, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE) 283 pipeTo = subprocess.Popen(pipeTo, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE)
279 self.stdout = pipeTo.stdin 284 self.stdout = pipeTo.stdin
280 else: # can't pipe output AND send it to a file 285 else: # can't pipe output AND send it to a file
281 outputTo = self.output_destination_finder(suffix) 286 outputTo = self.output_destination_finder(afterTerminator)
282 if outputTo: 287 if outputTo:
283 destination = outputTo[-1] 288 destination = outputTo[-1]
284 statekeeper = Statekeeper(self, ('stdout',)) 289 statekeeper = Statekeeper(self, ('stdout',))
285 mode = ((outputTo[1][0] == '>>') and 'a') or 'w' 290 mode = ((outputTo[1][0] == '>>') and 'a') or 'w'
286 if destination: 291 if destination:
556 runme = self.precmd(runme) 561 runme = self.precmd(runme)
557 stop = self.onecmd(runme) 562 stop = self.onecmd(runme)
558 stop = self.postcmd(stop, runme) 563 stop = self.postcmd(stop, runme)
559 do_r = do_run 564 do_r = do_run
560 565
561 def fileimport(self, statement, source): 566 def fileimport(self, source):
562 try: 567 try:
563 f = open(source) 568 f = open(source)
564 except IOError: 569 except IOError:
565 self.stdout.write("Couldn't read from file %s\n" % source) 570 self.stdout.write("Couldn't read from file %s\n" % source)
566 return '' 571 return ''