Add exclude
This commit is contained in:
parent
2c8ef55f15
commit
2f5977a8fc
1 changed files with 33 additions and 20 deletions
|
@ -13,10 +13,11 @@ import click_config_file
|
|||
from logging.handlers import SysLogHandler
|
||||
import zlib
|
||||
import sqlite3
|
||||
import re
|
||||
|
||||
class find_duplicate_files:
|
||||
|
||||
def __init__(self, debug_level, log_file, dummy, first_directory, second_directory):
|
||||
def __init__(self, debug_level, log_file, dummy, first_directory, second_directory, exclude):
|
||||
''' Initial function called when object is created '''
|
||||
self.config = dict()
|
||||
self.config['debug_level'] = debug_level
|
||||
|
@ -28,6 +29,7 @@ class find_duplicate_files:
|
|||
self.dummy = dummy
|
||||
self.first_directory = first_directory
|
||||
self.second_directory = second_directory
|
||||
self.exclude = exclude
|
||||
|
||||
self._init_db_cache()
|
||||
|
||||
|
@ -73,12 +75,22 @@ class find_duplicate_files:
|
|||
else:
|
||||
return False
|
||||
|
||||
def _test_exclude(self, file_name):
|
||||
""" Test if a filename match any of the exclusions """
|
||||
for exclude in self.exclude:
|
||||
match = re.search(exclude, file_name)
|
||||
if match:
|
||||
return True
|
||||
else:
|
||||
return False
|
||||
|
||||
def recursive_scandir(self, path, ignore_hidden_files=True):
|
||||
''' Recursively scan a directory for files'''
|
||||
files = dict()
|
||||
try:
|
||||
for file in os.scandir(path):
|
||||
if not file.name.startswith('.'):
|
||||
if not self._test_exclude(file.path):
|
||||
if file.is_file():
|
||||
check_cache = self._check_file_cache(file.path)
|
||||
if check_cache:
|
||||
|
@ -142,9 +154,10 @@ class find_duplicate_files:
|
|||
@click.option("--dummy","-n", is_flag=True, help="Don't do anything, just show what would be done.") # Don't forget to add dummy to parameters of main function
|
||||
@click.option('--first-directory', '-f', required=True, help='First directory to find files AND TO DELETE FILES FROM!!!')
|
||||
@click.option('--second-directory', '-s', required=True, help='Second directory to find files')
|
||||
@click.option('--exclude', '-e', multiple=True, help='Regular expression pattern to exclude from files and directories.')
|
||||
@click_config_file.configuration_option()
|
||||
def __main__(debug_level, log_file, dummy, first_directory, second_directory):
|
||||
return find_duplicate_files(debug_level, log_file, dummy, first_directory, second_directory)
|
||||
def __main__(debug_level, log_file, dummy, first_directory, second_directory, exclude):
|
||||
return find_duplicate_files(debug_level, log_file, dummy, first_directory, second_directory, exclude)
|
||||
|
||||
if __name__ == "__main__":
|
||||
__main__()
|
||||
|
|
Loading…
Reference in a new issue