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.
This commit is contained in:
Adrian Sampson 2014-11-02 20:57:00 -08:00
parent 421fac30c6
commit 0aeadebcea
2 changed files with 16 additions and 23 deletions

View file

@ -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)

View file

@ -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.
folder containing the album Man the Animal Cannon.