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

add a plugin for finer control over ignored files #233

Merged
merged 1 commit into from Feb 1, 2017

Conversation

2 participants
@t-animal
Contributor

t-animal commented Jan 20, 2017

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

This comment has been minimized.

Contributor

t-animal commented Jan 20, 2017

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

This comment has been minimized.

Contributor

t-animal commented Jan 20, 2017

[settled]

@t-animal t-animal force-pushed the t-animal:nomedia_plugin branch from cf03347 to a3a4aa9 Jan 20, 2017

@saimn

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"

This comment has been minimized.

@saimn

saimn Jan 20, 2017

Owner

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".\

This comment has been minimized.

@saimn

saimn Jan 20, 2017

Owner

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:

This comment has been minimized.

@saimn

saimn Jan 20, 2017

Owner

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()):

This comment has been minimized.

@saimn

saimn Jan 20, 2017

Owner

list is useless here

This comment has been minimized.

@t-animal

t-animal Jan 22, 2017

Contributor

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

This comment has been minimized.

@saimn

saimn Jan 25, 2017

Owner

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

This comment has been minimized.

@saimn

saimn Jan 20, 2017

Owner

Use os.path.join instead

@saimn

This comment has been minimized.

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 t-animal:nomedia_plugin branch 2 times, most recently from 43feb78 to eaf6922 Jan 22, 2017

@t-animal

This comment has been minimized.

Contributor

t-animal commented Jan 22, 2017

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.

@t-animal t-animal force-pushed the t-animal:nomedia_plugin branch from eaf6922 to 5d9d337 Jan 22, 2017

@saimn

This comment has been minimized.

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

This comment has been minimized.

Contributor

t-animal commented Jan 26, 2017

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

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details
@saimn

This comment has been minimized.

Owner

saimn commented Feb 1, 2017

Ok, merging ! Thanks

@t-animal t-animal deleted the t-animal:nomedia_plugin branch Feb 2, 2017

@saimn saimn added this to the 1.4.0 milestone Feb 5, 2017

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment