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

Support flag for "no prompt" orphan removal and fixed tests for empty flac #9

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
13 changes: 10 additions & 3 deletions flacsync/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ def get_dest_orphans( dest_dir, base_dir, sources ):
return orphans


def del_dest_orphans( dest_dir, base_dir, sources ):
def del_dest_orphans( dest_dir, base_dir, sources, prompt=True ):
"""
Interactively prompt the user to remove all orphaned files located in the
destination file path(s).
Expand All @@ -286,7 +286,7 @@ def del_dest_orphans( dest_dir, base_dir, sources ):
"""
# create list of orphans
orphans = get_dest_orphans( dest_dir, base_dir, sources )
yes_to_all = False
yes_to_all = not prompt
for o in orphans:
rm = True
if not yes_to_all:
Expand Down Expand Up @@ -472,6 +472,13 @@ def get_opts( argv ):
action='callback', callback=store_once,
type='choice', dest='enc_type', help=_help_str(helpstr))

helpstr = """
force without prompting the removal of files and directories in the dest dir that have
no
corresponding source file"""
parser.add_option( '-n', '--no-prompt-removal', dest='prompt',
default=True, action="store_false", help=_help_str(helpstr) )

helpstr = """
prevent the removal of files and directories in the dest dir that have no
corresponding source file"""
Expand Down Expand Up @@ -580,7 +587,7 @@ def main( argv=None ):

# remove orphans, if defined
if opts.del_orphans:
del_dest_orphans( opts.dest_dir, opts.base_dir, opts.sources)
del_dest_orphans( opts.dest_dir, opts.base_dir, opts.sources, prompt=opts.prompt)

# exit if no work
if not encoders: return
Expand Down
3 changes: 3 additions & 0 deletions flacsync/encoder.py
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,9 @@ def _get_embedded_cover( self ):
picture = sp.Popen( 'metaflac --export-picture-to=- "%s"' % (self.src), shell=True, stdout=sp.PIPE).communicate()[0]
except:
return None
# if the data is not large enough to be an image return nothing
if len(picture) < 3 :
return None
# write the cover to a deterministic filename based on hash
h = hashlib.md5()
h.update(picture)
Expand Down