Skip to content

Commit

Permalink
Browse files Browse the repository at this point in the history
ensure bare table names in filters are treated as '*.<name>'
  • Loading branch information
abg committed Jul 8, 2010
1 parent 4087120 commit 596bc9d
Show file tree
Hide file tree
Showing 3 changed files with 47 additions and 6 deletions.
Expand Up @@ -6,7 +6,9 @@
from holland.core.exceptions import BackupError
from holland.lib.compression import open_stream, lookup_compression
from holland.lib.mysql import MySQLSchema, connect, MySQLError
from holland.lib.mysql import include_glob, exclude_glob
from holland.lib.mysql import include_glob, exclude_glob, \
include_glob_qualified, \
exclude_glob_qualified
from holland.lib.mysql import DatabaseIterator, MetadataTableIterator, \
SimpleTableIterator
from holland.backup.mysqldump.base import start
Expand Down Expand Up @@ -85,8 +87,9 @@ def __init__(self, name, config, target_directory, dry_run=False):
self.schema.add_database_filter(
exclude_glob(*config['exclude-databases'])
)
self.schema.add_table_filter(include_glob(*config['tables']))
self.schema.add_table_filter(exclude_glob(*config['exclude-tables']))

self.schema.add_table_filter(include_glob_qualified(*config['tables']))
self.schema.add_table_filter(exclude_glob_qualified(*config['exclude-tables']))
self.schema.add_engine_filter(include_glob(*config['engines']))
self.schema.add_engine_filter(exclude_glob(*config['exclude-engines']))

Expand Down
@@ -1,7 +1,9 @@
"""MySQL Schema introspection support"""

from holland.lib.mysql.schema.filter import IncludeFilter, ExcludeFilter, \
include_glob, exclude_glob
include_glob, exclude_glob, \
include_glob_qualified, \
exclude_glob_qualified
from holland.lib.mysql.schema.base import MySQLSchema, DatabaseIterator, \
MetadataTableIterator, \
SimpleTableIterator
Expand All @@ -15,4 +17,6 @@
'ExcludeFilter',
'include_glob',
'exclude_glob',
'include_glob_qualified',
'exclude_glob_qualified',
]
38 changes: 36 additions & 2 deletions plugins/holland.lib.mysql/holland/lib/mysql/schema/filter.py
Expand Up @@ -67,8 +67,42 @@ def __call__(self, item):

def exclude_glob(*pattern):
"""Create an exclusion filter from a glob pattern"""
return ExcludeFilter([fnmatch.translate(pat) for pat in pattern])
result = []
for pat in pattern:
result.append(fnmatch.translate(pat))
return ExcludeFilter(result)

def include_glob(*pattern):
"""Create an inclusion filter from glob patterns"""
return IncludeFilter([fnmatch.translate(pat) for pat in pattern])
result = []
for pat in pattern:
result.append(fnmatch.translate(pat))
return IncludeFilter(result)

def include_glob_qualified(*pattern):
"""Create an inclusion filter from glob patterns
Additionally ensure the pattern is for a qualified table name.
If not '.' is found in the name, this implies an implicit *.
before the name
"""
result = []
for pat in pattern:
if '.' not in pat:
pat = '*.' + pat
result.append(pat)
return include_glob(*result)

def exclude_glob_qualified(*pattern):
"""Create an exclusion filter from glob patterns
Additionally ensure the pattern is for a qualified table name.
If not '.' is found in the name, this implies an implicit *.
before the name
"""
result = []
for pat in pattern:
if '.' not in pat:
pat = '*.' + pat
result.append(pat)
return exclude_glob(*result)

0 comments on commit 596bc9d

Please sign in to comment.