changeset 217:a65b98938596

multi-pull working pretty well
author catherine@Elli.myhome.westell.com
date Thu, 29 Jan 2009 12:53:13 -0500
parents c5a49947eedc
children 397979c7f6d6
files sqlpython/sqlpyPlus.py
diffstat 1 files changed, 24 insertions(+), 20 deletions(-) [+]
line wrap: on
line diff
--- a/sqlpython/sqlpyPlus.py	Thu Jan 29 12:31:56 2009 -0500
+++ b/sqlpython/sqlpyPlus.py	Thu Jan 29 12:53:13 2009 -0500
@@ -539,24 +539,22 @@
                                           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('-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")])
     def do_pull(self, arg, opts):
         """Displays source code."""
 
-        target = arg.upper()
-        object_type, owner, object_name = self.resolve(target)
-        if not object_type:
-            return
-        #self.stdout.write("%s %s.%s\n" % (object_type, owner, object_name))
-        self.stdout.write(str(self.curs.callfunc('DBMS_METADATA.GET_DDL', cx_Oracle.CLOB,
-                                                 [object_type, object_name, owner])))
-        if opts.full:
-            for dependent_type in ('OBJECT_GRANT', 'CONSTRAINT', 'TRIGGER'):        
-                try:
-                    self.stdout.write(str(self.curs.callfunc('DBMS_METADATA.GET_DEPENDENT_DDL', cx_Oracle.CLOB,
-                                                             [dependent_type, object_name, owner])))
-                except cx_Oracle.DatabaseError:
-                    pass
+        for (owner, object_type, object_name) in self.resolve_many(arg, opts):        
+            self.stdout.write(str(self.curs.callfunc('DBMS_METADATA.GET_DDL', cx_Oracle.CLOB,
+                                                     [object_type, object_name, owner])))
+            if opts.full:
+                for dependent_type in ('OBJECT_GRANT', 'CONSTRAINT', 'TRIGGER'):        
+                    try:
+                        self.stdout.write(str(self.curs.callfunc('DBMS_METADATA.GET_DEPENDENT_DDL', cx_Oracle.CLOB,
+                                                                 [dependent_type, object_name, owner])))
+                    except cx_Oracle.DatabaseError:
+                        pass
 
     all_users_option = make_option('-a', action='store_const', dest="scope",
                                          default={'col':'', 'view':'user', 'schemas':'user'}, 
@@ -871,8 +869,13 @@
         
     def _ls_statement(self, arg, opts):
         if arg:
-            where = """\nWHERE object_type || '/' || object_name
-                  LIKE '%%%s%%'""" % (arg.upper().replace('*','%'))
+            target = arg.upper()
+            if opts.exact:
+                where = """\nWHERE object_name = '%s'
+                             OR object_type || '/' || object_name = '%s'""" % \
+                            (target, target)
+            else:
+                where = "\nWHERE object_type || '/' || object_name LIKE '%%%s%%'" % (arg.upper().replace('*','%'))
         else:
             where = ''
         if opts.all:
@@ -888,8 +891,8 @@
         return {'objname': objname, 'moreColumns': moreColumns,
                 'whose': whose, 'where': where}        
         
-    @options([make_option('-a', '--all', action='store_true', help="all schemas' objects")])
     def resolve_many(self, arg, opts):
+        opts.long = False
         clauses = self._ls_statement(arg, opts)
         if opts.all:
             clauses['owner'] = 'owner'
@@ -897,12 +900,13 @@
             clauses['owner'] = 'user'
         statement = '''SELECT %(owner)s, object_type, object_name 
                   FROM   %(whose)s_objects %(where)s
-                  ORDER BY object_type, object_name;''' % clauses
+                  ORDER BY object_type, object_name''' % clauses
         self.curs.execute(statement)
         return self.curs.fetchall()
     
     @options([make_option('-l', '--long', action='store_true', help='long descriptions'),
-              make_option('-a', '--all', action='store_true', help="all schemas' objects")])        
+              make_option('-a', '--all', action='store_true', help="all schemas' objects"),
+              make_option('-x', '--exact', action='store_true', default=False, help="match name exactly")])        
     def do_ls(self, arg, opts):
         statement = '''SELECT object_type || '/' || %(objname)s AS name %(moreColumns)s 
                   FROM   %(whose)s_objects %(where)s