From 0aeadebceae33dabc37906a09035ed646c3f33e0 Mon Sep 17 00:00:00 2001 From: Adrian Sampson Date: Sun, 2 Nov 2014 20:57:00 -0800 Subject: [PATCH] freedesktop (#1056): Make handler a method This lets us use `self.config`. The previous version, which checked `beets.config['auto']`, was looking in the wrong scope. --- beetsplug/freedesktop.py | 27 ++++++++++----------------- docs/plugins/freedesktop.rst | 12 ++++++------ 2 files changed, 16 insertions(+), 23 deletions(-) diff --git a/beetsplug/freedesktop.py b/beetsplug/freedesktop.py index 732bea544..0aea97c38 100644 --- a/beetsplug/freedesktop.py +++ b/beetsplug/freedesktop.py @@ -17,18 +17,13 @@ from beets.plugins import BeetsPlugin from beets.ui import Subcommand - from beets.ui import decargs -from beets import config - -import os.path +import os import logging log = logging.getLogger('beets.freedesktop') -freedesktop_command = Subcommand("freedesktop", help="Create .directory files") - def process_query(lib, opts, args): for album in lib.albums(decargs(args)): @@ -53,10 +48,6 @@ def create_file(albumpath, artfile): file = open(outfilename, 'w') file.write(file_contents) file.close() - pass - - -freedesktop_command.func = process_query class FreedesktopPlugin(BeetsPlugin): @@ -65,14 +56,16 @@ class FreedesktopPlugin(BeetsPlugin): self.config.add({ 'auto': False }) + self.register_listener('album_imported', self.imported) def commands(self): + freedesktop_command = Subcommand("freedesktop", + help="Create .directory files") + freedesktop_command.func = process_query return [freedesktop_command] - -@FreedesktopPlugin.listen('album_imported') -def imported(lib, album): - automatic = config['auto'].get(bool) - if not automatic: - return - process_album(album) + def imported(self, lib, album): + automatic = self.config['auto'].get(bool) + if not automatic: + return + process_album(album) diff --git a/docs/plugins/freedesktop.rst b/docs/plugins/freedesktop.rst index 4d7a57234..9c3d1a4be 100644 --- a/docs/plugins/freedesktop.rst +++ b/docs/plugins/freedesktop.rst @@ -1,9 +1,9 @@ Freedesktop Plugin ================== -The ``freedesktop`` plugin creates .directory files in your album folders. This -allows, when using a freedesktop.org compliant file manager, such as -Dolphin or Nautilus, an album to have its cover art as the folder's thumbnail. +The ``freedesktop`` plugin creates .directory files in your album folders. +This lets Freedesktop.org compliant file managers such as Dolphin or Nautilus +to use an album's cover art as the folder's thumbnail. To use the ``freedesktop`` plugin, enable it (see :doc:`/plugins/index`). @@ -13,8 +13,8 @@ Configuration To configure the plugin, make a ``freedesktop:`` section in your configuration file. The only available option is: -- ``auto``: Create .directory files automatically during import. - Default: ``no`` +- ``auto``: Create .directory files automatically during import. + Default: ``no``. Creating .directory Files Manually ---------------------------------- @@ -22,4 +22,4 @@ Creating .directory Files Manually The ``freedesktop`` command provided by this plugin creates .directory files for albums that match a query (see :doc:`/reference/query`). For example, ``beet freedesktop man the animal cannon`` will create the .directory file for the -folder containing the album Man the Animal Cannon. \ No newline at end of file +folder containing the album Man the Animal Cannon.