update Beets

This commit is contained in:
AdeHub
2024-08-24 16:44:41 +12:00
parent a63098a919
commit 046d4d82b4
116 changed files with 17353 additions and 9964 deletions
+35 -34
View File
@@ -5,10 +5,13 @@ like the following in your config.yaml to configure:
file: 644
dir: 755
"""
import os
from beets import config, util
import stat
from beets import config
from beets.plugins import BeetsPlugin
from beets.util import ancestry
from beets.util import ancestry, displayable_path, syspath
def convert_perm(perm):
@@ -25,7 +28,7 @@ def check_permissions(path, permission):
"""Check whether the file's permissions equal the given vector.
Return a boolean.
"""
return oct(os.stat(path).st_mode & 0o777) == oct(permission)
return oct(stat.S_IMODE(os.stat(syspath(path)).st_mode)) == oct(permission)
def assert_permissions(path, permission, log):
@@ -33,24 +36,20 @@ def assert_permissions(path, permission, log):
log a warning message. Return a boolean indicating the match, like
`check_permissions`.
"""
if not check_permissions(util.syspath(path), permission):
log.warning(
'could not set permissions on {}',
util.displayable_path(path),
)
if not check_permissions(path, permission):
log.warning("could not set permissions on {}", displayable_path(path))
log.debug(
'set permissions to {}, but permissions are now {}',
"set permissions to {}, but permissions are now {}",
permission,
os.stat(util.syspath(path)).st_mode & 0o777,
os.stat(syspath(path)).st_mode & 0o777,
)
def dirs_in_library(library, item):
"""Creates a list of ancestor directories in the beets library path.
"""
return [ancestor
for ancestor in ancestry(item)
if ancestor.startswith(library)][1:]
"""Creates a list of ancestor directories in the beets library path."""
return [
ancestor for ancestor in ancestry(item) if ancestor.startswith(library)
][1:]
class Permissions(BeetsPlugin):
@@ -58,18 +57,19 @@ class Permissions(BeetsPlugin):
super().__init__()
# Adding defaults.
self.config.add({
'file': '644',
'dir': '755',
})
self.config.add(
{
"file": "644",
"dir": "755",
}
)
self.register_listener('item_imported', self.fix)
self.register_listener('album_imported', self.fix)
self.register_listener('art_set', self.fix_art)
self.register_listener("item_imported", self.fix)
self.register_listener("album_imported", self.fix)
self.register_listener("art_set", self.fix_art)
def fix(self, lib, item=None, album=None):
"""Fix the permissions for an imported Item or Album.
"""
"""Fix the permissions for an imported Item or Album."""
files = []
dirs = set()
if item:
@@ -82,8 +82,7 @@ class Permissions(BeetsPlugin):
self.set_permissions(files=files, dirs=dirs)
def fix_art(self, album):
"""Fix the permission for Album art file.
"""
"""Fix the permission for Album art file."""
if album.artpath:
self.set_permissions(files=[album.artpath])
@@ -92,18 +91,19 @@ class Permissions(BeetsPlugin):
# string (in YAML quotes) or, for convenience, as an integer so the
# quotes can be omitted. In the latter case, we need to reinterpret the
# integer as octal, not decimal.
file_perm = config['permissions']['file'].get()
dir_perm = config['permissions']['dir'].get()
file_perm = config["permissions"]["file"].get()
dir_perm = config["permissions"]["dir"].get()
file_perm = convert_perm(file_perm)
dir_perm = convert_perm(dir_perm)
for path in files:
# Changing permissions on the destination file.
self._log.debug(
'setting file permissions on {}',
util.displayable_path(path),
"setting file permissions on {}",
displayable_path(path),
)
os.chmod(util.syspath(path), file_perm)
if not check_permissions(path, file_perm):
os.chmod(syspath(path), file_perm)
# Checks if the destination path has the permissions configured.
assert_permissions(path, file_perm, self._log)
@@ -112,10 +112,11 @@ class Permissions(BeetsPlugin):
for path in dirs:
# Changing permissions on the destination directory.
self._log.debug(
'setting directory permissions on {}',
util.displayable_path(path),
"setting directory permissions on {}",
displayable_path(path),
)
os.chmod(util.syspath(path), dir_perm)
if not check_permissions(path, dir_perm):
os.chmod(syspath(path), dir_perm)
# Checks if the destination path has the permissions configured.
assert_permissions(path, dir_perm, self._log)