diff --git a/lib/gui/main.py b/lib/gui/main.py index 37ab26c..527aa01 100755 --- a/lib/gui/main.py +++ b/lib/gui/main.py @@ -522,6 +522,7 @@ def cmd_btn_run(self): mozfiles = load_moz_files( filepaths=mozdir, ignore_dirs=self.config_gui['ignore_dirs'], + ignore_strs=self.config_gui['ignore_strs'], split_parts=not self.var_no_part_split.get(), ) except OSError as ex: diff --git a/lib/util/parser.py b/lib/util/parser.py index f1c19b9..9717021 100755 --- a/lib/util/parser.py +++ b/lib/util/parser.py @@ -118,7 +118,8 @@ def get_archive_info(datdir, archdir): ) -def get_dir_files(dirpath, ignore_dirs=None, ext='.dat', _level=0): +def get_dir_files( + dirpath, ignore_dirs=None, ignore_strs=None, ext='.dat', _level=0): """ Loads all MozaikFiles contained in a directory. """ indent = ' ' * _level debug('{}Looking for {} files in: {}'.format( @@ -132,7 +133,12 @@ def get_dir_files(dirpath, ignore_dirs=None, ext='.dat', _level=0): ] datfiles = [] for diritem in diritems: - if is_ignored_dir(diritem, ignore_dirs=ignore_dirs): + ignore = is_ignored_dir( + diritem, + ignore_dirs=ignore_dirs, + ignore_strs=ignore_strs, + ) + if ignore: continue if diritem.endswith(ext): if is_valid_dat_file(diritem, _indent=indent): @@ -143,6 +149,7 @@ def get_dir_files(dirpath, ignore_dirs=None, ext='.dat', _level=0): get_dir_files( diritem, ignore_dirs=ignore_dirs, + ignore_strs=ignore_strs, ext=ext, _level=_level + 1, ) @@ -195,10 +202,22 @@ def increment_file_path(path): return newpath -def is_ignored_dir(dirpath, ignore_dirs=None): +def is_ignored_dir(dirpath, ignore_dirs=None, ignore_strs=None): """ Return True if this `dirpath` should be ignored. """ - if not ignore_dirs: + if not (ignore_dirs or ignore_strs): return False + if not ignore_dirs: + ignore_dirs = [] + if ignore_strs: + ignore_strs = [s.lower() for s in ignore_strs] + else: + ignore_strs = [] + dirpathlower = dirpath.lower() + for s in ignore_strs: + if s in dirpathlower: + debug('Ignoring matched string ({!r}): {}'.format(s, dirpath)) + return True + if dirpath.rstrip('/') in ignore_dirs: debug('Ignoring matched dir: {}'.format(dirpath)) return True @@ -240,7 +259,9 @@ def load_moz_file(filename, split_parts=True): return master.into_width_files() -def load_moz_files(filepaths, ignore_dirs=None, ext='.dat', split_parts=True): +def load_moz_files( + filepaths, ignore_dirs=None, ignore_strs=None, + ext='.dat', split_parts=True): """ Loads multiple MozaikFiles from file names, and returns a list of MozaikFiles. """ @@ -250,7 +271,12 @@ def load_moz_files(filepaths, ignore_dirs=None, ext='.dat', split_parts=True): files = [] for filepath in filepaths: if os.path.isdir(filepath): - if is_ignored_dir(filepath, ignore_dirs=ignore_dirs): + ignore = is_ignored_dir( + filepath, + ignore_dirs=ignore_dirs, + ignore_strs=ignore_strs, + ) + if ignore: continue # A directory, possibly containing .dat files # or sub-dirs with .dat files. @@ -259,9 +285,11 @@ def load_moz_files(filepaths, ignore_dirs=None, ext='.dat', split_parts=True): get_dir_files( filepath, ignore_dirs=ignore_dirs, + ignore_strs=ignore_strs, ext=ext, ), ignore_dirs=ignore_dirs, + ignore_strs=ignore_strs, ext=ext, split_parts=split_parts, ) diff --git a/tigertamer.py b/tigertamer.py index cc7eec2..f0d142d 100755 --- a/tigertamer.py +++ b/tigertamer.py @@ -59,8 +59,10 @@ {script} -f func [-e] [-s] [-D] {script} -g [-e] [-r] [-s] [-D] {script} (-u | -U) [ARCHIVE_DIR] [-D] - {script} [FILE...] [-e] [-i dir...] [-n] [-s] [-D] - {script} [FILE...] [-e] [-i dir...] [-o dir [-a dir]] [-s] [-D] + {script} [FILE...] [-e] [-i dir...] [-I text...] + [-n] [-s] [-D] + {script} [FILE...] [-e] [-i dir...] [-I text...] + [-o dir [-a dir]] [-s] [-D] Options: ARCHIVE_DIR : Directory to look for archive files. @@ -74,6 +76,8 @@ -f name, --func name : Run a function from WinMain for debugging. This automatically implies -g,--gui. -g,--gui : Load the Tiger Tamer GUI. + -I str,--IGNORE str : One or more strings to ignore when looking + for mozaik files (applies to full file path). -i dir,--ignore dir : One or more directories to ignore when looking for mozaik files. The output and archive directories are @@ -107,6 +111,9 @@ def main(argd): ) ignore_dirs = set(config.get('ignore_dirs', [])) ignore_dirs.update(set(argd['--ignore'])) + ignore_strs = set(config.get('ignore_strs', [])) + ignore_strs.update(set(argd['--IGNORE'])) + if outdir and (outdir != '-'): ignore_dirs.add(outdir) if archdir and (archdir != '-'): @@ -136,6 +143,7 @@ def main(argd): dat_dir=inpaths[0] if inpaths else '', tiger_dir='' if outdir in (None, '-') else outdir, ignore_dirs=tuple(ignore_dirs), + ignore_strs=tuple(ignore_strs), run_function=argd['--func'], ) @@ -159,6 +167,7 @@ def main(argd): mozfiles = load_moz_files( inpaths, ignore_dirs=ignore_dirs, + ignore_strs=ignore_strs, split_parts=not argd['--nosplit'], )