rsgalloway / pyseq

Compressed sequence string module for Python
https://pyseq.rsgalloway.com/
Other
123 stars 36 forks source link

Hi #46

Closed masqu3rad3 closed 11 months ago

masqu3rad3 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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 commented 6 years ago

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])