Skip to content

Commit

Permalink
Use PluginFunctions and PluginPriority to reduce code redundancy.
Browse files Browse the repository at this point in the history
weight was renamed priority
Execution loops were replaced by PluginFunctions.run() call
  • Loading branch information
zas committed Apr 24, 2014
1 parent 2fc6da0 commit b7468b8
Showing 1 changed file with 9 additions and 20 deletions.
29 changes: 9 additions & 20 deletions picard/metadata.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
from os import fdopen, unlink
from PyQt4.QtCore import QObject
from picard import config, log
from picard.plugin import ExtensionPoint
from picard.plugin import PluginFunctions, PluginPriority
from picard.similarity import similarity2
from picard.util import (
encode_filename,
Expand Down Expand Up @@ -439,34 +439,23 @@ def strip_whitespace(self):
self.apply_func(lambda s: s.strip())


from collections import defaultdict
_album_metadata_processors = PluginFunctions()
_track_metadata_processors = PluginFunctions()

_album_metadata_processors = defaultdict(ExtensionPoint)
_track_metadata_processors = defaultdict(ExtensionPoint)


def register_album_metadata_processor(function, weight=100):
def register_album_metadata_processor(function, priority=PluginPriority.NORMAL):
"""Registers new album-level metadata processor."""
_album_metadata_processors[weight].register(function.__module__, function)
_album_metadata_processors.register(function.__module__, function, priority)


def register_track_metadata_processor(function, weight=100):
def register_track_metadata_processor(function, priority=PluginPriority.NORMAL):
"""Registers new track-level metadata processor."""
_track_metadata_processors[weight].register(function.__module__, function)
_track_metadata_processors.register(function.__module__, function, priority)


def run_album_metadata_processors(tagger, metadata, release):
for weight, processors in sorted(_album_metadata_processors.iteritems(),
key=lambda (k, v): k,
reverse=True):
for processor in processors:
processor(tagger, metadata, release)
_album_metadata_processors.run(tagger, metadata, release)


def run_track_metadata_processors(tagger, metadata, release, track):
for weight, processors in sorted(_track_metadata_processors.iteritems(),
key=lambda (k, v): k,
reverse=True):
for processor in processors:
processor(tagger, metadata, track, release)

_track_metadata_processors.run(tagger, metadata, track, release)

0 comments on commit b7468b8

Please sign in to comment.