From af36d85ef834c73ef9324dc305b7c1a651b4733d Mon Sep 17 00:00:00 2001 From: Malte Ried Date: Sun, 21 Dec 2014 21:52:09 +0100 Subject: [PATCH] Implemented a better solution for the pretend flag Corrected the documentation (shortcut -e is not available any more) --- beets/importer.py | 63 +++++++++++++++++++++++------------------- docs/reference/cli.rst | 6 ++-- 2 files changed, 38 insertions(+), 31 deletions(-) diff --git a/beets/importer.py b/beets/importer.py index a2a12158c..0877b5508 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -277,20 +277,25 @@ class ImportSession(object): else: stages = [query_tasks(self)] - if self.config['group_albums'] and \ - not self.config['singletons']: - # Split directory tasks into one task for each album - stages += [group_albums(self)] - if self.config['autotag']: - # FIXME We should also resolve duplicates when not - # autotagging. This is currently handled in `user_query` - stages += [lookup_candidates(self), user_query(self)] + if self.config['pretend']: + # Only log the imported files and end the pipeline + stages += [log_files(self)] else: - stages += [import_asis(self)] - stages += [apply_choices(self)] - for stage_func in plugins.import_stages(): - stages.append(plugin_stage(self, stage_func)) - stages += [manipulate_files(self)] + if self.config['group_albums'] and \ + not self.config['singletons']: + # Split directory tasks into one task for each album + stages += [group_albums(self)] + if self.config['autotag']: + # FIXME We should also resolve duplicates when not + # autotagging. This is currently handled in `user_query` + stages += [lookup_candidates(self), user_query(self)] + else: + stages += [import_asis(self)] + stages += [apply_choices(self)] + + for stage_func in plugins.import_stages(): + stages.append(plugin_stage(self, stage_func)) + stages += [manipulate_files(self)] pl = pipeline.Pipeline(stages) # Run the pipeline. @@ -1096,24 +1101,15 @@ def read_tasks(session): task_factory = ImportTaskFactory(toppath, session) imported = False for t in task_factory.tasks(): - 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 + imported |= not t.skip + yield t # Indicate the directory is finished. # FIXME hack to delete extracted archives - if not session.config['pretend']: - if archive_task is None: - yield task_factory.sentinel() - else: - yield archive_task + if archive_task is None: + yield task_factory.sentinel() + else: + yield archive_task if not imported: log.warn(u'No files imported from {0}' @@ -1299,6 +1295,17 @@ def manipulate_files(session, task): task.finalize(session) +@pipeline.stage +def log_files(session, task): + """A coroutine (pipeline stage) to log each file which will be imported + """ + if isinstance(task, SingletonImportTask): + log.info(displayable_path(task.item['path'])) + elif task.items: + for item in task.items: + log.info(displayable_path(item['path'])) + + def group_albums(session): """Group the items of a task by albumartist and album name and create a new task for each album. Yield the tasks as a multi message. diff --git a/docs/reference/cli.rst b/docs/reference/cli.rst index da5f0e04a..a11ed394e 100644 --- a/docs/reference/cli.rst +++ b/docs/reference/cli.rst @@ -48,7 +48,7 @@ import `````` :: - beet import [-CeWAPRqst] [-l LOGPATH] PATH... + beet import [-CWAPRqst] [-l LOGPATH] PATH... beet import [options] -L QUERY Add music to your library, attempting to get correct tags for it from @@ -128,8 +128,8 @@ Optional command flags: ``--group-albums`` option to split the files based on their metadata before matching them as separate albums. -* If you just want to know which files would be imported, you can use the ``-e`` - (or ``--pretend``) option. If set, beets will only print a list of file +* If you just want to know which files would be imported, you can use the + ``--pretend`` option. If set, beets will only print a list of file it will import when the option is removed and won't do anything else. .. _rarfile: https://pypi.python.org/pypi/rarfile/2.2