-
Notifications
You must be signed in to change notification settings - Fork 171
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
Conversation
Here's the docstring: This plugin offers more fine-grained control over exluded images and folders, similarly to how To ignore a folder or image put a .nomedia file next to it in its parent folder and put its name
will ignore all images but Alternatively, if you put a .nomedia file into a folder and leave it blank (i.e. an empty file WARNING: When you have a pre-existing gallery from a previous run of sigal adding a new .nomedia |
[settled] |
cf03347
to
a3a4aa9
Compare
There was a problem hiding this 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" |
There was a problem hiding this comment.
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".\ |
There was a problem hiding this comment.
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: |
There was a problem hiding this comment.
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()): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
list
is useless here
There was a problem hiding this comment.
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.
There was a problem hiding this comment.
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): |
There was a problem hiding this comment.
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
It looks like the most convincing point to me ;-) |
43feb78
to
eaf6922
Compare
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. |
eaf6922
to
5d9d337
Compare
@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). |
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/ |
Ok, merging ! Thanks |
add a plugin for finer control over ignored files
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