diff --git a/lib/tfw/components/directory_snapshotting_event_handler.py b/lib/tfw/components/directory_snapshotting_event_handler.py index 55fcde8..8b6f384 100644 --- a/lib/tfw/components/directory_snapshotting_event_handler.py +++ b/lib/tfw/components/directory_snapshotting_event_handler.py @@ -17,20 +17,26 @@ LOG = logging.getLogger(__name__) class DirectorySnapshottingEventHandler(EventHandlerBase): - def __init__(self, key, directories): + def __init__(self, key, directories, exclude_unix_patterns=None): super().__init__(key) self.snapshot_providers = {} + self._exclude_unix_patterns = exclude_unix_patterns self.init_snapshot_providers(directories) self.command_handlers = { 'take_snapshot': self.handle_take_snapshot, - 'restore_snapshot': self.handle_restore_snapshot + 'restore_snapshot': self.handle_restore_snapshot, + 'exclude': self.handle_exclude } def init_snapshot_providers(self, directories): for index, directory in enumerate(directories): git_dir = self.init_git_dir(index, directory) - self.snapshot_providers[directory] = SnapshotProvider(directory, git_dir) + self.snapshot_providers[directory] = SnapshotProvider( + directory, + git_dir, + self._exclude_unix_patterns + ) @staticmethod def init_git_dir(index, directory): @@ -70,3 +76,12 @@ class DirectorySnapshottingEventHandler(EventHandlerBase): for provider in self.snapshot_providers.values(): provider.restore_snapshot(date) return data + + def handle_exclude(self, data): + exclude_unix_patterns = data['value'] + if not isinstance(exclude_unix_patterns, list): + raise KeyError + + for provider in self.snapshot_providers.values(): + provider.exclude = exclude_unix_patterns + return data