Skip to content

add a plugin for finer control over ignored files #233

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

Merged
merged 1 commit into from
Feb 1, 2017

Conversation

t-animal
Copy link
Contributor

This has the advantage that
a) you can put a .nomedia file in a directory and forget about it, no need to update the sigal config
b) you don't have to know how to write fnmatch rules
c) you can easily ignore one of two equally named directories
d) if you want to exclude many single images your config does not get cluttered
e) last (and least ;) ) you can simply copy a directory from your Android phone and .nomedia entries have the same meaning

@t-animal
Copy link
Contributor Author

Here's the docstring:

This plugin offers more fine-grained control over exluded images and folders, similarly to how
it's handled on Android.

To ignore a folder or image put a .nomedia file next to it in its parent folder and put its name
into the file.
E.g.:

    content of folder:
        IMG_3425.JPG, IMG_2426.JPG, IMG_2427.JPG, subfolder, .nomedia
    content of .nomedia:
        IMG_2426.JPG
        IMG_2427.JPG
        subfolder

will ignore all images but IMG_3425.JPG and the subfolder

Alternatively, if you put a .nomedia file into a folder and leave it blank (i.e. an empty file
called .nomedia in a folder containing images), this ignores the whole folder it's located in
(like on Android).

WARNING: When you have a pre-existing gallery from a previous run of sigal adding a new .nomedia
file will not remove the newly ignored images/albums from the existing gallery (only the entries
in the parent gallery pointing to it). They might still be reachable thereafter. Either remove
the whole gallery to be sure or remove the ignored files/folders inside the gallery to remove
them for good.

@t-animal
Copy link
Contributor Author

t-animal commented Jan 20, 2017

[settled]

Copy link
Owner

@saimn saimn left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Left a few stylistic comments, otherwise it looks good.


def filter_nomedia(album, settings=None):
"""Removes all filtered Media and subdirs from an Album"""
nomediaPath = album.src_path + "/.nomedia"
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use os.path.join instead of string concatenation.

if os.path.isfile(nomediaPath):

if os.path.getsize(nomediaPath) == 0:
logger.info("Ignoring album '{}' because of present 0-byte .nomedia file".\
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Useless backslash. Also it's better to use logger.info('... %s ...', album.name) as it avoids a string formatting when the logger level is higher than INFO.

album.medias = []

else:
with open(nomediaPath, "Ur") as nomediaFile:
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I discover the U mode ;-), but from the docs: 'U' mode is deprecated and will raise an exception in future versions
of Python. It has no effect in Python 3.

Also use io.open for Python 2 compatibility (not sure how long I will keep it !).


#subdirs have been added to the gallery already, remove them there, too
for ignoredEntry in ignoredEntries:
for key in list(album.gallery.albums.keys()):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

list is useless here

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Without the explicit list-call you'd change the dict while iterating and that throws an exception.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good point.

#subdirs have been added to the gallery already, remove them there, too
for ignoredEntry in ignoredEntries:
for key in list(album.gallery.albums.keys()):
if key.startswith(album.path + os.path.sep + ignoredEntry):
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Use os.path.join instead

@saimn
Copy link
Owner

saimn commented Jan 20, 2017

e) last (and least ;) ) you can simply copy a directory from your Android phone and .nomedia entries have the same meaning

It looks like the most convincing point to me ;-)
I know that other plugins are not tested, and that's bad 😞 , but to be sure that your plugin works it would be very useful that have some tests.

@t-animal t-animal force-pushed the nomedia_plugin branch 2 times, most recently from 43feb78 to eaf6922 Compare January 22, 2017 21:20
@t-animal
Copy link
Contributor Author

Ok, so I've added test cases and now the plugin also removes the ignored folders themselves from the directory tree, not just from the gallery (if they are empty) - this leaks less information.

@saimn
Copy link
Owner

saimn commented Jan 25, 2017

@t-animal - Sorry for the delay. It looks good, my only concern is the license of the images you added. For the other images I used personal ones or images from Wikipedia. Can you replace your images by the ones already present in the tests ? It would also save some space in the git directory (if your squash your commits).

@t-animal
Copy link
Contributor Author

The images are all from the apollo 7 mission and are in the public domain: https://www.flickr.com/photos/projectapolloarchive/21756099278/in/album-72157657129869694/

@saimn saimn merged commit 63ef462 into saimn:master Feb 1, 2017
@saimn
Copy link
Owner

saimn commented Feb 1, 2017

Ok, merging ! Thanks

@t-animal t-animal deleted the nomedia_plugin branch February 2, 2017 16:43
@saimn saimn added this to the 1.4.0 milestone Feb 5, 2017
kontza pushed a commit to kontza/sigal that referenced this pull request Aug 28, 2020
add a plugin for finer control over ignored files
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.

2 participants