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

ImportAdded support for in-place and link imports #1170

Merged
merged 2 commits into from
Dec 28, 2014
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
11 changes: 11 additions & 0 deletions beetsplug/importadded.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,16 @@ def reimported_album(album):
return album.path in replaced_album_paths


@ImportAddedPlugin.listen('import_task_start')
def record_if_inplace(task, session):
if not (session.config['copy'] or session.config['move'] or
session.config['link']):
log.debug(u"In place import detected, recording mtimes from source"
u" paths")
for item in task.items:
record_import_mtime(item, item.path, item.path)


@ImportAddedPlugin.listen('import_task_files')
def record_reimported(task, session):
global reimported_item_ids, replaced_album_paths
Expand Down Expand Up @@ -81,6 +91,7 @@ def write_item_mtime(item, mtime):

@ImportAddedPlugin.listen('before_item_moved')
@ImportAddedPlugin.listen('item_copied')
@ImportAddedPlugin.listen('item_linked')
def record_import_mtime(item, source, destination):
"""Record the file mtime of an item's path before its import.
"""
Expand Down
11 changes: 10 additions & 1 deletion test/test_importadded.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,13 +76,22 @@ def assertEqualTimes(self, first, second, msg=None):
"""For comparing file modification times at a sufficient precision"""
self.assertAlmostEqual(first, second, places=4, msg=msg)

def test_import_album_with_added_dates(self):
def assertAlbumImport(self):
self.importer.run()
album = self.lib.albums().get()
self.assertEqual(album.added, self.min_mtime)
for item in album.items():
self.assertEqual(item.added, self.min_mtime)

def test_import_album_with_added_dates(self):
self.assertAlbumImport()

def test_import_album_inplace_with_added_dates(self):
self.config['import']['copy'] = False
self.config['import']['move'] = False
self.config['import']['link'] = False
self.assertAlbumImport()

def test_import_album_with_preserved_mtimes(self):
self.config['importadded']['preserve_mtimes'] = True
self.importer.run()
Expand Down