<commit_before>from beets.plugins import BeetsPlugin
from beets.ui import Subcommand

from beets.ui import decargs

import os.path
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)):
        process_album(album)


def process_album(album):
    albumpath = album.item_dir()
    if album.artpath:
        fullartpath = album.artpath
        artfile = os.path.split(fullartpath)[1]
        create_file(albumpath, artfile)
    else:
        log.debug(u'freedesktop: album has no art')


def create_file(albumpath, artfile):
    file_contents = "[Desktop Entry]\nIcon=./" + artfile
    outfilename = os.path.join(albumpath, ".directory")

    if not os.path.exists(outfilename):
        file = open(outfilename, 'w')
        file.write(file_contents)
        file.close()
    pass


freedesktop_command.func = process_query


class FreedesktopPlugin(BeetsPlugin):
    """Creates freedesktop.org-compliant .directory files on an album level.
    """
    def __init__(self):
        super(FreedesktopPlugin, self).__init__()
        self.config.add({
            'auto': False
        })
        global automatic
        automatic = self.config['auto'].get(bool)

    def commands(self):
        return [freedesktop_command]


@FreedesktopPlugin.listen('album_imported')
def imported(lib, album):
    if not automatic:
        return
    process_album(album)<commit_msg>Fixed up config checking to make freedesktop plugin pass flake8.<commit_after>from beets.plugins import BeetsPlugin
from beets.ui import Subcommand

from beets.ui import decargs

from beets import config

import os.path
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)):
        process_album(album)


def process_album(album):
    albumpath = album.item_dir()
    if album.artpath:
        fullartpath = album.artpath
        artfile = os.path.split(fullartpath)[1]
        create_file(albumpath, artfile)
    else:
        log.debug(u'freedesktop: album has no art')


def create_file(albumpath, artfile):
    file_contents = "[Desktop Entry]\nIcon=./" + artfile
    outfilename = os.path.join(albumpath, ".directory")

    if not os.path.exists(outfilename):
        file = open(outfilename, 'w')
        file.write(file_contents)
        file.close()
    pass


freedesktop_command.func = process_query


class FreedesktopPlugin(BeetsPlugin):
    """Creates freedesktop.org-compliant .directory files on an album level.
    """
    def __init__(self):
        super(FreedesktopPlugin, self).__init__()
        self.config.add({
            'auto': False
        })

    def commands(self):
        return [freedesktop_command]


@FreedesktopPlugin.listen('album_imported')
def imported(lib, album):
    automatic = config['auto'].get(bool)
    if not automatic:
        return
    process_album(album)
{'fraction_non_alphanumeric': 0.10600706713780919, 'fraction_numerical': 0.0009637006103437199, 'mean_word_length': 3.3430962343096233, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2725154', 'n_tokens_mistral': 979, 'n_tokens_neox': 959, 'n_words': 220}