Changeset 4519:c4c0660af381 in livinglogic.python.xist for src/ll/orasql/scripts/oracreate.py

Show
Ignore:
Timestamp:
07/14/11 13:06:40 (8 years ago)
Author:
Walter Doerwald <walter@…>
Branch:
default
Tags:
rel-3-22
Message:

Added options --include and --exclude to oracreate, oradrop and oragrant.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • src/ll/orasql/scripts/oracreate.py

    r4473 r4519  
    5656        The encoding of the output (if ``-x`` is not given; default is ``utf-8``). 
    5757 
     58    ``--include`` : regexp 
     59        Only include objects in the output if their name contains the regular 
     60        expression. 
     61 
     62    ``--exclude`` : regexp 
     63        Exclude objects from the output if their name contains the regular 
     64        expression. 
    5865 
    5966Examples 
     
    7077 
    7178 
    72 import sys, os, argparse 
     79import sys, os, re, argparse 
    7380 
    7481from ll import misc, astyle, orasql 
     
    94101    p.add_argument("-i", "--ignore", dest="ignore", help="Ignore errors? (default %(default)s)", default=False, action=misc.FlagAction) 
    95102    p.add_argument("-e", "--encoding", dest="encoding", help="Encoding for output (default %(default)s)", default="utf-8") 
     103    p.add_argument(      "--include", dest="include", metavar="REGEXP", help="Include only objects whose name contains PATTERN (default: %(default)s)", type=re.compile) 
     104    p.add_argument(      "--exclude", dest="exclude", metavar="REGEXP", help="Exclude objects whose name contains PATTERN (default: %(default)s)", type=re.compile) 
    96105 
    97106    args = p.parse_args(args) 
     
    122131        if obj.owner is not None: 
    123132            return False 
    124         if args.keepjunk: 
    125             return True 
    126133        # output pk, fks etc. only when they belong to a table we do output 
    127134        if isinstance(obj, (orasql.Constraint, orasql.Index)): 
    128135            obj = obj.table() 
    129         if "$" in obj.name or obj.name.startswith("SYS_EXPORT_SCHEMA_"): 
     136        if ("$" in obj.name or "/" in obj.name or obj.name.startswith("SYS_EXPORT_SCHEMA_")) and not args.keepjunk: 
     137            return False 
     138        if args.include is not None and args.include.search(obj.name) is None: 
     139            return False 
     140        if args.exclude is not None and args.exclude.search(obj.name) is not None: 
    130141            return False 
    131142        return True