# HG changeset patch # User catherine@Elli.myhome.westell.com # Date 1233258356 18000 # Node ID 397979c7f6d663ba03c07a40ef806a5bd4e9b0a6 # Parent a65b98938596eea2529b17f1ba8a25f98702568a dumping working but not for wildcards diff -r a65b98938596 -r 397979c7f6d6 sqlpython/sqlpyPlus.py --- a/sqlpython/sqlpyPlus.py Thu Jan 29 12:53:13 2009 -0500 +++ b/sqlpython/sqlpyPlus.py Thu Jan 29 14:45:56 2009 -0500 @@ -539,13 +539,23 @@ terminator = arg.parsed.terminator or ';', suffix = arg.parsed.suffix)) - @options([make_option('-f', '--full', action='store_true', help='get dependent objects as well'), + @options([make_option('-d', '--dump', action='store_true', help='dump results to files'), + make_option('-f', '--full', action='store_true', help='get dependent objects as well'), make_option('-a', '--all', action='store_true', help="all schemas' objects"), - make_option('-x', '--exact', action='store_true', default=False, help="match object name exactly")]) + make_option('-x', '--exact', action='store_true', help="match object name exactly")]) def do_pull(self, arg, opts): """Displays source code.""" + if opts.dump: + statekeeper = Statekeeper(self, ('stdout',)) for (owner, object_type, object_name) in self.resolve_many(arg, opts): + if opts.dump: + try: + os.makedirs(os.path.join(owner.lower(), object_type.lower().replace(' ','_'))) + except OSError: + pass + self.stdout = open(os.path.join(owner.lower(), object_type.lower().replace(' ','_'), '%s.sql' % object_name.lower()), 'w') + self.stdout.write(str(self.curs.callfunc('DBMS_METADATA.GET_DDL', cx_Oracle.CLOB, [object_type, object_name, owner]))) if opts.full: @@ -555,6 +565,10 @@ [dependent_type, object_name, owner]))) except cx_Oracle.DatabaseError: pass + if opts.dump: + self.stdout.close() + if opts.dump: + statekeeper.restore() all_users_option = make_option('-a', action='store_const', dest="scope", default={'col':'', 'view':'user', 'schemas':'user'},