Added a flag --detailed to get a more detailed output of the --pretend option.

This commit is contained in:
Malte Ried 2014-12-29 12:54:16 +01:00
parent a892128996
commit 5123a41258
5 changed files with 72 additions and 22 deletions

View file

@ -22,6 +22,7 @@ import:
flat: no
group_albums: no
pretend: false
detailed: false
clutter: ["Thumbs.DB", ".DS_Store"]
ignore: [".*", "*~", "System Volume Information"]

View file

@ -1299,9 +1299,16 @@ def manipulate_files(session, task):
def log_files(session, task):
"""A coroutine (pipeline stage) to log each file which will be imported
"""
detailed = config['import']['detailed'].get()
if isinstance(task, SingletonImportTask):
log.info(displayable_path(task.item['path']))
if detailed:
log.info(
'Singleton: {0}'.format(displayable_path(task.item['path'])))
else:
log.info(displayable_path(task.item['path']))
elif task.items:
if detailed:
log.info('Album {0}'.format(displayable_path(task.paths[0])))
for item in task.items:
log.info(displayable_path(item['path']))

View file

@ -947,6 +947,10 @@ import_cmd.parser.add_option(
'--pretend', dest='pretend', action='store_true',
help='just print the files to import'
)
import_cmd.parser.add_option(
'--detailed', dest='detailed', action='store_true',
help='use in conjunction with --pretend to get sophisticated output'
)
import_cmd.func = import_func
default_commands.append(import_cmd)

View file

@ -132,6 +132,10 @@ Optional command flags:
option. If set, beets will just print a list of files that it would
otherwise import.
* To get a more detailed output with the ``--pretend`` option, you can use the
``--detailed`` flag. This way you can see which tracks beets think should
belong to an album.
.. _rarfile: https://pypi.python.org/pypi/rarfile/2.2
.. only:: html

View file

@ -1542,7 +1542,8 @@ class ImportPretendTest(_common.TestCase, ImportHelper):
def setUp(self):
super(ImportPretendTest, self).setUp()
self.setup_beets()
self._create_import_dir(1)
self.__create_import_dir()
self.__create_empty_import_dir()
self._setup_import_session()
config['import']['pretend'] = True
self.matcher = AutotagStub().install()
@ -1552,35 +1553,31 @@ class ImportPretendTest(_common.TestCase, ImportHelper):
self.teardown_beets()
self.matcher.restore()
def test_import_pretend(self):
def __create_import_dir(self):
self._create_import_dir(1)
resource_path = os.path.join(_common.RSRC, u'empty.mp3')
single_path = os.path.join(self.import_dir, u'track_2.mp3')
shutil.copy(resource_path, single_path)
import_files = [
self.import_paths = [
os.path.join(self.import_dir, u'the_album'),
single_path
]
self._setup_import_session(singletons=True)
self.importer.paths = import_files
self.import_files = [
displayable_path(
os.path.join(self.import_paths[0], u'track_1.mp3')),
displayable_path(single_path)
]
with capture_log() as logs:
self.importer.run()
self.assertEqual(len(self.lib.items()), 0)
self.assertEqual(len(self.lib.albums()), 0)
self.assertEqual(len(logs), 3)
self.assertEqual(logs[1], os.path.join(import_files[0],
u'track_1.mp3'))
self.assertEqual(logs[2], import_files[1])
def test_import_pretend_empty(self):
def __create_empty_import_dir(self):
path = os.path.join(self.temp_dir, 'empty')
os.makedirs(path)
self.empty_path = path
self._setup_import_session(singletons=True)
self.importer.paths = [path]
def __run(self, import_paths, singletons=True, detailed=False):
config['import']['detailed'] = detailed
self._setup_import_session(singletons=singletons)
self.importer.paths = import_paths
with capture_log() as logs:
self.importer.run()
@ -1588,9 +1585,46 @@ class ImportPretendTest(_common.TestCase, ImportHelper):
self.assertEqual(len(self.lib.items()), 0)
self.assertEqual(len(self.lib.albums()), 0)
return logs
def test_import_pretend(self):
logs = self.__run(self.import_paths)
self.assertEqual(len(logs), 3)
self.assertEqual(logs[1], self.import_files[0])
self.assertEqual(logs[2], self.import_files[1])
def test_import_pretend_empty(self):
logs = self.__run([self.empty_path])
self.assertEqual(len(logs), 2)
self.assertEqual(logs[1], 'No files imported from {0}'
.format(displayable_path(path)))
.format(displayable_path(self.empty_path)))
def test_import_singletons_pretend_detailed(self):
logs = self.__run(self.import_paths, detailed=True)
self.assertEqual(len(logs), 3)
self.assertEqual(logs[1], 'Singleton: %s' % self.import_files[0])
self.assertEqual(logs[2], 'Singleton: %s' % self.import_paths[1])
def test_import_album_pretend_detailed(self):
logs = self.__run(self.import_paths, singletons=False, detailed=True)
self.assertEqual(len(logs), 5)
self.assertEqual(logs[1],
'Album %s' % displayable_path(self.import_paths[0]))
self.assertEqual(logs[2], self.import_files[0])
self.assertEqual(logs[3],
'Album %s' % displayable_path(self.import_paths[1]))
self.assertEqual(logs[4], self.import_paths[1])
def test_import_pretend_empty_detailed(self):
logs = self.__run([self.empty_path], detailed=True)
self.assertEqual(len(logs), 2)
self.assertEqual(logs[1], 'No files imported from {0}'
.format(displayable_path(self.empty_path)))
def suite():