mirror of
https://github.com/beetbox/beets.git
synced 2026-01-30 12:02:41 +01:00
Reduced the count of accesses of the pretend config option. Now it's only one place where it is read.
Changed the output to use the log system rather than print_.
This commit is contained in:
parent
2db346388a
commit
440fe9a2ea
4 changed files with 50 additions and 29 deletions
|
|
@ -21,6 +21,7 @@ import:
|
|||
detail: no
|
||||
flat: no
|
||||
group_albums: no
|
||||
pretend: false
|
||||
|
||||
clutter: ["Thumbs.DB", ".DS_Store"]
|
||||
ignore: [".*", "*~", "System Volume Information"]
|
||||
|
|
|
|||
|
|
@ -34,7 +34,6 @@ from beets import dbcore
|
|||
from beets import plugins
|
||||
from beets import util
|
||||
from beets import config
|
||||
from beets.ui import print_
|
||||
from beets.util import pipeline, sorted_walk, ancestry
|
||||
from beets.util import syspath, normpath, displayable_path
|
||||
from enum import Enum
|
||||
|
|
@ -961,8 +960,6 @@ class ImportTaskFactory(object):
|
|||
self.toppath = toppath
|
||||
self.session = session
|
||||
self.skipped = 0
|
||||
self.pretend = session.config[
|
||||
'pretend'] if 'pretend' in session.config else False
|
||||
|
||||
def tasks(self):
|
||||
"""Yield all import tasks for `self.toppath`.
|
||||
|
|
@ -973,22 +970,15 @@ class ImportTaskFactory(object):
|
|||
for dirs, paths in self.paths():
|
||||
if self.session.config['singletons']:
|
||||
for path in paths:
|
||||
if self.pretend:
|
||||
print_(displayable_path(path))
|
||||
else:
|
||||
task = self.singleton(path)
|
||||
if task:
|
||||
yield task
|
||||
task = self.singleton(path)
|
||||
if task:
|
||||
yield task
|
||||
yield self.sentinel(dirs)
|
||||
|
||||
else:
|
||||
if self.pretend:
|
||||
for path in paths:
|
||||
print_(displayable_path(path))
|
||||
else:
|
||||
task = self.album(paths, dirs)
|
||||
if task:
|
||||
yield task
|
||||
task = self.album(paths, dirs)
|
||||
if task:
|
||||
yield task
|
||||
|
||||
def paths(self):
|
||||
"""Walk `self.toppath` and yield pairs of directory lists and
|
||||
|
|
@ -1106,18 +1096,26 @@ def read_tasks(session):
|
|||
task_factory = ImportTaskFactory(toppath, session)
|
||||
imported = False
|
||||
for t in task_factory.tasks():
|
||||
imported |= not t.skip
|
||||
yield t
|
||||
if session.config['pretend']:
|
||||
imported = True
|
||||
if isinstance(t, SingletonImportTask):
|
||||
log.info(displayable_path(t.item['path']))
|
||||
elif t.items:
|
||||
for item in t.items:
|
||||
log.info(displayable_path(item['path']))
|
||||
else:
|
||||
imported |= not t.skip
|
||||
yield t
|
||||
|
||||
# Indicate the directory is finished.
|
||||
# FIXME hack to delete extracted archives
|
||||
if not task_factory.pretend:
|
||||
if not session.config['pretend']:
|
||||
if archive_task is None:
|
||||
yield task_factory.sentinel()
|
||||
else:
|
||||
yield archive_task
|
||||
|
||||
if not imported and not task_factory.pretend:
|
||||
if not imported:
|
||||
log.warn(u'No files imported from {0}'
|
||||
.format(displayable_path(user_toppath)))
|
||||
|
||||
|
|
|
|||
|
|
@ -944,7 +944,7 @@ import_cmd.parser.add_option(
|
|||
help='group tracks in a folder into separate albums'
|
||||
)
|
||||
import_cmd.parser.add_option(
|
||||
'-e', '--pretend', dest='pretend', action='store_true',
|
||||
'--pretend', dest='pretend', action='store_true',
|
||||
help='only print files to import, but don\'t import'
|
||||
)
|
||||
import_cmd.func = import_func
|
||||
|
|
|
|||
|
|
@ -25,6 +25,7 @@ from mock import patch
|
|||
|
||||
import _common
|
||||
from _common import unittest
|
||||
from beets.util import displayable_path
|
||||
from helper import TestImportSession, TestHelper, has_program, capture_log
|
||||
from beets import importer
|
||||
from beets.importer import albums_in_dir
|
||||
|
|
@ -1533,6 +1534,11 @@ class ReimportTest(unittest.TestCase, ImportHelper):
|
|||
class ImportPretendTest(_common.TestCase, ImportHelper):
|
||||
""" Test the pretend commandline option
|
||||
"""
|
||||
|
||||
def __init__(self):
|
||||
super(ImportPretendTest, self).__init__()
|
||||
self.matcher = None
|
||||
|
||||
def setUp(self):
|
||||
super(ImportPretendTest, self).setUp()
|
||||
self.setup_beets()
|
||||
|
|
@ -1546,7 +1552,7 @@ class ImportPretendTest(_common.TestCase, ImportHelper):
|
|||
self.teardown_beets()
|
||||
self.matcher.restore()
|
||||
|
||||
def test_import_enumerate_only(self):
|
||||
def test_import_pretend(self):
|
||||
resource_path = os.path.join(_common.RSRC, u'empty.mp3')
|
||||
single_path = os.path.join(self.import_dir, u'track_2.mp3')
|
||||
|
||||
|
|
@ -1558,17 +1564,33 @@ class ImportPretendTest(_common.TestCase, ImportHelper):
|
|||
self._setup_import_session(singletons=True)
|
||||
self.importer.paths = import_files
|
||||
|
||||
self.importer.run()
|
||||
out = self.io.getoutput()
|
||||
with capture_log() as logs:
|
||||
self.importer.run()
|
||||
|
||||
self.assertEqual(len(self.lib.items()), 0)
|
||||
self.assertEqual(len(self.lib.albums()), 0)
|
||||
|
||||
lines = out.splitlines()
|
||||
self.assertEqual(len(lines), 2)
|
||||
self.assertEqual(lines[0], os.path.join(import_files[0],
|
||||
u'track_1.mp3'))
|
||||
self.assertEqual(lines[1], import_files[1])
|
||||
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):
|
||||
path = os.path.join(self.temp_dir, 'empty')
|
||||
os.makedirs(path)
|
||||
|
||||
self._setup_import_session(singletons=True)
|
||||
self.importer.paths = [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), 2)
|
||||
self.assertEqual(logs[1], 'No files imported from {0}'
|
||||
.format(displayable_path(path)))
|
||||
|
||||
|
||||
def suite():
|
||||
|
|
|
|||
Loading…
Reference in a new issue