From b140f249c146113e165078c40111a228f04e7a72 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michal=20Koutensk=C3=BD?= Date: Mon, 19 Feb 2018 10:45:47 +0100 Subject: [PATCH] Allow plugins to define early import stage functions --- beets/importer.py | 2 ++ beets/plugins.py | 20 ++++++++++++++++++++ 2 files changed, 22 insertions(+) diff --git a/beets/importer.py b/beets/importer.py index aac21d77f0..4e4084eec0 100644 --- a/beets/importer.py +++ b/beets/importer.py @@ -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)) diff --git a/beets/plugins.py b/beets/plugins.py index d62f3c011e..ace5170e31 100644 --- a/beets/plugins.py +++ b/beets/plugins.py @@ -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) @@ -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] + def get_import_stages(self): """Return a list of functions that should be called as importer pipelines stages. @@ -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 = []