Mercurial > sqlpython
changeset 451:fd86d22fe00d
mostly compatible with cmd2 0.6 - minor transcript test problem
author | catherine@Drou |
---|---|
date | Mon, 15 Feb 2010 17:44:56 -0500 |
parents | abf71d72f467 |
children | f87f804aab3b |
files | setup.py sqlpython/exampleSession.txt sqlpython/mysqlpy.py sqlpython/sqlpyPlus.py sqlpython/sqlpython.py |
diffstat | 5 files changed, 44 insertions(+), 58 deletions(-) [+] |
line wrap: on
line diff
--- a/setup.py Thu Feb 11 16:07:34 2010 -0500 +++ b/setup.py Mon Feb 15 17:44:56 2010 -0500 @@ -17,7 +17,7 @@ url="http://packages.python.org/sqlpython", packages=find_packages(), include_package_data=True, - install_requires=['pyparsing','cmd2>=0.6.0','gerald>=0.3.5', + install_requires=['pyparsing','cmd2>=0.6.0','gerald>=0.3.6', 'genshi>=0.5'], extras_require = { 'oracle': ['cx_Oracle>=5.0.2'],
--- a/sqlpython/exampleSession.txt Thu Feb 11 16:07:34 2010 -0500 +++ b/sqlpython/exampleSession.txt Mon Feb 15 17:44:56 2010 -0500 @@ -4,10 +4,6 @@ user testschema, password testschema, with the RESOURCE privilege (`GRANT RESOURCE TO testschema`). -SQL.No_Connection> set color off -colors - was: True -now: False - SQL.No_Connection> connect testschema/testschema@orcl 0:testschema@orcl> drop table play; /.*/
--- a/sqlpython/mysqlpy.py Thu Feb 11 16:07:34 2010 -0500 +++ b/sqlpython/mysqlpy.py Mon Feb 15 17:44:56 2010 -0500 @@ -102,7 +102,6 @@ def do_longops(self,args): '''Runs query_longops defined above, to display long running operations (full scans, etc)''' - import pdb; pdb.set_trace() self.onecmd(self.query_longops) def do_load(self,args): @@ -185,39 +184,7 @@ def run(): my=mysqlpy() - print my.__doc__ - # split a complex argument string, like - # ``--postgres -H localhost dbname username ls "select * from tbl" @myscript`` - # into a portion to feed to ``do_connect`` and a portion to run as SQL commands - connectstring = sys.argv[1:] - commands = [] - for (n, arg) in enumerate(sys.argv[1:]): - if arg.startswith('@') or len(arg.split()) > 1: - connectstring = sys.argv[1:n+1] - commands = sys.argv[n+1:] - break - if connectstring: - my.onecmd('connect %s' % ' '.join(connectstring)) - for command in commands: - if my.onecmd(command + '\n') == my._STOP_AND_EXIT: - return my.cmdloop() -class TestCase(Cmd2TestCase): - CmdApp = mysqlpy - if __name__ == '__main__': - testfiles = sys.argv[1:] - for arg in ('-t', '--test'): - if arg in testfiles: - testfiles.remove(arg) - sys.argv.remove(arg) - mysqlpy.testfiles = testfiles - if not testfiles: - print 'No test file specified to run against!' - sys.exit() - if hasattr(mysqlpy, 'testfiles'): - sys.argv = [sys.argv[0]] # the --test argument upsets unittest.main() - unittest.main() - else: - run() \ No newline at end of file + run() \ No newline at end of file
--- a/sqlpython/sqlpyPlus.py Thu Feb 11 16:07:34 2010 -0500 +++ b/sqlpython/sqlpyPlus.py Mon Feb 15 17:44:56 2010 -0500 @@ -375,7 +375,8 @@ def __init__(self): sqlpython.sqlpython.__init__(self) self.binds = CaselessDict() - self.settable.pop('case_insensitive') + if self.settable.has_key('case_insensitive'): + self.settable.pop('case_insensitive') self.stdoutBeforeSpool = sys.stdout self.sql_echo = False self.spoolFile = None @@ -1355,7 +1356,6 @@ (False, 'foo', None) ''' arg = self.parsed(arg) - import pdb; pdb.set_trace() try: var, val = self.assignmentSplitter.split(arg, maxsplit=1) except ValueError: @@ -1624,6 +1624,32 @@ # TODO: needs much polish return self.do__dir_constraints(arg) + def run_commands_at_invocation(self, callargs): + connection_args = [] + while True: + try: + arg = callargs.pop(0) + connection_args.append(arg) + if ';' in arg: + break + except IndexError: + break + if connection_args: + self.do_connect(' '.join(connection_args)) + sqlpython.sqlpython.run_commands_at_invocation(self, callargs) + for arg in callargs: + connection_args.append(callargs.pop()) + for initial_command in callargs: + if self.onecmd(initial_command + '\n') == app._STOP_AND_EXIT: + return + + def cmdloop(self): + if sys.argv[1] in ('--test', '-t'): + self.runTranscriptTests(sys.argv[2:]) + else: + self.run_commands_at_invocation(sys.argv[1:]) + self._cmdloop() + def _test(): import doctest doctest.testmod()
--- a/sqlpython/sqlpython.py Thu Feb 11 16:07:34 2010 -0500 +++ b/sqlpython/sqlpython.py Mon Feb 15 17:44:56 2010 -0500 @@ -109,29 +109,26 @@ if (self.rdbms == 'oracle') and self.serveroutput: self.curs.callproc('dbms_output.enable', []) return True - - @cmd2.options([cmd2.make_option('-a', '--add', action='store_true', + + @cmd2.options([cmd2.make_option('-a', '--add', action='store_true', help='add connection (keep current connection)'), - cmd2.make_option('-c', '--close', action='store_true', + cmd2.make_option('-c', '--close', action='store_true', help='close connection {N} (or current)'), - cmd2.make_option('-C', '--closeall', action='store_true', + cmd2.make_option('-C', '--closeall', action='store_true', help='close all connections'), cmd2.make_option('--postgres', action='store_true', help='Connect to postgreSQL: `sqlpython --postgres [DBNAME [USERNAME]]`'), cmd2.make_option('--oracle', action='store_true', help='Connect to an Oracle database'), - cmd2.make_option('--mysql', action='store_true', help='Connect to a MySQL database'), - cmd2.make_option('-H', '--hostname', type='string', - help='Machine where database is hosted'), - cmd2.make_option('-p', '--port', type='int', - help='Port to connect to'), - cmd2.make_option('--password', type='string', - help='Password'), - cmd2.make_option('-d', '--database', type='string', + cmd2.make_option('--mysql', action='store_true', help='Connect to a MySQL database'), + cmd2.make_option('-H', '--hostname', type='string', + help='Machine where database is hosted'), + cmd2.make_option('-p', '--port', type='int', + help='Port to connect to'), + cmd2.make_option('--password', type='string', + help='Password'), + cmd2.make_option('-d', '--database', type='string', help='Database name to connect to'), - cmd2.make_option('-U', '--username', type='string', - help='Database user name to connect as'), -# cmd2.make_option('-u', '--user', type='string', -# help='Database user name to connect as') - ]) + cmd2.make_option('-U', '--username', type='string', + help='Database user name to connect as')]) def do_connect(self, arg, opts): '''Opens the DB connection'''