Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Hi #46

Closed
wants to merge 3 commits into from
Closed

Hi #46

Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
9 changes: 7 additions & 2 deletions pyseq.py
Expand Up @@ -56,6 +56,7 @@
from glob import glob
from glob import iglob
from datetime import datetime
import fnmatch

__version__ = "0.5.1"

Expand Down Expand Up @@ -1152,7 +1153,7 @@ def iget_sequences(source):
log.debug("time: %s", datetime.now() - start)


def walk(source, level=-1, topdown=True, onerror=None, followlinks=False, hidden=False):
def walk(source, level=-1, topdown=True, onerror=None, followlinks=False, hidden=False, includes=()):
"""Generator that traverses a directory structure starting at
source looking for sequences.

Expand All @@ -1164,6 +1165,8 @@ def walk(source, level=-1, topdown=True, onerror=None, followlinks=False, hidden
:param followlinks: whether to follow links
:param hidden: include hidden files and dirs
"""
# transform glob patterns to regular expressions
includes = r'|'.join([fnmatch.translate(x) for x in includes])
start = datetime.now()
assert isinstance(source, basestring) is True
assert os.path.exists(source) is True
Expand All @@ -1175,7 +1178,9 @@ def walk(source, level=-1, topdown=True, onerror=None, followlinks=False, hidden
files = [f for f in files if not f[0] == '.']
dirs[:] = [d for d in dirs if not d[0] == '.']

files = [os.path.join(root, f) for f in files]
files = [os.path.join(root, f) for f in files if re.match(includes,f)]
# files = [f for f in files if re.match(includes, f)]
##

if topdown is True:
parts = root.replace(source, "").split(os.sep)
Expand Down