changeset 288:e7578e7ff9dd

sliced pull almost working...
author catherine@dellzilla
date Fri, 20 Mar 2009 17:23:54 -0400
parents 3ce9a48aa3fc
children 67ff100baeaa
files docs/source/comparison.rst docs/source/limitations.rst sqlpython/sqlpyPlus.py
diffstat 3 files changed, 32 insertions(+), 8 deletions(-) [+]
line wrap: on
line diff
--- a/docs/source/comparison.rst	Fri Mar 20 13:16:26 2009 -0400
+++ b/docs/source/comparison.rst	Fri Mar 20 17:23:54 2009 -0400
@@ -653,11 +653,11 @@
 When compiling PL/SQL objects (functions, packages, procedures) that contain errors, 
 the tools vary in the quality of information they return.
  
-  * Senora reports that a compilation error has occured, and `show errors` works as expected.
+* Senora reports that a compilation error has occured, and `show errors` works as expected.
       
-  * YASQL reports that a compilation error has occured.  `show errors` in YASQL lists the compilation errors for *all* invalid PL/SQL objects in the schema.
+* YASQL reports that a compilation error has occured.  `show errors` in YASQL lists the compilation errors for *all* invalid PL/SQL objects in the schema.
   
-  * sqlpython reports errors immediately upon compilation.
+* sqlpython reports errors immediately upon compilation.
       
 Note that, in senora and YASQL, abbreviated forms of `show errors`, like `sho err`, are not recognized.
 
@@ -831,13 +831,13 @@
 optional arguments will be assigned to `arg`, but in this case they are not used.
 Let's see a more useful function, one that will
 
-  * Make use of the argument string
+* Make use of the argument string
   
-  * Provide online documentation
+* Provide online documentation
   
-  * Use a flag to optionally modify the command's behavior
+* Use a flag to optionally modify the command's behavior
   
-  * Send output to file, paste buffer, or pipe when `>` or `|` is used.
+* Send output to file, paste buffer, or pipe when `>` or `|` is used.
   
 ::
 
--- a/docs/source/limitations.rst	Fri Mar 20 13:16:26 2009 -0400
+++ b/docs/source/limitations.rst	Fri Mar 20 17:23:54 2009 -0400
@@ -33,3 +33,4 @@
 
 * SET FEEDBACK OFF
 
+* SET AUTOTRACE ON
\ No newline at end of file
--- a/sqlpython/sqlpyPlus.py	Fri Mar 20 13:16:26 2009 -0400
+++ b/sqlpython/sqlpyPlus.py	Fri Mar 20 17:23:54 2009 -0400
@@ -397,6 +397,16 @@
             self.resultset.pystate['binds'][colname] = self[idx]
             self.resultset.pystate['binds'][str(idx+1)] = self[idx]
               
+def centeredSlice(lst, center=0, width=1):
+    width = max(width, -1)
+    if center < 0:
+        end = center + width + 1
+        if end >= 0:
+            end = None
+        return lst[center-width:end]
+    else:
+        return lst[max(center-width,0):center+width+1] 
+    
 class sqlpyPlus(sqlpython.sqlpython):
     defaultExtension = 'sql'
     sqlpython.sqlpython.shortcuts.update({':': 'setbind', 
@@ -831,7 +841,16 @@
                         ddl = [[object_type, object_name, owner]]
                     for ddlargs in ddl:
                         try:
-                            self.stdout.write('REMARK BEGIN %s\n%s\nREMARK END\n\n' % (object_name, str(self.curs.callfunc('DBMS_METADATA.GET_DDL', cx_Oracle.CLOB, ddlargs))))
+                            code = str(self.curs.callfunc('DBMS_METADATA.GET_DDL', cx_Oracle.CLOB, ddlargs))
+                            if opts.lines:
+                                code = code.splitlines()
+                                template = "%%-%dd:%%s" % len(str(len(code)))
+                                code = '\n'.join(template % (n+1, line) for (n, line) in enumerate(code))
+                            if opts.num is not None:
+                                code = code.splitlines()
+                                code = centeredSlice(code, center=opts.num+1, width=opts.width)
+                                code = '\n'.join(code)
+                            self.stdout.write('REMARK BEGIN %s\n%s\nREMARK END\n\n' % (object_name, code))
                         except cx_Oracle.DatabaseError, errmsg:
                             if object_type == 'JOB':
                                 print '%s: DBMS_METADATA.GET_DDL does not support JOBs (MetaLink DocID 567504.1)' % object_name
@@ -890,6 +909,10 @@
             
     @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('-l', '--lines', action='store_true', help='print line numbers'),
+              make_option('-n', '--num', type='int', help='only code near line #num'),
+              make_option('-w', '--width', type='int', default=5, 
+                          help='# of lines before and after --lineNo'),              
               make_option('-a', '--all', action='store_true', help="all schemas' objects"),
               make_option('-x', '--exact', action='store_true', help="match object name exactly")])
     def do_pull(self, arg, opts):