Mercurial > sqlpython
comparison sqlpyPlus.py @ 20:d6d64c2e3b98
shortcuts
author | devlinjs@FA7CZA6N1254998.wrightpatterson.afmc.ds.af.mil |
---|---|
date | Wed, 19 Dec 2007 11:49:23 -0500 |
parents | 2776755a3a7e |
children | 8b55aaa52ce9 |
comparison
equal
deleted
inserted
replaced
19:25f22e742a68 | 20:d6d64c2e3b98 |
---|---|
363 def parseline(self, line): | 363 def parseline(self, line): |
364 """Parse the line into a command name and a string containing | 364 """Parse the line into a command name and a string containing |
365 the arguments. Returns a tuple containing (command, args, line). | 365 the arguments. Returns a tuple containing (command, args, line). |
366 'command' and 'args' may be None if the line couldn't be parsed. | 366 'command' and 'args' may be None if the line couldn't be parsed. |
367 Overrides cmd.cmd.parseline to accept variety of shortcuts..""" | 367 Overrides cmd.cmd.parseline to accept variety of shortcuts..""" |
368 line = line.strip() | 368 |
369 if not line: | 369 cmd, arg. line = sqlpython.parseline(self, line) |
370 return None, None, line | 370 if cmd in ('select', 'sleect', 'insert', 'update', 'delete', 'describe', |
371 shortcut = self.shortcuts.get(line[0]) | |
372 if shortcut: | |
373 cmd, arg = shortcut, line[1:].strip() | |
374 else: | |
375 i, n = 0, len(line) | |
376 while i < n and line[i] in self.identchars: i = i+1 | |
377 cmd, arg = line[:i], line[i:].strip() | |
378 if cmd.lower() in ('select', 'sleect', 'insert', 'update', 'delete', 'describe', | |
379 'desc', 'comments', 'pull', 'refs', 'desc', 'triggers', 'find') \ | 371 'desc', 'comments', 'pull', 'refs', 'desc', 'triggers', 'find') \ |
380 and not hasattr(self, 'curs'): | 372 and not hasattr(self, 'curs'): |
381 print 'Not connected.' | 373 print 'Not connected.' |
382 return '', '', '' | 374 return '', '', '' |
383 return cmd, arg, line | 375 return cmd, arg, line |
384 | 376 |
385 def precmd(self, line): | 377 def precmd(self, line): |
423 def do_shortcuts(self,arg): | 415 def do_shortcuts(self,arg): |
424 """Lists available first-character shortcuts | 416 """Lists available first-character shortcuts |
425 (i.e. '!dir' is equivalent to 'shell dir')""" | 417 (i.e. '!dir' is equivalent to 'shell dir')""" |
426 for (scchar, scto) in self.shortcuts.items(): | 418 for (scchar, scto) in self.shortcuts.items(): |
427 print '%s: %s' % (scchar, scto) | 419 print '%s: %s' % (scchar, scto) |
428 | |
429 | 420 |
430 def colnames(self): | 421 def colnames(self): |
431 return [d[0] for d in curs.description] | 422 return [d[0] for d in curs.description] |
432 | 423 |
433 def sql_format_itm(self, itm, needsquotes): | 424 def sql_format_itm(self, itm, needsquotes): |
687 return object_type, owner, object_name | 678 return object_type, owner, object_name |
688 | 679 |
689 def do_resolve(self, arg): | 680 def do_resolve(self, arg): |
690 print self.resolve(arg) | 681 print self.resolve(arg) |
691 | 682 |
692 def do_shell(self, arg): | |
693 'execute a command as if at the OS prompt.' | |
694 os.system(arg) | |
695 | |
696 def spoolstop(self): | 683 def spoolstop(self): |
697 if self.spoolFile: | 684 if self.spoolFile: |
698 sys.stdout = self.stdoutBeforeSpool | 685 sys.stdout = self.stdoutBeforeSpool |
699 print 'Finished spooling to ', self.spoolFile.name | 686 print 'Finished spooling to ', self.spoolFile.name |
700 self.spoolFile.close() | 687 self.spoolFile.close() |