prompt: We are currently solving the following issue within our repository. Here is the issue text:
  --- BEGIN ISSUE ---
  embedart plugin disregards "write: no" and "-W" config opts
  Any import action with `embedart` enabled causes a full write of tags and art, even when config file specifies `write: no`, or commandline includes `-W`.
  
  CAUSE: `art.py` does not check config option `import/write` before calling `try_write`.
  
  SUGGESTED FIX: check config option first! :) PR will be attached presently.
  
  embedart plugin disregards "write: no" and "-W" config opts
  Any import action with `embedart` enabled causes a full write of tags and art, even when config file specifies `write: no`, or commandline includes `-W`.
  
  CAUSE: `art.py` does not check config option `import/write` before calling `try_write`.
  
  SUGGESTED FIX: check config option first! :) PR will be attached presently.
  
  embedart plugin disregards "write: no" and "-W" config opts
  Any import action with `embedart` enabled causes a full write of tags and art, even when config file specifies `write: no`, or commandline includes `-W`.
  
  CAUSE: `art.py` does not check config option `import/write` before calling `try_write`.
  
  SUGGESTED FIX: check config option first! :) PR will be attached presently.
  
  
  --- END ISSUE ---
  
  Below are some code segments, each from a relevant file. One or more of these files may contain bugs.
  --- BEGIN FILES ---
  Path: `beetsplug/embedart.py`
  Content:
  ```
  1 # This file is part of beets.
  2 # Copyright 2015, Adrian Sampson.
  3 #
  4 # Permission is hereby granted, free of charge, to any person obtaining
  5 # a copy of this software and associated documentation files (the
  6 # "Software"), to deal in the Software without restriction, including
  7 # without limitation the rights to use, copy, modify, merge, publish,
  8 # distribute, sublicense, and/or sell copies of the Software, and to
  9 # permit persons to whom the Software is furnished to do so, subject to
  10 # the following conditions:
  11 #
  12 # The above copyright notice and this permission notice shall be
  13 # included in all copies or substantial portions of the Software.
  14 
  15 """Allows beets to embed album art into file metadata."""
  16 from __future__ import (division, absolute_import, print_function,
  17                         unicode_literals)
  18 
  19 import os.path
  20 
  21 from beets.plugins import BeetsPlugin
  22 from beets import ui
  23 from beets.ui import decargs
  24 from beets.util import syspath, normpath, displayable_path, bytestring_path
  25 from beets.util.artresizer import ArtResizer
  26 from beets import config
  27 from beets import art
  28 
  29 
  30 class EmbedCoverArtPlugin(BeetsPlugin):
  31     """Allows albumart to be embedded into the actual files.
  32     """
  33     def __init__(self):
  34         super(EmbedCoverArtPlugin, self).__init__()
  35         self.config.add({
  36             'maxwidth': 0,
  37             'auto': True,
  38             'compare_threshold': 0,
  39             'ifempty': False,
  40         })
  41 
  42         if self.config['maxwidth'].get(int) and not ArtResizer.shared.local:
  43             self.config['maxwidth'] = 0
  44             self._log.warning(u"ImageMagick or PIL not found; "
  45                               u"'maxwidth' option ignored")
  46         if self.config['compare_threshold'].get(int) and not \
  47                 ArtResizer.shared.can_compare:
  48             self.config['compare_threshold'] = 0
  49             self._log.warning(u"ImageMagick 6.8.7 or higher not installed; "
  50                               u"'compare_threshold' option ignored")
  51 
  52         self.register_listener('art_set', self.process_album)
  53 
  54     def commands(self):
  55         # Embed command.
  56         embed_cmd = ui.Subcommand(
  57             'embedart', help='embed image files into file metadata'
  58         )
  59         embed_cmd.parser.add_option(
  60             '-f', '--file', metavar='PATH', help='the image file to embed'
  61         )
  62         maxwidth = self.config['maxwidth'].get(int)
  63         compare_threshold = self.config['compare_threshold'].get(int)
  64         ifempty = self.config['ifempty'].get(bool)
  65 
  66         def embed_func(lib, opts, args):
  67             if opts.file:
  68                 imagepath = normpath(opts.file)
  69                 if not os.path.isfile(syspath(imagepath)):
  70                     raise ui.UserError(u'image file {0} not found'.format(
  71                         displayable_path(imagepath)
  72                     ))
  73                 for item in lib.items(decargs(args)):
  74                     art.embed_item(self._log, item, imagepath, maxwidth, None,
  75                                    compare_threshold, ifempty)
  76             else:
  77                 for album in lib.albums(decargs(args)):
  78                     art.embed_album(self._log, album, maxwidth, False,
  79                                     compare_threshold, ifempty)
  80 
  81         embed_cmd.func = embed_func
  82 
  83         # Extract command.
  84         extract_cmd = ui.Subcommand('extractart',
  85                                     help='extract an image from file metadata')
  86         extract_cmd.parser.add_option('-o', dest='outpath',
  87                                       help='image output file')
  88         extract_cmd.parser.add_option('-n', dest='filename',
  89                                       help='image filename to create for all '
  90                                            'matched albums')
  91         extract_cmd.parser.add_option('-a', dest='associate',
  92                                       action='store_true',
  93                                       help='associate the extracted images '
  94                                            'with the album')
  95 
  96         def extract_func(lib, opts, args):
  97             if opts.outpath:
  98                 art.extract_first(self._log, normpath(opts.outpath),
  99                                   lib.items(decargs(args)))
  100             else:
  101                 filename = bytestring_path(opts.filename or
  102                                            config['art_filename'].get())
  103                 if os.path.dirname(filename) != '':
  104                     self._log.error(u"Only specify a name rather than a path "
  105                                     u"for -n")
  106                     return
  107                 for album in lib.albums(decargs(args)):
  108                     artpath = normpath(os.path.join(album.path, filename))
  109                     artpath = art.extract_first(self._log, artpath,
  110                                                 album.items())
  111                     if artpath and opts.associate:
  112                         album.set_art(artpath)
  113                         album.store()
  114         extract_cmd.func = extract_func
  115 
  116         # Clear command.
  117         clear_cmd = ui.Subcommand('clearart',
  118                                   help='remove images from file metadata')
  119 
  120         def clear_func(lib, opts, args):
  121             art.clear(self._log, lib, decargs(args))
  122         clear_cmd.func = clear_func
  123 
  124         return [embed_cmd, extract_cmd, clear_cmd]
  125 
  126     def process_album(self, album):
  127         """Automatically embed art after art has been set
  128         """
  129         if self.config['auto']:
  130             max_width = self.config['maxwidth'].get(int)
  131             art.embed_album(self._log, album, max_width, True,
  132                             self.config['compare_threshold'].get(int),
  133                             self.config['ifempty'].get(bool))
  134
  ```
  --- END FILES ---
  
  Please first localize the bug based on the issue statement, and then generate a patch according to the `git diff` format fenced by three backticks.
  
  Here is an example:
  
  ```diff
  diff --git a/examples/server_async.py b/examples/server_async.py
  --- a/examples/server_async.py
  +++ b/examples/server_async.py
  @@ -313,4 +313,4 @@
   
   
   if __name__ == "__main__":
  -    asyncio.run(run_async_server("."), debug=True)
  +    asyncio.run(run_async_server(), debug=True)
  diff --git a/examples/server_sync.py b/examples/server_sync.py
  --- a/examples/server_sync.py
  +++ b/examples/server_sync.py
  @@ -313,5 +313,5 @@
   
   
   if __name__ == "__main__":
  -    server = run_sync_server(".")
  +    server = run_sync_server()
       server.shutdown()
  
  ```
  
golden_diff: diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py
  --- a/beetsplug/embedart.py
  +++ b/beetsplug/embedart.py
  @@ -126,7 +126,7 @@
       def process_album(self, album):
           """Automatically embed art after art has been set
           """
  -        if self.config['auto']:
  +        if self.config['auto'] and config['import']['write']:
               max_width = self.config['maxwidth'].get(int)
               art.embed_album(self._log, album, max_width, True,
                               self.config['compare_threshold'].get(int),
  
verification_info: {"golden_diff": "diff --git a/beetsplug/embedart.py b/beetsplug/embedart.py\n--- a/beetsplug/embedart.py\n+++ b/beetsplug/embedart.py\n@@ -126,7 +126,7 @@\n     def process_album(self, album):\n         \"\"\"Automatically embed art after art has been set\n         \"\"\"\n-        if self.config['auto']:\n+        if self.config['auto'] and config['import']['write']:\n             max_width = self.config['maxwidth'].get(int)\n             art.embed_album(self._log, album, max_width, True,\n                             self.config['compare_threshold'].get(int),\n", "issue": "embedart plugin disregards \"write: no\" and \"-W\" config opts\nAny import action with `embedart` enabled causes a full write of tags and art, even when config file specifies `write: no`, or commandline includes `-W`.\n\nCAUSE: `art.py` does not check config option `import/write` before calling `try_write`.\n\nSUGGESTED FIX: check config option first! :) PR will be attached presently.\n\nembedart plugin disregards \"write: no\" and \"-W\" config opts\nAny import action with `embedart` enabled causes a full write of tags and art, even when config file specifies `write: no`, or commandline includes `-W`.\n\nCAUSE: `art.py` does not check config option `import/write` before calling `try_write`.\n\nSUGGESTED FIX: check config option first! :) PR will be attached presently.\n\nembedart plugin disregards \"write: no\" and \"-W\" config opts\nAny import action with `embedart` enabled causes a full write of tags and art, even when config file specifies `write: no`, or commandline includes `-W`.\n\nCAUSE: `art.py` does not check config option `import/write` before calling `try_write`.\n\nSUGGESTED FIX: check config option first! :) PR will be attached presently.\n\n", "before_files": [{"content": "# This file is part of beets.\n# Copyright 2015, Adrian Sampson.\n#\n# Permission is hereby granted, free of charge, to any person obtaining\n# a copy of this software and associated documentation files (the\n# \"Software\"), to deal in the Software without restriction, including\n# without limitation the rights to use, copy, modify, merge, publish,\n# distribute, sublicense, and/or sell copies of the Software, and to\n# permit persons to whom the Software is furnished to do so, subject to\n# the following conditions:\n#\n# The above copyright notice and this permission notice shall be\n# included in all copies or substantial portions of the Software.\n\n\"\"\"Allows beets to embed album art into file metadata.\"\"\"\nfrom __future__ import (division, absolute_import, print_function,\n                        unicode_literals)\n\nimport os.path\n\nfrom beets.plugins import BeetsPlugin\nfrom beets import ui\nfrom beets.ui import decargs\nfrom beets.util import syspath, normpath, displayable_path, bytestring_path\nfrom beets.util.artresizer import ArtResizer\nfrom beets import config\nfrom beets import art\n\n\nclass EmbedCoverArtPlugin(BeetsPlugin):\n    \"\"\"Allows albumart to be embedded into the actual files.\n    \"\"\"\n    def __init__(self):\n        super(EmbedCoverArtPlugin, self).__init__()\n        self.config.add({\n            'maxwidth': 0,\n            'auto': True,\n            'compare_threshold': 0,\n            'ifempty': False,\n        })\n\n        if self.config['maxwidth'].get(int) and not ArtResizer.shared.local:\n            self.config['maxwidth'] = 0\n            self._log.warning(u\"ImageMagick or PIL not found; \"\n                              u\"'maxwidth' option ignored\")\n        if self.config['compare_threshold'].get(int) and not \\\n                ArtResizer.shared.can_compare:\n            self.config['compare_threshold'] = 0\n            self._log.warning(u\"ImageMagick 6.8.7 or higher not installed; \"\n                              u\"'compare_threshold' option ignored\")\n\n        self.register_listener('art_set', self.process_album)\n\n    def commands(self):\n        # Embed command.\n        embed_cmd = ui.Subcommand(\n            'embedart', help='embed image files into file metadata'\n        )\n        embed_cmd.parser.add_option(\n            '-f', '--file', metavar='PATH', help='the image file to embed'\n        )\n        maxwidth = self.config['maxwidth'].get(int)\n        compare_threshold = self.config['compare_threshold'].get(int)\n        ifempty = self.config['ifempty'].get(bool)\n\n        def embed_func(lib, opts, args):\n            if opts.file:\n                imagepath = normpath(opts.file)\n                if not os.path.isfile(syspath(imagepath)):\n                    raise ui.UserError(u'image file {0} not found'.format(\n                        displayable_path(imagepath)\n                    ))\n                for item in lib.items(decargs(args)):\n                    art.embed_item(self._log, item, imagepath, maxwidth, None,\n                                   compare_threshold, ifempty)\n            else:\n                for album in lib.albums(decargs(args)):\n                    art.embed_album(self._log, album, maxwidth, False,\n                                    compare_threshold, ifempty)\n\n        embed_cmd.func = embed_func\n\n        # Extract command.\n        extract_cmd = ui.Subcommand('extractart',\n                                    help='extract an image from file metadata')\n        extract_cmd.parser.add_option('-o', dest='outpath',\n                                      help='image output file')\n        extract_cmd.parser.add_option('-n', dest='filename',\n                                      help='image filename to create for all '\n                                           'matched albums')\n        extract_cmd.parser.add_option('-a', dest='associate',\n                                      action='store_true',\n                                      help='associate the extracted images '\n                                           'with the album')\n\n        def extract_func(lib, opts, args):\n            if opts.outpath:\n                art.extract_first(self._log, normpath(opts.outpath),\n                                  lib.items(decargs(args)))\n            else:\n                filename = bytestring_path(opts.filename or\n                                           config['art_filename'].get())\n                if os.path.dirname(filename) != '':\n                    self._log.error(u\"Only specify a name rather than a path \"\n                                    u\"for -n\")\n                    return\n                for album in lib.albums(decargs(args)):\n                    artpath = normpath(os.path.join(album.path, filename))\n                    artpath = art.extract_first(self._log, artpath,\n                                                album.items())\n                    if artpath and opts.associate:\n                        album.set_art(artpath)\n                        album.store()\n        extract_cmd.func = extract_func\n\n        # Clear command.\n        clear_cmd = ui.Subcommand('clearart',\n                                  help='remove images from file metadata')\n\n        def clear_func(lib, opts, args):\n            art.clear(self._log, lib, decargs(args))\n        clear_cmd.func = clear_func\n\n        return [embed_cmd, extract_cmd, clear_cmd]\n\n    def process_album(self, album):\n        \"\"\"Automatically embed art after art has been set\n        \"\"\"\n        if self.config['auto']:\n            max_width = self.config['maxwidth'].get(int)\n            art.embed_album(self._log, album, max_width, True,\n                            self.config['compare_threshold'].get(int),\n                            self.config['ifempty'].get(bool))\n", "path": "beetsplug/embedart.py"}], "after_files": [{"content": "# This file is part of beets.\n# Copyright 2015, Adrian Sampson.\n#\n# Permission is hereby granted, free of charge, to any person obtaining\n# a copy of this software and associated documentation files (the\n# \"Software\"), to deal in the Software without restriction, including\n# without limitation the rights to use, copy, modify, merge, publish,\n# distribute, sublicense, and/or sell copies of the Software, and to\n# permit persons to whom the Software is furnished to do so, subject to\n# the following conditions:\n#\n# The above copyright notice and this permission notice shall be\n# included in all copies or substantial portions of the Software.\n\n\"\"\"Allows beets to embed album art into file metadata.\"\"\"\nfrom __future__ import (division, absolute_import, print_function,\n                        unicode_literals)\n\nimport os.path\n\nfrom beets.plugins import BeetsPlugin\nfrom beets import ui\nfrom beets.ui import decargs\nfrom beets.util import syspath, normpath, displayable_path, bytestring_path\nfrom beets.util.artresizer import ArtResizer\nfrom beets import config\nfrom beets import art\n\n\nclass EmbedCoverArtPlugin(BeetsPlugin):\n    \"\"\"Allows albumart to be embedded into the actual files.\n    \"\"\"\n    def __init__(self):\n        super(EmbedCoverArtPlugin, self).__init__()\n        self.config.add({\n            'maxwidth': 0,\n            'auto': True,\n            'compare_threshold': 0,\n            'ifempty': False,\n        })\n\n        if self.config['maxwidth'].get(int) and not ArtResizer.shared.local:\n            self.config['maxwidth'] = 0\n            self._log.warning(u\"ImageMagick or PIL not found; \"\n                              u\"'maxwidth' option ignored\")\n        if self.config['compare_threshold'].get(int) and not \\\n                ArtResizer.shared.can_compare:\n            self.config['compare_threshold'] = 0\n            self._log.warning(u\"ImageMagick 6.8.7 or higher not installed; \"\n                              u\"'compare_threshold' option ignored\")\n\n        self.register_listener('art_set', self.process_album)\n\n    def commands(self):\n        # Embed command.\n        embed_cmd = ui.Subcommand(\n            'embedart', help='embed image files into file metadata'\n        )\n        embed_cmd.parser.add_option(\n            '-f', '--file', metavar='PATH', help='the image file to embed'\n        )\n        maxwidth = self.config['maxwidth'].get(int)\n        compare_threshold = self.config['compare_threshold'].get(int)\n        ifempty = self.config['ifempty'].get(bool)\n\n        def embed_func(lib, opts, args):\n            if opts.file:\n                imagepath = normpath(opts.file)\n                if not os.path.isfile(syspath(imagepath)):\n                    raise ui.UserError(u'image file {0} not found'.format(\n                        displayable_path(imagepath)\n                    ))\n                for item in lib.items(decargs(args)):\n                    art.embed_item(self._log, item, imagepath, maxwidth, None,\n                                   compare_threshold, ifempty)\n            else:\n                for album in lib.albums(decargs(args)):\n                    art.embed_album(self._log, album, maxwidth, False,\n                                    compare_threshold, ifempty)\n\n        embed_cmd.func = embed_func\n\n        # Extract command.\n        extract_cmd = ui.Subcommand('extractart',\n                                    help='extract an image from file metadata')\n        extract_cmd.parser.add_option('-o', dest='outpath',\n                                      help='image output file')\n        extract_cmd.parser.add_option('-n', dest='filename',\n                                      help='image filename to create for all '\n                                           'matched albums')\n        extract_cmd.parser.add_option('-a', dest='associate',\n                                      action='store_true',\n                                      help='associate the extracted images '\n                                           'with the album')\n\n        def extract_func(lib, opts, args):\n            if opts.outpath:\n                art.extract_first(self._log, normpath(opts.outpath),\n                                  lib.items(decargs(args)))\n            else:\n                filename = bytestring_path(opts.filename or\n                                           config['art_filename'].get())\n                if os.path.dirname(filename) != '':\n                    self._log.error(u\"Only specify a name rather than a path \"\n                                    u\"for -n\")\n                    return\n                for album in lib.albums(decargs(args)):\n                    artpath = normpath(os.path.join(album.path, filename))\n                    artpath = art.extract_first(self._log, artpath,\n                                                album.items())\n                    if artpath and opts.associate:\n                        album.set_art(artpath)\n                        album.store()\n        extract_cmd.func = extract_func\n\n        # Clear command.\n        clear_cmd = ui.Subcommand('clearart',\n                                  help='remove images from file metadata')\n\n        def clear_func(lib, opts, args):\n            art.clear(self._log, lib, decargs(args))\n        clear_cmd.func = clear_func\n\n        return [embed_cmd, extract_cmd, clear_cmd]\n\n    def process_album(self, album):\n        \"\"\"Automatically embed art after art has been set\n        \"\"\"\n        if self.config['auto'] and config['import']['write']:\n            max_width = self.config['maxwidth'].get(int)\n            art.embed_album(self._log, album, max_width, True,\n                            self.config['compare_threshold'].get(int),\n                            self.config['ifempty'].get(bool))\n", "path": "beetsplug/embedart.py"}]}