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

wants to merge 3 commits into from

Conversation

masqu3rad3
Copy link

for the image Viewer I have been working on
(https://github.com/masqu3rad3/FileTools/tree/master/ImageViewerSA)
I added 'include=[]' flag to the pyseq.py module.
If nothing specified, it works as it is.
If a list of extensions are given e.g [".jpg", ",exr"] it filters down the sequences to those extensions only.

Thanks for the great work & wish you the best

@rsgalloway
Copy link
Owner

Cool, thanks. Interesting idea. My only concern is about affecting the performance by doing the extra check. Right now, it looks like it's checking even if you haven't added anything to includes. Also, I think you don't want to set a mutable value (in this case a list) as s default argument.

@masqu3rad3
Copy link
Author

Yes, you are right. I actually couldn't think about that. I guess a tuple can be used to make it immutable, but could not think right away for escaping extra check. I will give a thought and do couple of tests. Thanks for replying.

@broganross
Copy link

Would it be a little more forward thinking to add a filter callback argument? That way user's could implement whatever filtering they require? The callable returns a boolean of whether the file name is to be included.

def walk(source, level=-1, topdown=True, onerror=None, followlinks=False, hidden=False, filter_cb=None):
    ...
    joined_files = []
    for file_name in files:
        if filter_cb is not None and filter_cb(root, file_name) is True:
            joined_files.append(os.path.join(root, file_name))
        else:
            joined_files.append(os.path.join(root, file_name))
    ...

def filter_cb_example(root, file_name):
  return os.path.splitext(file_name)[1] in [".jpg", ".tiff"]


walk("some/path", filter_cb=filter_cb_example)

Also, I'm pretty sure re.match doesn't take a list, or a tuple. You'd have to extend your code to work correctly.

@masqu3rad3
Copy link
Author

Also, I'm pretty sure re.match doesn't take a list, or a tuple. You'd have to extend your code to work correctly.

Yes my bad. I was converting the list into a string value before re.match in my clipped version. Forgot to add it here
includes = r'|'.join([fnmatch.translate(x) for x in includes])

@masqu3rad3 masqu3rad3 closed this Nov 23, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants