Esempio n. 1
0
def skip_engines(include=('*',), exclude=()):
    """Create a handler to evaluate table-ddl nodes and skip
    ddl + dml based on a table engine using an inclusion/exclusion
    check

    :param include: list of glob patterns that must match for inclusions
    :param exclude: list of glob patterns that should be excluded
    """
    check = Filter()
    check.include([pat.lower() for pat in include])
    check.exclude([pat.lower() for pat in exclude])

    def _skip_handler(dispatcher, node):
        """Process node and skip based on engine filters"""
        for token in node.tokens:
            if token.symbol is 'CreateTable':
                engine, = token.extract('^[)] ENGINE=([a-zA-Z]+)')
            elif token.symbol is 'CreateTmpView':
                engine = 'view'
            else:
                continue
            try:
                check(engine.lower())
            except FilteredItem:
                name = '%s.%s' % (dispatcher.database, dispatcher.table)
                # add a check for the dm - should be a one shot check
                if engine == 'view':
                    dispatcher.register('view-ddl', skip_tables(exclude=[name]))
                else:
                    dispatcher.register('table-dml', 
                                        skip_tables(exclude=[name]))
                raise SkipNode()
        return node
    return _skip_handler
Esempio n. 2
0
def skip_tables(include=('*',), exclude=()):
    """Create a handler to evaluate table-* nodes and optionally skip these 
    based on an inclusion/exclusion check

    :param include: list of glob patterns that must match for inclusions
    :param exclude: list of glob patterns that should be excluded
    """
    check = Filter()
    check.include(list(include))
    check.exclude(list(exclude))
    def _skip_handler(dispatcher, node):
        """Process a node and skip based on table filter"""
        try:
            check('%s.%s' % (dispatcher.database, dispatcher.table))
        except FilteredItem:
            raise SkipNode()
        return node
    return _skip_handler
Esempio n. 3
0
def skip_databases(include=('*',), exclude=()):
    """Create a handler to evaluate database-ddl and skip the node based
    on an inclusion/exclusion check

    :param include: list of glob patterns that must match for inclusions
    :param exclude: list of glob patterns that should be excluded
    """
    check = Filter()
    check.include(list(include))
    check.exclude(list(exclude))
    def _skip_handler(dispatcher, node):
        """Process a node and skip based on database filter"""
        try:
            check(dispatcher.database)
        except FilteredItem:
            raise SkipNode()
        return node
    return _skip_handler