Mercurial > python-cmd2
comparison cmd2.py @ 71:ea1697be3d00
getting suffix
author | catherine@Elli.myhome.westell.com |
---|---|
date | Wed, 25 Jun 2008 12:32:21 -0400 |
parents | 48b0bf2e3d2e |
children | 6031a06bb6d7 |
comparison
equal
deleted
inserted
replaced
70:48b0bf2e3d2e | 71:ea1697be3d00 |
---|---|
233 command = command.lower() | 233 command = command.lower() |
234 return command, args | 234 return command, args |
235 | 235 |
236 def completedStatement(self, firstline): | 236 def completedStatement(self, firstline): |
237 statement = firstline | 237 statement = firstline |
238 while not self.commmand_terminator_finder(statement): | 238 termination_found = self.commmand_terminator_finder(statement) |
239 while not termination_found: | |
239 inp = self.pseudo_raw_input(self.continuationPrompt) | 240 inp = self.pseudo_raw_input(self.continuationPrompt) |
240 statement = '%s\n%s' % (statement, inp) | 241 statement = '%s\n%s' % (statement, inp) |
241 return statement | 242 termination_found = self.commmand_terminator_finder(statement) |
243 return termination_found[0], termination_found[-1] | |
242 # assembling a list of lines and joining them at the end would be faster, | 244 # assembling a list of lines and joining them at the end would be faster, |
243 # but statementHasEnded needs a string arg; anyway, we're getting | 245 # but statementHasEnded needs a string arg; anyway, we're getting |
244 # user input and users are slow. | 246 # user input and users are slow. |
245 | 247 |
246 def onecmd(self, line, assumeComplete=False): | 248 def onecmd(self, line, assumeComplete=False): |
253 commands by the interpreter should stop. | 255 commands by the interpreter should stop. |
254 | 256 |
255 """ | 257 """ |
256 command, args = self.extractCommand(line) | 258 command, args = self.extractCommand(line) |
257 statement = originalStatement = ' '.join([command, args]) | 259 statement = originalStatement = ' '.join([command, args]) |
260 suffix = statement | |
258 if (not assumeComplete) and (command in self.multilineCommands): | 261 if (not assumeComplete) and (command in self.multilineCommands): |
259 statement = self.completedStatement(statement) | 262 statement, suffix = self.completedStatement(statement) |
260 statekeeper = None | 263 statekeeper = None |
261 stop = 0 | 264 stop = 0 |
262 | 265 |
263 inputFrom = self.input_source_finder(statement) | 266 inputFrom = self.input_source_finder(suffix) |
264 if inputFrom: | 267 if inputFrom: |
265 statement, source = inputFrom[0], inputFrom[-1] | 268 statement, source = inputFrom[0], inputFrom[-1] |
266 if source: | 269 if source: |
267 statement = '%s %s' % (statement, self.fileimport(statement=statement, source=source)) | 270 statement = '%s %s' % (statement, self.fileimport(statement=statement, source=source)) |
268 else: | 271 else: |
269 statement = '%s %s' % (statement, getPasteBuffer()) | 272 statement = '%s %s' % (statement, getPasteBuffer()) |
270 | 273 |
271 pipeTo = self.pipe_destination_finder(statement) | 274 pipeTo = self.pipe_destination_finder(suffix) |
272 if pipeTo: | 275 if pipeTo: |
273 statement, pipeTo = pipeTo[0], pipeTo[-1] | 276 statement, pipeTo = pipeTo[0], pipeTo[-1] |
274 statekeeper = Statekeeper(self, ('stdout',)) | 277 statekeeper = Statekeeper(self, ('stdout',)) |
275 pipeTo = subprocess.Popen(pipeTo, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE) | 278 pipeTo = subprocess.Popen(pipeTo, shell=True, stdout=subprocess.PIPE, stdin=subprocess.PIPE) |
276 self.stdout = pipeTo.stdin | 279 self.stdout = pipeTo.stdin |
277 else: # can't pipe output AND send it to a file | 280 else: # can't pipe output AND send it to a file |
278 outputTo = self.output_destination_finder(statement) | 281 outputTo = self.output_destination_finder(suffix) |
279 if outputTo: | 282 if outputTo: |
280 statement, destination = outputTo[0], outputTo[-1] | 283 statement, destination = outputTo[0], outputTo[-1] |
281 statekeeper = Statekeeper(self, ('stdout',)) | 284 statekeeper = Statekeeper(self, ('stdout',)) |
282 mode = ((outputTo[1][0] == '>>') and 'a') or 'w' | 285 mode = ((outputTo[1][0] == '>>') and 'a') or 'w' |
283 if destination: | 286 if destination: |