X-Git-Url: https://wannabe.guru.org/gitweb/?a=blobdiff_plain;f=directory_filter.py;h=d14dce7c6eec912e2b2c5b07ebe9b6ef4dfcf716;hb=ed8fa2b10b0177b15b7423263bdd390efde2f0c8;hp=9fa13c2c1169c9895af5de7c4494627cd972d735;hpb=64a9a97fdff29f4bb9eef4e80faaeaa520d59506;p=python_utils.git diff --git a/directory_filter.py b/directory_filter.py index 9fa13c2..d14dce7 100644 --- a/directory_filter.py +++ b/directory_filter.py @@ -4,18 +4,15 @@ import hashlib import os from typing import Any, Optional -import predicate -import file_utils - -class DirectoryFileFilter(predicate.Predicate): - """A predicate that will return False if when a proposed file's +class DirectoryFileFilter(object): + """A predicate that will return False if / when a proposed file's content to-be-written is identical to the contents of the file; skip the write. """ - def __init__(self, directory: str): super().__init__() + import file_utils if not file_utils.does_directory_exist(directory): raise ValueError(directory) self.directory = directory @@ -31,6 +28,7 @@ class DirectoryFileFilter(predicate.Predicate): self._update_file(path, mtime) def _update_file(self, filename: str, mtime: Optional[float] = None): + import file_utils assert file_utils.does_file_exist(filename) if mtime is None: mtime = file_utils.get_file_raw_mtime(filename) @@ -60,6 +58,7 @@ class DirectoryAllFilesFilter(DirectoryFileFilter): print(self.all_md5s) def _update_file(self, filename: str, mtime: Optional[float] = None): + import file_utils assert file_utils.does_file_exist(filename) if mtime is None: mtime = file_utils.get_file_raw_mtime(filename) @@ -75,4 +74,3 @@ class DirectoryAllFilesFilter(DirectoryFileFilter): mem_hash.update(item) md5 = mem_hash.hexdigest() return md5 not in self.all_md5s -