├── tests ├── __init__.py ├── rsrc │ └── full.mp3 ├── test_nesteddirectory.py ├── test_printignored.py ├── test_filename.py ├── test_flatdirectory.py ├── _common.py ├── test_reimport.py └── helper.py ├── setup.cfg ├── beetsplug ├── __init__.py └── copyartifacts.py ├── requirements.txt ├── .gitignore ├── .travis.yml ├── tox.ini ├── Makefile ├── setup.py ├── LICENSE └── README.rst /tests/__init__.py: -------------------------------------------------------------------------------- 1 | -------------------------------------------------------------------------------- /setup.cfg: -------------------------------------------------------------------------------- 1 | [nosetests] 2 | verbosity=1 3 | logging-clear-handlers=1 4 | -------------------------------------------------------------------------------- /beetsplug/__init__.py: -------------------------------------------------------------------------------- 1 | __import__('pkg_resources').declare_namespace(__name__) 2 | -------------------------------------------------------------------------------- /tests/rsrc/full.mp3: -------------------------------------------------------------------------------- https://raw.githubusercontent.com/sbarakat/beets-copyartifacts/HEAD/tests/rsrc/full.mp3 -------------------------------------------------------------------------------- /requirements.txt: -------------------------------------------------------------------------------- 1 | # tests 2 | nose==1.3.7 3 | mock==2.0.0 4 | # for FetchArt plugin 5 | requests==2.12.4 6 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | *.pyc 2 | *.swp 3 | .tox/* 4 | dist/* 5 | build/* 6 | env/* 7 | beets/* 8 | beets_copyartifacts.egg-info/* 9 | -------------------------------------------------------------------------------- /.travis.yml: -------------------------------------------------------------------------------- 1 | language: python 2 | 3 | python: 4 | - "2.7" 5 | - "3.5" 6 | 7 | install: 8 | - "pip install tox-travis" 9 | 10 | script: 11 | - "tox" 12 | -------------------------------------------------------------------------------- /tox.ini: -------------------------------------------------------------------------------- 1 | [tox] 2 | envlist = py27,py35 3 | 4 | [testenv] 5 | deps = 6 | nose 7 | commands = 8 | py27: python -m nose {posargs} 9 | py{34,35,36}: python -bb -m nose {posargs} 10 | 11 | -------------------------------------------------------------------------------- /Makefile: -------------------------------------------------------------------------------- 1 | init: 2 | git clone --depth 1 https://github.com/beetbox/beets.git beets 3 | virtualenv env 4 | ./env/bin/pip install -r requirements.txt 5 | ./env/bin/pip install -e . 6 | cp -b config.yaml ~/.config/beets/ 7 | 8 | test: 9 | nosetests tests 10 | -------------------------------------------------------------------------------- /tests/test_nesteddirectory.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | from tests.helper import CopyArtifactsTestCase 5 | from beets import config 6 | 7 | class CopyArtifactsFromNestedDirectoryTest(CopyArtifactsTestCase): 8 | """ 9 | Tests to check that copyartifacts copies or moves artifact files from a nested directory 10 | structure. i.e. songs in an album are imported from two directories corresponding to 11 | disc numbers or flat option is used 12 | """ 13 | -------------------------------------------------------------------------------- /setup.py: -------------------------------------------------------------------------------- 1 | from setuptools import setup, find_packages 2 | 3 | with open('README.rst') as f: 4 | readme = f.read() 5 | 6 | setup( 7 | name="beets-copyartifacts", 8 | version="0.1.2", 9 | description="beets plugin to copy non-music files to import path", 10 | long_description=readme, 11 | author='Sami Barakat', 12 | author_email='sami@sbarakat.co.uk', 13 | url='https://github.com/sbarakat/beets-copyartifacts', 14 | download_url='https://github.com/sbarakat/beets-copyartifacts.git', 15 | license='MIT', 16 | platforms='ALL', 17 | 18 | packages=['beetsplug'], 19 | namespace_packages=['beetsplug'], 20 | install_requires=['beets>=1.3.11'], 21 | 22 | classifiers=[ 23 | 'Topic :: Multimedia :: Sound/Audio', 24 | 'Topic :: Multimedia :: Sound/Audio :: Players :: MP3', 25 | 'License :: OSI Approved :: MIT License', 26 | 'Environment :: Console', 27 | 'Environment :: Web Environment', 28 | 'Programming Language :: Python :: 2', 29 | 'Programming Language :: Python :: 2.7', 30 | ] 31 | ) 32 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | The MIT License (MIT) 2 | 3 | Copyright (c) 2014 Sami Barakat 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | -------------------------------------------------------------------------------- /tests/test_printignored.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | from tests.helper import CopyArtifactsTestCase, capture_log 5 | from beets import config 6 | 7 | class CopyArtifactsPrintIgnoredTest(CopyArtifactsTestCase): 8 | """ 9 | Tests to check print ignored files functionality and configuration. 10 | """ 11 | def setUp(self): 12 | super(CopyArtifactsPrintIgnoredTest, self).setUp() 13 | 14 | self._create_flat_import_dir() 15 | self._setup_import_session(autotag=False) 16 | 17 | def test_do_not_print_ignored_by_default(self): 18 | config['copyartifacts']['extensions'] = '.file' 19 | 20 | with capture_log() as logs: 21 | self._run_importer() 22 | 23 | self.assert_not_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file2') 24 | 25 | # check output log 26 | logs = [line for line in logs if line.startswith('copyartifacts:')] 27 | self.assertEqual(logs, []) 28 | 29 | def test_print_ignored(self): 30 | config['copyartifacts']['print_ignored'] = True 31 | config['copyartifacts']['extensions'] = '.file' 32 | 33 | with capture_log() as logs: 34 | self._run_importer() 35 | 36 | self.assert_not_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file2') 37 | 38 | # check output log 39 | logs = [line for line in logs if line.startswith('copyartifacts:')] 40 | self.assertEqual(logs, [ 41 | 'copyartifacts: Ignored files:', 42 | 'copyartifacts: artifact.file2', 43 | ]) 44 | 45 | -------------------------------------------------------------------------------- /tests/test_filename.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | from tests.helper import CopyArtifactsTestCase 5 | import beets 6 | from beets import config 7 | 8 | class CopyArtifactsFilename(CopyArtifactsTestCase): 9 | """ 10 | Tests to check handling of artifacts with filenames containing unicode characters 11 | """ 12 | def setUp(self): 13 | super(CopyArtifactsFilename, self).setUp() 14 | 15 | self._set_import_dir() 16 | self.album_path = os.path.join(self.import_dir, b'the_album') 17 | os.makedirs(self.album_path) 18 | 19 | self._setup_import_session(autotag=False) 20 | 21 | config['copyartifacts']['extensions'] = '.file' 22 | 23 | def test_import_dir_with_unicode_character_in_artifact_name_copy(self): 24 | open(os.path.join(self.album_path, beets.util.bytestring_path(u'\xe4rtifact.file')), 'a').close() 25 | medium = self._create_medium(os.path.join(self.album_path, b'track_1.mp3'), b'full.mp3') 26 | self.import_media = [medium] 27 | 28 | self._run_importer() 29 | 30 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', beets.util.bytestring_path(u'\xe4rtifact.file')) 31 | 32 | def test_import_dir_with_unicode_character_in_artifact_name_move(self): 33 | config['import']['move'] = True 34 | 35 | open(os.path.join(self.album_path, beets.util.bytestring_path(u'\xe4rtifact.file')), 'a').close() 36 | medium = self._create_medium(os.path.join(self.album_path, b'track_1.mp3'), b'full.mp3') 37 | self.import_media = [medium] 38 | 39 | self._run_importer() 40 | 41 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', beets.util.bytestring_path(u'\xe4rtifact.file')) 42 | 43 | def test_import_dir_with_illegal_character_in_album_name(self): 44 | config['paths']['ext:file'] = str('$albumpath/$artist - $album') 45 | 46 | # Create import directory, illegal filename character used in the album name 47 | open(os.path.join(self.album_path, b'artifact.file'), 'a').close() 48 | medium = self._create_medium(os.path.join(self.album_path, b'track_1.mp3'), 49 | b'full.mp3', 50 | b'Tag Album?') 51 | self.import_media = [medium] 52 | 53 | self._run_importer() 54 | 55 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album_', b'Tag Artist - Tag Album_.file') 56 | 57 | -------------------------------------------------------------------------------- /tests/test_flatdirectory.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | 4 | from tests.helper import CopyArtifactsTestCase 5 | from beets import config 6 | 7 | class CopyArtifactsFromFlatDirectoryTest(CopyArtifactsTestCase): 8 | """ 9 | Tests to check that copyartifacts copies or moves artifact files from a flat directory. 10 | i.e. all songs in an album are imported from a single directory 11 | Also tests extensions config option 12 | """ 13 | def setUp(self): 14 | super(CopyArtifactsFromFlatDirectoryTest, self).setUp() 15 | 16 | self._create_flat_import_dir() 17 | self._setup_import_session(autotag=False) 18 | 19 | def test_only_copy_artifacts_matching_configured_extension(self): 20 | config['copyartifacts']['extensions'] = '.file' 21 | 22 | self._run_importer() 23 | 24 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file') 25 | self.assert_not_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file2') 26 | 27 | def test_copy_all_artifacts_by_default(self): 28 | self._run_importer() 29 | 30 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file') 31 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file2') 32 | 33 | def test_copy_artifacts(self): 34 | self._run_importer() 35 | 36 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file') 37 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file2') 38 | 39 | def test_ignore_media_files(self): 40 | self._run_importer() 41 | 42 | self.assert_not_in_lib_dir(b'Tag Artist', b'Tag Album', b'track_1.mp3') 43 | 44 | def test_move_artifacts(self): 45 | config['import']['move'] = True 46 | 47 | self._run_importer() 48 | 49 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file') 50 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file2') 51 | self.assert_not_in_import_dir(b'the_album', b'artifact.file') 52 | self.assert_not_in_import_dir(b'the_album', b'artifact.file2') 53 | 54 | def test_prune_import_directory_when_emptied(self): 55 | """ 56 | Check that plugin does not interfere with normal 57 | pruning of emptied import directories. 58 | """ 59 | config['import']['move'] = True 60 | 61 | self._run_importer() 62 | 63 | self.assert_not_in_import_dir(b'the_album') 64 | 65 | def test_do_nothing_when_not_copying_or_moving(self): 66 | """ 67 | Check that plugin leaves everthing alone when not 68 | copying (-C command line option) and not moving. 69 | """ 70 | config['import']['copy'] = False 71 | config['import']['move'] = False 72 | 73 | self._run_importer() 74 | 75 | self.assert_number_of_files_in_dir(3, self.import_dir, b'the_album') 76 | self.assert_in_import_dir(b'the_album', b'artifact.file') 77 | self.assert_in_import_dir(b'the_album', b'artifact.file2') 78 | 79 | def test_rename_when_copying(self): 80 | config['copyartifacts']['extensions'] = '.file' 81 | config['paths']['ext:file'] = str('$albumpath/$artist - $album') 82 | 83 | self._run_importer() 84 | 85 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'Tag Artist - Tag Album.file') 86 | self.assert_in_import_dir(b'the_album', b'artifact.file') 87 | 88 | def test_rename_when_moving(self): 89 | config['copyartifacts']['extensions'] = '.file' 90 | config['paths']['ext:file'] = str('$albumpath/$artist - $album') 91 | config['import']['move'] = True 92 | 93 | self._run_importer() 94 | 95 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'Tag Artist - Tag Album.file') 96 | self.assert_not_in_import_dir(b'the_album', b'artifact.file') 97 | 98 | -------------------------------------------------------------------------------- /README.rst: -------------------------------------------------------------------------------- 1 | 2 | THIS BEETS PLUGIN IS NO LONGER BEING MAINTAINED 3 | 4 | I no longer have time to maintain this plugin. Thank you to all those involved for their contributions. 5 | 6 | Some alternatives have been described on `issue #31 `_, notably: 7 | 8 | * `beets-copyartifacts3 `_ - a fork by Adam Miller which includes Python 3 fixes 9 | * `beets-extrafiles `_ - an entirely new plugin for managing files 10 | 11 | 12 | copyartifacts plugin for beets 13 | ============================== 14 | 15 | .. image:: https://travis-ci.org/sbarakat/beets-copyartifacts.svg?branch=master 16 | :target: https://travis-ci.org/sbarakat/beets-copyartifacts 17 | 18 | A plugin that moves non-music files during the import process. 19 | 20 | This is a plugin for `beets `__: a music 21 | library manager and much more. 22 | 23 | Installing 24 | ---------- 25 | 26 | Stable 27 | ~~~~~~ 28 | 29 | The stable version of the plugin is available from PyPI. Installation can be done using pip: 30 | 31 | :: 32 | 33 | pip install beets-copyartifacts 34 | 35 | If you get permission errors try running it with ``sudo`` 36 | 37 | Development 38 | ~~~~~~~~~~~ 39 | 40 | The development version can be installed from GitHub by using these commands: 41 | 42 | :: 43 | 44 | git clone https://github.com/sbarakat/beets-copyartifacts.git 45 | cd beets-copyartifacts 46 | python setup.py install 47 | 48 | If you get permission errors try running it with ``sudo`` 49 | 50 | Configuration 51 | ------------- 52 | 53 | You will need to enable the plugin in beets' config.yaml 54 | 55 | :: 56 | 57 | plugins: copyartifacts 58 | 59 | It can copy files by file extenstion: 60 | 61 | :: 62 | 63 | copyartifacts: 64 | extensions: .cue .log 65 | 66 | Or copy all non-music files (it does this by default): 67 | 68 | :: 69 | 70 | copyartifacts: 71 | extensions: .* 72 | 73 | It can also print what got left: 74 | 75 | :: 76 | 77 | copyartifacts: 78 | print_ignored: yes 79 | 80 | Renaming files 81 | ~~~~~~~~~~~~~~ 82 | 83 | Renaming works in much the same way as beets `Path 84 | Formats `__ 85 | with the following limitations: - The fields available are ``$artist``, 86 | ``$albumartist``, ``$album`` and ``$albumpath``. - The full set of 87 | `built in 88 | functions `__ 89 | are also supported, with the exception of ``%aunique`` - which will 90 | return an empty string. 91 | 92 | Each template string uses a query syntax for each of the file 93 | extensions. For example the following template string will be applied to 94 | ``.log`` files: 95 | 96 | :: 97 | 98 | paths: 99 | ext:log: $albumpath/$artist - $album 100 | 101 | This will rename a log file to: 102 | ``~/Music/Artist/2014 - Album/Artist - Album.log`` 103 | 104 | Example config 105 | ~~~~~~~~~~~~~~ 106 | 107 | :: 108 | 109 | plugins: copyartifacts 110 | 111 | paths: 112 | default: $albumartist/$year - $album/$track - $title 113 | singleton: Singletons/$artist - $title 114 | ext:log: $albumpath/$artist - $album 115 | ext:cue: $albumpath/$artist - $album 116 | ext:jpg: $albumpath/cover 117 | 118 | copyartifacts: 119 | extensions: .cue .log .jpg 120 | print_ignored: yes 121 | 122 | Thanks 123 | ------ 124 | 125 | copyartifacts was built on top of the hard work already done by Adrian 126 | Sampson and the larger community on 127 | `beets `__. We have also benefited from the 128 | work of our 129 | `contributors `__. 130 | 131 | This plugin was built out of necessity and to scratch an itch. It has 132 | gained a bit of attention, so I intend to maintain it where I can, 133 | however I doubt I will be able to spend large amount of time on it. 134 | Please report any issues you may have and feel free to contribute. 135 | 136 | License 137 | ------- 138 | 139 | Copyright (c) 2015-2017 Sami Barakat 140 | 141 | Licensed under the `MIT 142 | license `__. 143 | -------------------------------------------------------------------------------- /tests/_common.py: -------------------------------------------------------------------------------- 1 | import sys 2 | import os 3 | import shutil 4 | import unittest 5 | import tempfile 6 | 7 | import beets 8 | from beets import util 9 | from beets import logging 10 | 11 | # Test resources path. 12 | RSRC = util.bytestring_path(os.path.join(os.path.dirname(__file__), 'rsrc')) 13 | 14 | # Propagate to root logger so nosetest can capture it 15 | log = logging.getLogger('beets') 16 | log.propagate = True 17 | log.setLevel(logging.DEBUG) 18 | 19 | class Assertions(object): 20 | """A mixin with additional unit test assertions.""" 21 | 22 | def assertExists(self, path): # noqa 23 | self.assertTrue(os.path.exists(util.syspath(path)), 24 | u'file does not exist: {!r}'.format(path)) 25 | 26 | def assertNotExists(self, path): # noqa 27 | self.assertFalse(os.path.exists(util.syspath(path)), 28 | u'file exists: {!r}'.format((path))) 29 | 30 | def assert_equal_path(self, a, b): 31 | """Check that two paths are equal.""" 32 | self.assertEqual(util.normpath(a), util.normpath(b), 33 | u'paths are not equal: {!r} and {!r}'.format(a, b)) 34 | 35 | 36 | # A test harness for all beets tests. 37 | # Provides temporary, isolated configuration. 38 | class TestCase(unittest.TestCase, Assertions): 39 | """A unittest.TestCase subclass that saves and restores beets' 40 | global configuration. This allows tests to make temporary 41 | modifications that will then be automatically removed when the test 42 | completes. Also provides some additional assertion methods, a 43 | temporary directory, and a DummyIO. 44 | """ 45 | def setUp(self): 46 | # A "clean" source list including only the defaults. 47 | beets.config.sources = [] 48 | beets.config.read(user=False, defaults=True) 49 | 50 | # Direct paths to a temporary directory. Tests can also use this 51 | # temporary directory. 52 | self.temp_dir = util.bytestring_path(tempfile.mkdtemp()) 53 | 54 | beets.config['statefile'] = \ 55 | util.py3_path(os.path.join(self.temp_dir, b'state.pickle')) 56 | beets.config['library'] = \ 57 | util.py3_path(os.path.join(self.temp_dir, b'library.db')) 58 | beets.config['directory'] = \ 59 | util.py3_path(os.path.join(self.temp_dir, b'libdir')) 60 | 61 | # Set $HOME, which is used by confit's `config_dir()` to create 62 | # directories. 63 | self._old_home = os.environ.get('HOME') 64 | os.environ['HOME'] = util.py3_path(self.temp_dir) 65 | 66 | # Initialize, but don't install, a DummyIO. 67 | self.io = DummyIO() 68 | 69 | def tearDown(self): 70 | if os.path.isdir(self.temp_dir): 71 | shutil.rmtree(self.temp_dir) 72 | if self._old_home is None: 73 | del os.environ['HOME'] 74 | else: 75 | os.environ['HOME'] = self._old_home 76 | self.io.restore() 77 | 78 | beets.config.clear() 79 | beets.config._materialized = False 80 | 81 | 82 | 83 | # Mock I/O. 84 | 85 | class InputException(Exception): 86 | def __init__(self, output=None): 87 | self.output = output 88 | 89 | def __str__(self): 90 | msg = "Attempt to read with no input provided." 91 | if self.output is not None: 92 | msg += " Output: {!r}".format(self.output) 93 | return msg 94 | 95 | 96 | class DummyOut(object): 97 | encoding = 'utf-8' 98 | 99 | def __init__(self): 100 | self.buf = [] 101 | 102 | def write(self, s): 103 | self.buf.append(s) 104 | 105 | def get(self): 106 | if six.PY2: 107 | return b''.join(self.buf) 108 | else: 109 | return ''.join(self.buf) 110 | 111 | def flush(self): 112 | self.clear() 113 | 114 | def clear(self): 115 | self.buf = [] 116 | 117 | class DummyIn(object): 118 | encoding = 'utf-8' 119 | 120 | def __init__(self, out=None): 121 | self.buf = [] 122 | self.reads = 0 123 | self.out = out 124 | 125 | def add(self, s): 126 | if six.PY2: 127 | self.buf.append(s + b'\n') 128 | else: 129 | self.buf.append(s + '\n') 130 | 131 | def readline(self): 132 | if not self.buf: 133 | if self.out: 134 | raise InputException(self.out.get()) 135 | else: 136 | raise InputException() 137 | self.reads += 1 138 | return self.buf.pop(0) 139 | 140 | class DummyIO(object): 141 | """Mocks input and output streams for testing UI code.""" 142 | def __init__(self): 143 | self.stdout = DummyOut() 144 | self.stdin = DummyIn(self.stdout) 145 | 146 | def addinput(self, s): 147 | self.stdin.add(s) 148 | 149 | def getoutput(self): 150 | res = self.stdout.get() 151 | self.stdout.clear() 152 | return res 153 | 154 | def readcount(self): 155 | return self.stdin.reads 156 | 157 | def install(self): 158 | sys.stdin = self.stdin 159 | sys.stdout = self.stdout 160 | 161 | def restore(self): 162 | sys.stdin = sys.__stdin__ 163 | sys.stdout = sys.__stdout__ 164 | 165 | 166 | -------------------------------------------------------------------------------- /tests/test_reimport.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import unittest 4 | 5 | from tests.helper import CopyArtifactsTestCase 6 | from beets import config 7 | 8 | import logging 9 | log = logging.getLogger("beets") 10 | 11 | class CopyArtifactsReimportTest(CopyArtifactsTestCase): 12 | """ 13 | Tests to check that copyartifacts handles reimports correctly 14 | """ 15 | def setUp(self): 16 | """ 17 | Setup an import directory of the following structure: 18 | 19 | testlib_dir/ 20 | Tag Artist/ 21 | Tag Album/ 22 | Tag Title 1.mp3 23 | artifact.file 24 | """ 25 | super(CopyArtifactsReimportTest, self).setUp() 26 | 27 | self._create_flat_import_dir() 28 | self._setup_import_session(autotag=False) 29 | 30 | config['copyartifacts']['extensions'] = u'.file' 31 | 32 | log.debug('--- initial import') 33 | self._run_importer() 34 | 35 | def test_reimport_artifacts_with_copy(self): 36 | # Cause files to relocate when reimported 37 | self.lib.path_formats[0] = ('default', os.path.join('1$artist', '$album', '$title')) 38 | self._setup_import_session(autotag=False, 39 | import_dir=self.lib_dir) 40 | 41 | log.debug('--- second import') 42 | self._run_importer() 43 | 44 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file') 45 | self.assert_in_lib_dir(b'1Tag Artist', b'Tag Album', b'artifact.file') 46 | 47 | def test_reimport_artifacts_with_move(self): 48 | # Cause files to relocate when reimported 49 | self.lib.path_formats[0] = ('default', os.path.join('1$artist', '$album', '$title')) 50 | self._setup_import_session(autotag=False, 51 | import_dir=self.lib_dir, 52 | move=True) 53 | 54 | log.debug('--- second import') 55 | self._run_importer() 56 | 57 | self.assert_not_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file') 58 | self.assert_in_lib_dir(b'1Tag Artist', b'Tag Album', b'artifact.file') 59 | 60 | def test_prune_empty_directories_with_copy_import(self): 61 | """ 62 | No directories are pruned when importing with 'copy'. Test is 63 | identical to test_reimport_artifacts_with_copy, included for 64 | completeness. 65 | """ 66 | # Cause files to relocate when reimported 67 | self.lib.path_formats[0] = ('default', os.path.join('1$artist', '$album', '$title')) 68 | self._setup_import_session(autotag=False, 69 | import_dir=self.lib_dir) 70 | 71 | log.debug('--- second import') 72 | self._run_importer() 73 | 74 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file') 75 | self.assert_in_lib_dir(b'1Tag Artist', b'Tag Album', b'artifact.file') 76 | 77 | @unittest.skip('Failing') 78 | def test_prune_empty_directories_with_move_import(self): 79 | # Cause files to relocate when reimported 80 | self.lib.path_formats[0] = ('default', os.path.join('1$artist', '$album', '$title')) 81 | self._setup_import_session(autotag=False, 82 | import_dir=self.lib_dir, 83 | move=True) 84 | 85 | log.debug('--- second import') 86 | self._run_importer() 87 | 88 | self.assert_not_in_lib_dir(b'Tag Artist') 89 | self.assert_in_lib_dir(b'1Tag Artist', b'Tag Album', b'artifact.file') 90 | 91 | def test_do_nothing_when_paths_do_not_change_with_copy_import(self): 92 | self._setup_import_session(autotag=False, 93 | import_dir=self.lib_dir) 94 | 95 | log.debug('--- second import') 96 | self._run_importer() 97 | 98 | self.assert_number_of_files_in_dir(2, self.lib_dir, b'Tag Artist', b'Tag Album') 99 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file') 100 | 101 | def test_do_nothing_when_paths_do_not_change_with_move_import(self): 102 | self._setup_import_session(autotag=False, 103 | import_dir=self.lib_dir, 104 | move=True) 105 | 106 | log.debug('--- second import') 107 | self._run_importer() 108 | 109 | self.assert_number_of_files_in_dir(2, self.lib_dir, b'Tag Artist', b'Tag Album') 110 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file') 111 | 112 | def test_rename_with_copy_import(self): 113 | config['paths']['ext:file'] = str(os.path.join('$albumpath', '$artist - $album')) 114 | self._setup_import_session(autotag=False, 115 | import_dir=self.lib_dir) 116 | 117 | log.debug('--- second import') 118 | self._run_importer() 119 | 120 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file') 121 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'Tag Artist - Tag Album.file') 122 | 123 | def test_rename_with_move_import(self): 124 | config['paths']['ext:file'] = str(os.path.join('$albumpath', '$artist - $album')) 125 | self._setup_import_session(autotag=False, 126 | import_dir=self.lib_dir, 127 | move=True) 128 | 129 | log.debug('--- second import') 130 | self._run_importer() 131 | 132 | self.assert_not_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file') 133 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'Tag Artist - Tag Album.file') 134 | 135 | def test_rename_when_paths_do_not_change(self): 136 | """ 137 | This test considers the situation where the path format for a file extension 138 | is changed and files already in the library are reimported and renamed to 139 | reflect the change 140 | """ 141 | config['paths']['ext:file'] = str(os.path.join('$albumpath', '$album')) 142 | self._setup_import_session(autotag=False, 143 | import_dir=self.lib_dir, 144 | move=True) 145 | 146 | log.debug('--- second import') 147 | self._run_importer() 148 | 149 | self.assert_not_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file') 150 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'Tag Album.file') 151 | 152 | @unittest.skip('Todo') 153 | def test_multiple_reimport_artifacts_with_move(self): 154 | # Cause files to relocate when reimported 155 | #self.lib.path_formats[0] = ('default', os.path.join('1$artist', '$album', '$title')) 156 | config['paths']['ext:file'] = str(os.path.join('$albumpath', '$album')) 157 | self._setup_import_session(autotag=False, 158 | import_dir=self.lib_dir, 159 | move=True) 160 | 161 | album_path = os.path.join(self.lib_dir, b'Tag Artist', b'Tag Album') 162 | log.debug('@@@@@@@@@@@@@@') 163 | log.debug(album_path) 164 | open(os.path.join(album_path, b'artifact2.file'), 'a').close() 165 | 166 | log.debug('--- second import') 167 | self._run_importer() 168 | 169 | self.assert_not_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file') 170 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'Tag Album.file') 171 | 172 | log.debug('--- third import') 173 | self._run_importer() 174 | 175 | self.assert_not_in_lib_dir(b'Tag Artist', b'Tag Album', b'artifact.file') 176 | self.assert_in_lib_dir(b'Tag Artist', b'Tag Album', b'Tag Album.file') 177 | 178 | -------------------------------------------------------------------------------- /beetsplug/copyartifacts.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import filecmp 4 | 5 | import beets.util 6 | from beets import config 7 | from beets.ui import get_path_formats 8 | from beets.mediafile import TYPES 9 | from beets.plugins import BeetsPlugin 10 | from beets.library import DefaultTemplateFunctions 11 | from beets.util.functemplate import Template 12 | 13 | __version__ = '0.1.2' 14 | __author__ = 'Sami Barakat ' 15 | 16 | class CopyArtifactsPlugin(BeetsPlugin): 17 | def __init__(self): 18 | super(CopyArtifactsPlugin, self).__init__() 19 | 20 | self.config.add({ 21 | 'extensions': '.*', 22 | 'print_ignored': False 23 | }) 24 | 25 | self._process_queue = [] 26 | self._dirs_seen = [] 27 | 28 | self.extensions = self.config['extensions'].as_str_seq() 29 | self.print_ignored = self.config['print_ignored'].get() 30 | 31 | self.path_formats = [c for c in beets.ui.get_path_formats() if c[0][:4] == u'ext:'] 32 | 33 | self.register_listener('item_moved', self.collect_artifacts) 34 | self.register_listener('item_copied', self.collect_artifacts) 35 | self.register_listener('cli_exit', self.process_events) 36 | 37 | def _destination(self, filename, mapping): 38 | '''Returns a destination path a file should be moved to. The filename 39 | is unique to ensure files aren't overwritten. This also checks the 40 | config for path formats based on file extension allowing the use of 41 | beets' template functions. If no path formats are found for the file 42 | extension the original filename is used with the album path. 43 | - ripped from beets/library.py 44 | ''' 45 | file_ext = os.path.splitext(filename)[1] 46 | 47 | for query, path_format in self.path_formats: 48 | query_ext = '.' + query[4:] 49 | if query_ext == file_ext.decode('utf8'): 50 | break 51 | else: 52 | # No query matched; use original filename 53 | file_path = os.path.join(mapping['albumpath'], 54 | beets.util.displayable_path(filename)) 55 | return file_path 56 | 57 | if isinstance(path_format, Template): 58 | subpath_tmpl = path_format 59 | else: 60 | subpath_tmpl = Template(path_format) 61 | 62 | # Get template funcs and evaluate against mapping 63 | funcs = DefaultTemplateFunctions().functions() 64 | file_path = subpath_tmpl.substitute(mapping, funcs) + file_ext.decode('utf8') 65 | 66 | # Sanitize filename 67 | filename = beets.util.sanitize_path(os.path.basename(file_path)) 68 | dirname = os.path.dirname(file_path) 69 | file_path = os.path.join(dirname, filename) 70 | 71 | return file_path 72 | 73 | # XXX: may be better to use FormattedMapping class from beets/dbcore/db.py 74 | def _get_formatted(self, value): 75 | '''Replace path separators in value 76 | - ripped from beets/dbcore/db.py 77 | ''' 78 | sep_repl = beets.config['path_sep_replace'].as_str() 79 | for sep in (os.path.sep, os.path.altsep): 80 | if sep: 81 | value = value.replace(sep, sep_repl) 82 | 83 | return value 84 | 85 | def _generate_mapping(self, item, album_path): 86 | mapping = { 87 | 'artist': item.artist or u'None', 88 | 'albumartist': item.albumartist or u'None', 89 | 'album': item.album or u'None', 90 | } 91 | for key in mapping: 92 | mapping[key] = self._get_formatted(mapping[key]) 93 | 94 | mapping['albumpath'] = beets.util.displayable_path(album_path) 95 | 96 | return mapping 97 | 98 | def collect_artifacts(self, item, source, destination): 99 | source_path = os.path.dirname(source) 100 | dest_path = os.path.dirname(destination) 101 | 102 | # Check if this path has already been processed 103 | if source_path in self._dirs_seen: 104 | return 105 | 106 | non_handled_files = [] 107 | for root, dirs, files in beets.util.sorted_walk( 108 | source_path, ignore=config['ignore'].as_str_seq()): 109 | for filename in files: 110 | source_file = os.path.join(root, filename) 111 | 112 | # Skip any files extensions handled by beets 113 | file_ext = os.path.splitext(filename)[1] 114 | if len(file_ext) > 1 and file_ext.decode('utf8')[1:] in TYPES: 115 | continue 116 | 117 | non_handled_files.append(source_file) 118 | 119 | self._process_queue.extend([{ 120 | 'files': non_handled_files, 121 | 'mapping': self._generate_mapping(item, dest_path) 122 | }]) 123 | self._dirs_seen.extend([source_path]) 124 | 125 | def process_events(self): 126 | for item in self._process_queue: 127 | self.process_artifacts(item['files'], item['mapping'], False) 128 | 129 | def process_artifacts(self, source_files, mapping, reimport=False): 130 | if len(source_files) == 0: 131 | return 132 | 133 | ignored_files = [] 134 | source_path = os.path.dirname(source_files[0]) 135 | 136 | for source_file in source_files: 137 | # os.path.basename() not suitable here as files may be contained 138 | # within dir of source_path 139 | filename = source_file[len(source_path)+1:] 140 | 141 | dest_file = self._destination(filename, mapping) 142 | 143 | # Skip as another plugin or beets has already moved this file 144 | if not os.path.exists(source_file): 145 | ignored_files.append(source_file) 146 | continue 147 | 148 | # Skip extensions not handled by plugin 149 | file_ext = os.path.splitext(filename)[1] 150 | if ('.*' not in self.extensions 151 | and file_ext.decode('utf8') not in self.extensions): 152 | ignored_files.append(source_file) 153 | continue 154 | 155 | # Skip file if it already exists in dest 156 | if (os.path.exists(dest_file) 157 | and filecmp.cmp(source_file, dest_file)): 158 | ignored_files.append(source_file) 159 | continue 160 | 161 | dest_file = beets.util.unique_path(dest_file) 162 | beets.util.mkdirall(dest_file) 163 | dest_file = beets.util.bytestring_path(dest_file) 164 | 165 | # TODO: detect if beets was called with 'move' and override config 166 | # option here 167 | 168 | if config['import']['move']: 169 | self._move_artifact(source_file, dest_file) 170 | else: 171 | if reimport: 172 | # This is a reimport 173 | # files are already in the library directory 174 | self._move_artifact(source_file, dest_file) 175 | else: 176 | # A normal import, just copy 177 | self._copy_artifact(source_file, dest_file) 178 | 179 | 180 | if self.print_ignored and ignored_files: 181 | self._log.warning(u'Ignored files:') 182 | for f in ignored_files: 183 | self._log.warning(' {0}', os.path.basename(f)) 184 | 185 | def _copy_artifact(self, source_file, dest_file): 186 | self._log.info(u'Copying artifact: {0}'.format(os.path.basename(dest_file.decode('utf8')))) 187 | beets.util.copy(source_file, dest_file) 188 | 189 | def _move_artifact(self, source_file, dest_file): 190 | if not os.path.exists(source_file): 191 | # Sanity check for other plugins moving files 192 | return 193 | 194 | self._log.info(u'Moving artifact: {0}'.format(os.path.basename(dest_file.decode('utf8')))) 195 | beets.util.move(source_file, dest_file) 196 | 197 | dir_path = os.path.split(source_file)[0] 198 | beets.util.prune_dirs(dir_path, clutter=config['clutter'].as_str_seq()) 199 | 200 | -------------------------------------------------------------------------------- /tests/helper.py: -------------------------------------------------------------------------------- 1 | import os 2 | import sys 3 | import six 4 | import shutil 5 | from contextlib import contextmanager 6 | from enum import Enum 7 | 8 | import tests._common as _common 9 | 10 | from beets import util 11 | from beets import library 12 | from beets import importer 13 | from beets import mediafile 14 | from beets import config 15 | from beets import plugins 16 | 17 | # Make sure the development versions of the plugins are used 18 | import beetsplug # noqa: E402 19 | beetsplug.__path__ = [os.path.abspath( 20 | os.path.join(__file__, '..', '..', 'beetsplug') 21 | )] 22 | 23 | from beetsplug import copyartifacts 24 | 25 | import logging 26 | log = logging.getLogger("beets") 27 | 28 | 29 | class LogCapture(logging.Handler): 30 | 31 | def __init__(self): 32 | logging.Handler.__init__(self) 33 | self.messages = [] 34 | 35 | def emit(self, record): 36 | self.messages.append(six.text_type(record.msg)) 37 | 38 | 39 | @contextmanager 40 | def capture_log(logger='beets'): 41 | capture = LogCapture() 42 | log = logging.getLogger(logger) 43 | log.addHandler(capture) 44 | try: 45 | yield capture.messages 46 | finally: 47 | log.removeHandler(capture) 48 | 49 | 50 | 51 | class CopyArtifactsTestCase(_common.TestCase): 52 | """ 53 | Provides common setup and teardown, a convenience method for exercising the 54 | plugin/importer, tools to setup a library, a directory containing files 55 | that are to be imported and an import session. The class also provides stubs 56 | for the autotagging library and assertions helpers. 57 | """ 58 | def setUp(self): 59 | super(CopyArtifactsTestCase, self).setUp() 60 | 61 | plugins._classes = set([copyartifacts.CopyArtifactsPlugin]) 62 | 63 | self._setup_library() 64 | 65 | # Install the DummyIO to capture anything directed to stdout 66 | self.io.install() 67 | 68 | def _run_importer(self): 69 | """ 70 | Create an instance of the plugin, run the importer, and 71 | remove/unregister the plugin instance so a new instance can 72 | be created when this method is run again. 73 | This is a convenience method that can be called to setup, exercise 74 | and teardown the system under test after setting any config options 75 | and before assertions are made regarding changes to the filesystem. 76 | """ 77 | # Setup 78 | # Create an instance of the plugin 79 | plugins.find_plugins() 80 | 81 | # Exercise 82 | # Run the importer 83 | self.importer.run() 84 | # Fake the occurence of the cli_exit event 85 | plugins.send('cli_exit', lib=self.lib) 86 | 87 | # Teardown 88 | if plugins._instances: 89 | classes = list(plugins._classes) 90 | 91 | # Unregister listners 92 | for event in classes[0].listeners: 93 | del classes[0].listeners[event][0] 94 | 95 | # Delete the plugin instance so a new one gets created for each test 96 | del plugins._instances[classes[0]] 97 | 98 | log.debug("--- library structure") 99 | self._list_files(self.lib_dir) 100 | 101 | def _setup_library(self): 102 | self.lib_db = os.path.join(self.temp_dir, b'testlib.blb') 103 | self.lib_dir = os.path.join(self.temp_dir, b'testlib_dir') 104 | 105 | os.mkdir(self.lib_dir) 106 | 107 | self.lib = library.Library(self.lib_db) 108 | self.lib.directory = self.lib_dir 109 | self.lib.path_formats = [ 110 | (u'default', os.path.join(u'$artist', u'$album', u'$title')), 111 | (u'singleton:true', os.path.join(u'singletons', u'$title')), 112 | (u'comp:true', os.path.join(u'compilations', u'$album', u'$title')), 113 | ] 114 | 115 | def _create_flat_import_dir(self): 116 | """ 117 | Creates a directory with media files and artifacts. 118 | Sets ``self.import_dir`` to the path of the directory. Also sets 119 | ``self.import_media`` to a list :class:`MediaFile` for all the media files in 120 | the directory. 121 | 122 | The directory has the following layout 123 | the_album/ 124 | track_1.mp3 125 | artifact.file 126 | artifact.file2 127 | """ 128 | self._set_import_dir() 129 | 130 | album_path = os.path.join(self.import_dir, b'the_album') 131 | os.makedirs(album_path) 132 | 133 | # Create artifact 134 | open(os.path.join(album_path, b'artifact.file'), 'a').close() 135 | open(os.path.join(album_path, b'artifact.file2'), 'a').close() 136 | 137 | medium = self._create_medium(os.path.join(album_path, b'track_1.mp3'), b'full.mp3') 138 | self.import_media = [medium] 139 | 140 | log.debug("--- import directory created") 141 | self._list_files(album_path) 142 | 143 | def _create_medium(self, path, resource_name, album=None): 144 | """ 145 | Creates and saves a media file object located at path using resource_name 146 | from the beets test resources directory as initial data 147 | """ 148 | 149 | resource_path = os.path.join(_common.RSRC, resource_name) 150 | 151 | metadata = { 152 | 'artist': 'Tag Artist', 153 | 'album': album or 'Tag Album', 154 | 'albumartist': None, 155 | 'mb_trackid': None, 156 | 'mb_albumid': None, 157 | 'comp': None 158 | } 159 | 160 | # Copy media file 161 | shutil.copy(resource_path, path) 162 | medium = mediafile.MediaFile(path) 163 | 164 | # Set metadata 165 | metadata['track'] = 1 166 | metadata['title'] = 'Tag Title 1' 167 | for attr in metadata: 168 | setattr(medium, attr, metadata[attr]) 169 | medium.save() 170 | 171 | return medium 172 | 173 | def _set_import_dir(self): 174 | """ 175 | Sets the import_dir and ensures that it is empty. 176 | """ 177 | self.import_dir = os.path.join(self.temp_dir, b'testsrcdir') 178 | if os.path.isdir(self.import_dir): 179 | shutil.rmtree(self.import_dir) 180 | 181 | def _create_nested_import_dir(self): 182 | """ 183 | Creates a directory with media files and artifacts nested in subdirectories. 184 | Sets ``self.import_dir`` to the path of the directory. Also sets 185 | ``self.import_media`` to a list :class:`MediaFile` for all the media files in 186 | the directory. 187 | 188 | The directory has the following layout 189 | the_album/ 190 | disc1/ 191 | track_1.mp3 192 | artifact1.file 193 | disc2/ 194 | track_1.mp3 195 | artifact2.file 196 | """ 197 | 198 | def _setup_import_session(self, import_dir=None, 199 | delete=False, threaded=False, copy=True, 200 | singletons=False, move=False, autotag=True): 201 | config['import']['copy'] = copy 202 | config['import']['delete'] = delete 203 | config['import']['timid'] = True 204 | config['threaded'] = False 205 | config['import']['singletons'] = singletons 206 | config['import']['move'] = move 207 | config['import']['autotag'] = autotag 208 | config['import']['resume'] = False 209 | 210 | self.importer = TestImportSession(self.lib, 211 | loghandler=None, 212 | paths=[import_dir or self.import_dir], 213 | query=None) 214 | 215 | def _list_files(self, startpath): 216 | path = startpath.decode('utf8') 217 | for root, dirs, files in os.walk(path): 218 | level = root.replace(path, '').count(os.sep) 219 | indent = u' ' * 4 * (level) 220 | log.debug(u'{}{}/'.format(indent, os.path.basename(root))) 221 | subindent = u' ' * 4 * (level + 1) 222 | for f in files: 223 | log.debug(u'{}{}'.format(subindent, f)) 224 | 225 | def assert_in_lib_dir(self, *segments): 226 | """ 227 | Join the ``segments`` and assert that this path exists in the library 228 | directory 229 | """ 230 | self.assertExists(os.path.join(self.lib_dir, *segments)) 231 | 232 | def assert_not_in_lib_dir(self, *segments): 233 | """ 234 | Join the ``segments`` and assert that this path does not exist in 235 | the library directory 236 | """ 237 | self.assertNotExists(os.path.join(self.lib_dir, *segments)) 238 | 239 | def assert_in_import_dir(self, *segments): 240 | """ 241 | Join the ``segments`` and assert that this path exists in the import 242 | directory 243 | """ 244 | self.assertExists(os.path.join(self.import_dir, *segments)) 245 | 246 | def assert_not_in_import_dir(self, *segments): 247 | """ 248 | Join the ``segments`` and assert that this path does not exist in 249 | the library directory 250 | """ 251 | self.assertNotExists(os.path.join(self.import_dir, *segments)) 252 | 253 | def assert_number_of_files_in_dir(self, count, *segments): 254 | """ 255 | Assert that there are ``count`` files in path formed by joining ``segments`` 256 | """ 257 | self.assertEqual(len([name for name in os.listdir(os.path.join(*segments))]), count) 258 | 259 | 260 | class TestImportSession(importer.ImportSession): 261 | """ImportSession that can be controlled programaticaly. 262 | 263 | >>> lib = Library(':memory:') 264 | >>> importer = TestImportSession(lib, paths=['/path/to/import']) 265 | >>> importer.add_choice(importer.action.SKIP) 266 | >>> importer.add_choice(importer.action.ASIS) 267 | >>> importer.default_choice = importer.action.APPLY 268 | >>> importer.run() 269 | 270 | This imports ``/path/to/import`` into `lib`. It skips the first 271 | album and imports thesecond one with metadata from the tags. For the 272 | remaining albums, the metadata from the autotagger will be applied. 273 | """ 274 | 275 | def __init__(self, *args, **kwargs): 276 | super(TestImportSession, self).__init__(*args, **kwargs) 277 | self._choices = [] 278 | self._resolutions = [] 279 | 280 | default_choice = importer.action.APPLY 281 | 282 | def add_choice(self, choice): 283 | self._choices.append(choice) 284 | 285 | def clear_choices(self): 286 | self._choices = [] 287 | 288 | def choose_match(self, task): 289 | try: 290 | choice = self._choices.pop(0) 291 | except IndexError: 292 | choice = self.default_choice 293 | 294 | if choice == importer.action.APPLY: 295 | return task.candidates[0] 296 | elif isinstance(choice, int): 297 | return task.candidates[choice - 1] 298 | else: 299 | return choice 300 | 301 | choose_item = choose_match 302 | 303 | Resolution = Enum('Resolution', 'REMOVE SKIP KEEPBOTH') 304 | 305 | default_resolution = 'REMOVE' 306 | 307 | def add_resolution(self, resolution): 308 | assert isinstance(resolution, self.Resolution) 309 | self._resolutions.append(resolution) 310 | 311 | def resolve_duplicate(self, task, found_duplicates): 312 | try: 313 | res = self._resolutions.pop(0) 314 | except IndexError: 315 | res = self.default_resolution 316 | 317 | if res == self.Resolution.SKIP: 318 | task.set_choice(importer.action.SKIP) 319 | elif res == self.Resolution.REMOVE: 320 | task.should_remove_duplicates = True 321 | 322 | --------------------------------------------------------------------------------