Compiled search condition
| 61 | |
| 62 | |
| 63 | class CompiledSearch: |
| 64 | """Compiled search condition""" |
| 65 | |
| 66 | def __init__(self, search): |
| 67 | self.command = search.command |
| 68 | |
| 69 | def re_compile(regex): |
| 70 | return re.compile(regex, fs_scan_re_flags) if regex else None |
| 71 | |
| 72 | self.regex = re_compile(search.regex) |
| 73 | self.nregex = re_compile(search.nregex) |
| 74 | self.wholeregex = re_compile(search.wholeregex) |
| 75 | self.nwholeregex = re_compile(search.nwholeregex) |
| 76 | |
| 77 | def match(self, dirpath, filename): |
| 78 | full_path = os.path.join(dirpath, filename) |
| 79 | |
| 80 | if self.regex and not self.regex.search(filename): |
| 81 | return None |
| 82 | |
| 83 | if self.nregex and self.nregex.search(filename): |
| 84 | return None |
| 85 | |
| 86 | if self.wholeregex and not self.wholeregex.search(full_path): |
| 87 | return None |
| 88 | |
| 89 | if self.nwholeregex and self.nwholeregex.search(full_path): |
| 90 | return None |
| 91 | |
| 92 | return full_path |
| 93 | |
| 94 | |
| 95 | class DeepScan: |