duplicate resolution callback function (#164)

This commit is contained in:
Adrian Sampson 2012-03-19 15:32:53 -07:00
parent 6bfbb899bc
commit 19b08f8e99
4 changed files with 15 additions and 5 deletions

View file

@ -275,7 +275,8 @@ class ImportConfig(object):
'quiet_fallback', 'copy', 'write', 'art', 'delete',
'choose_match_func', 'should_resume_func', 'threaded',
'autot', 'singletons', 'timid', 'choose_item_func',
'query', 'incremental', 'ignore']
'query', 'incremental', 'ignore',
'resolve_duplicate_func']
def __init__(self, **kwargs):
for slot in self._fields:
setattr(self, slot, kwargs[slot])
@ -577,8 +578,7 @@ def user_query(config):
# Check for duplicates if we have a match (or ASIS).
if _duplicate_check(lib, task, recent):
tag_log(config.logfile, 'duplicate', task.path)
log.warn("This album is already in the library!")
task.set_choice(action.SKIP)
config.resolve_duplicate_func(task, config)
def show_progress(config):
"""This stage replaces the initial_lookup and user_query stages
@ -777,8 +777,7 @@ def item_query(config):
# Duplicate check.
if _item_duplicate_check(lib, task, recent):
tag_log(config.logfile, 'duplicate', task.item.path)
log.warn("This item is already in the library!")
task.set_choice(action.SKIP)
config.resolve_duplicate_func(task, config)
def item_progress(config):
"""Skips the lookup and query stages in a non-autotagged singleton

View file

@ -564,6 +564,14 @@ def choose_item(task, config):
assert not isinstance(choice, importer.action)
return choice
def resolve_duplicate(task, config):
"""Decide what to do when a new album or item seems similar to one
that's already in the library.
"""
log.warn("This %s is already in the library!" %
("album" if task.is_album else "item"))
task.set_choice(importer.action.SKIP)
# The import command.
def import_files(lib, paths, copy, write, autot, logpath, art, threaded,
@ -636,6 +644,7 @@ def import_files(lib, paths, copy, write, autot, logpath, art, threaded,
query = query,
incremental = incremental,
ignore = ignore,
resolve_duplicate_func = resolve_duplicate,
)
finally:

View file

@ -95,6 +95,7 @@ def iconfig(lib, **kwargs):
query = None,
incremental = False,
ignore = [],
resolve_duplicate_func = lambda x, y: None,
)
for k, v in kwargs.items():
setattr(config, k, v)

View file

@ -105,6 +105,7 @@ class NonAutotaggedImportTest(unittest.TestCase):
query = None,
incremental = False,
ignore = [],
resolve_duplicate_func = None,
)
return paths