Skip to content

Commit

Permalink
Add ignore_strs, to match against any part of the path.
Browse files Browse the repository at this point in the history
  • Loading branch information
cjwelborn committed Feb 28, 2019
1 parent fe968ab commit 15f77c9
Show file tree
Hide file tree
Showing 3 changed files with 46 additions and 8 deletions.
1 change: 1 addition & 0 deletions lib/gui/main.py
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
40 changes: 34 additions & 6 deletions lib/util/parser.py
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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):
Expand All @@ -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,
)
Expand Down Expand Up @@ -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
Expand Down Expand Up @@ -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.
"""
Expand All @@ -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.
Expand All @@ -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,
)
Expand Down
13 changes: 11 additions & 2 deletions tigertamer.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand All @@ -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
Expand Down Expand Up @@ -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 != '-'):
Expand Down Expand Up @@ -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'],
)

Expand All @@ -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'],
)

Expand Down

0 comments on commit 15f77c9

Please sign in to comment.