changeset 218:397979c7f6d6

dumping working but not for wildcards
author catherine@Elli.myhome.westell.com
date Thu, 29 Jan 2009 14:45:56 -0500
parents a65b98938596
children a5bd42b00565
files sqlpython/sqlpyPlus.py
diffstat 1 files changed, 16 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- 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'},