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

Early stage pipeline plugin functions #2814

Merged
merged 5 commits into from
Feb 22, 2018
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions beets/importer.py
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,8 @@ def run(self):
stages += [import_asis(self)]

# Plugin stages.
for stage_func in plugins.early_import_stages():
stages.append(plugin_stage(self, stage_func))
for stage_func in plugins.import_stages():
stages.append(plugin_stage(self, stage_func))

Expand Down
20 changes: 20 additions & 0 deletions beets/plugins.py
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ def __init__(self, name=None):
self.template_fields = {}
if not self.album_template_fields:
self.album_template_fields = {}
self.early_import_stages = []
self.import_stages = []

self._log = log.getChild(self.name)
Expand All @@ -94,6 +95,17 @@ def commands(self):
"""
return ()

def get_early_import_stages(self):
"""Return a list of functions that should be called as importer
pipelines stages early in the pipeline.

The callables are wrapped versions of the functions in
`self.early_import_stages`. Wrapping provides some bookkeeping for the
plugin: specifically, the logging level is adjusted to WARNING.
"""
return [self._set_log_level_and_params(logging.WARNING, import_stage)
for import_stage in self.early_import_stages]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perhaps the logging wrapper code (here and in the function below) can be factored out into a helper function?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sure.


def get_import_stages(self):
"""Return a list of functions that should be called as importer
pipelines stages.
Expand Down Expand Up @@ -393,6 +405,14 @@ def template_funcs():
return funcs


def early_import_stages():
"""Get a list of early import stage functions defined by plugins."""
stages = []
for plugin in find_plugins():
stages += plugin.get_early_import_stages()
return stages


def import_stages():
"""Get a list of import stage functions defined by plugins."""
stages = []
Expand Down
2 changes: 1 addition & 1 deletion beetsplug/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ def __init__(self):
u'copy_album_art': False,
u'album_art_maxwidth': 0,
})
self.import_stages = [self.auto_convert]
self.early_import_stages = [self.auto_convert]

self.register_listener('import_task_files', self._cleanup)

Expand Down