Skip to content

Commit 8271960

Browse files
committed
Delegate attribute access to logging
1 parent 5c4f0b6 commit 8271960

32 files changed

+196
-195
lines changed

beets/art.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,7 +38,7 @@ def get_art(log, item):
3838
try:
3939
mf = mediafile.MediaFile(syspath(item.path))
4040
except mediafile.UnreadableFileError as exc:
41-
log.warning("Could not extract art from {}: {}", item.filepath, exc)
41+
log.warning("Could not extract art from {.filepath}: {}", item, exc)
4242
return
4343

4444
return mf.art
@@ -88,7 +88,7 @@ def embed_item(
8888
# Make sure the image kind is safe (some formats only support PNG
8989
# and JPEG).
9090
if image.mime_type not in ("image/jpeg", "image/png"):
91-
log.info("not embedding image of unsupported type: {}", image.mime_type)
91+
log.info("not embedding image of unsupported type: {.mime_type}", image)
9292
return
9393

9494
item.try_write(path=itempath, tags={"images": [image]}, id3v23=id3v23)
@@ -185,7 +185,7 @@ def extract(log, outpath, item):
185185
# Add an extension to the filename.
186186
ext = mediafile.image_extension(art)
187187
if not ext:
188-
log.warning("Unknown image type in {}.", item.filepath)
188+
log.warning("Unknown image type in {.filepath}.", item)
189189
return
190190
outpath += bytestring_path(f".{ext}")
191191

beets/autotag/match.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def _add_candidate(
197197
checking the track count, ordering the items, checking for
198198
duplicates, and calculating the distance.
199199
"""
200-
log.debug("Candidate: {} - {} ({})", info.artist, info.album, info.album_id)
200+
log.debug("Candidate: {.artist} - {.album} ({.album_id})", info, info, info)
201201

202202
# Discard albums with zero tracks.
203203
if not info.tracks:

beets/importer/stages.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -82,10 +82,10 @@ def query_tasks(session: ImportSession):
8282
# Search for albums.
8383
for album in session.lib.albums(session.query):
8484
log.debug(
85-
"yielding album {}: {} - {}",
86-
album.id,
87-
album.albumartist,
88-
album.album,
85+
"yielding album {.id}: {.albumartist} - {.album}",
86+
album,
87+
album,
88+
album,
8989
)
9090
items = list(album.items())
9191
_freshen_items(items)

beets/importer/tasks.py

Lines changed: 23 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -271,7 +271,7 @@ def remove_duplicates(self, lib: library.Library):
271271
for item in duplicate_items:
272272
item.remove()
273273
if lib.directory in util.ancestry(item.path):
274-
log.debug("deleting duplicate {}", item.filepath)
274+
log.debug("deleting duplicate {.filepath}", item)
275275
util.remove(item.path)
276276
util.prune_dirs(os.path.dirname(item.path), lib.directory)
277277

@@ -552,12 +552,12 @@ def _reduce_and_log(new_obj, existing_fields, overwrite_keys):
552552
]
553553
if overwritten_fields:
554554
log.debug(
555-
"Reimported {} {}. Not preserving flexible attributes {}. "
556-
"Path: {}",
555+
"Reimported {} {.id}. Not preserving flexible attributes {}. "
556+
"Path: {.filepath}",
557557
noun,
558-
new_obj.id,
558+
new_obj,
559559
overwritten_fields,
560-
new_obj.filepath,
560+
new_obj,
561561
)
562562
for key in overwritten_fields:
563563
del existing_fields[key]
@@ -576,17 +576,17 @@ def _reduce_and_log(new_obj, existing_fields, overwrite_keys):
576576
self.album.artpath = replaced_album.artpath
577577
self.album.store()
578578
log.debug(
579-
"Reimported album {}. Preserving attribute ['added']. "
580-
"Path: {}",
581-
self.album.id,
582-
self.album.filepath,
579+
"Reimported album {.album.id}. Preserving attribute ['added']. "
580+
"Path: {.album.filepath}",
581+
self,
582+
self,
583583
)
584584
log.debug(
585-
"Reimported album {}. Preserving flexible attributes {}. "
586-
"Path: {}",
587-
self.album.id,
585+
"Reimported album {.album.id}. Preserving flexible attributes {}. "
586+
"Path: {.album.filepath}",
587+
self,
588588
list(album_fields.keys()),
589-
self.album.filepath,
589+
self,
590590
)
591591

592592
for item in self.imported_items():
@@ -595,21 +595,21 @@ def _reduce_and_log(new_obj, existing_fields, overwrite_keys):
595595
if dup_item.added and dup_item.added != item.added:
596596
item.added = dup_item.added
597597
log.debug(
598-
"Reimported item {}. Preserving attribute ['added']. "
599-
"Path: {}",
600-
item.id,
601-
item.filepath,
598+
"Reimported item {.id}. Preserving attribute ['added']. "
599+
"Path: {.filepath}",
600+
item,
601+
item,
602602
)
603603
item_fields = _reduce_and_log(
604604
item, dup_item._values_flex, REIMPORT_FRESH_FIELDS_ITEM
605605
)
606606
item.update(item_fields)
607607
log.debug(
608-
"Reimported item {}. Preserving flexible attributes {}. "
609-
"Path: {}",
610-
item.id,
608+
"Reimported item {.id}. Preserving flexible attributes {}. "
609+
"Path: {.filepath}",
610+
item,
611611
list(item_fields.keys()),
612-
item.filepath,
612+
item,
613613
)
614614
item.store()
615615

@@ -619,7 +619,7 @@ def remove_replaced(self, lib):
619619
"""
620620
for item in self.imported_items():
621621
for dup_item in self.replaced_items[item]:
622-
log.debug("Replacing item {}: {}", dup_item.id, item.filepath)
622+
log.debug("Replacing item {.id}: {.filepath}", dup_item, item)
623623
dup_item.remove()
624624
log.debug(
625625
"{} of {} items replaced",
@@ -1067,7 +1067,7 @@ def unarchive(self):
10671067

10681068
# Now read albums from the extracted directory.
10691069
self.toppath = archive_task.toppath
1070-
log.debug("Archive extracted to: {}", self.toppath)
1070+
log.debug("Archive extracted to: {.toppath}", self)
10711071
return archive_task
10721072

10731073
def read_item(self, path: util.PathBytes):

beets/library/models.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1012,7 +1012,7 @@ def try_sync(self, write, move, with_album=True):
10121012
if move:
10131013
# Check whether this file is inside the library directory.
10141014
if self._db and self._db.directory in util.ancestry(self.path):
1015-
log.debug("moving {} to synchronize path", self.filepath)
1015+
log.debug("moving {.filepath} to synchronize path", self)
10161016
self.move(with_album=with_album)
10171017
self.store()
10181018

beets/ui/commands.py

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1282,11 +1282,11 @@ def _get_choices(self, task):
12821282
dup_choices = [c for c in all_choices if c.short == short]
12831283
for c in dup_choices[1:]:
12841284
log.warning(
1285-
"Prompt choice '{}' removed due to conflict "
1286-
"with '{}' (short letter: '{}')",
1287-
c.long,
1288-
dup_choices[0].long,
1289-
c.short,
1285+
"Prompt choice '{.long}' removed due to conflict "
1286+
"with '{.long}' (short letter: '{.short}')",
1287+
c,
1288+
dup_choices[0],
1289+
c,
12901290
)
12911291
extra_choices.remove(c)
12921292

@@ -1641,17 +1641,17 @@ def update_items(lib, query, album, move, pretend, fields, exclude_fields=None):
16411641
# Did the item change since last checked?
16421642
if item.current_mtime() <= item.mtime:
16431643
log.debug(
1644-
"skipping {} because mtime is up to date ({})",
1645-
item.filepath,
1646-
item.mtime,
1644+
"skipping {.filepath} because mtime is up to date ({.mtime})",
1645+
item,
1646+
item,
16471647
)
16481648
continue
16491649

16501650
# Read new data.
16511651
try:
16521652
item.read()
16531653
except library.ReadError as exc:
1654-
log.error("error reading {}: {}", item.filepath, exc)
1654+
log.error("error reading {.filepath}: {}", item, exc)
16551655
continue
16561656

16571657
# Special-case album artist when it matches track artist. (Hacky
@@ -1884,7 +1884,7 @@ def show_stats(lib, query, exact):
18841884
try:
18851885
total_size += os.path.getsize(syspath(item.path))
18861886
except OSError as exc:
1887-
log.info("could not get size of {}: {}", item.path, exc)
1887+
log.info("could not get size of {.path}: {}", item, exc)
18881888
else:
18891889
total_size += int(item.length * item.bitrate / 8)
18901890
total_time += item.length
@@ -2175,7 +2175,7 @@ def isalbummoved(album):
21752175
)
21762176

21772177
for obj in objs:
2178-
log.debug("moving: {}", obj.filepath)
2178+
log.debug("moving: {.filepath}", obj)
21792179

21802180
if export:
21812181
# Copy without affecting the database.
@@ -2258,14 +2258,14 @@ def write_items(lib, query, pretend, force):
22582258
for item in items:
22592259
# Item deleted?
22602260
if not os.path.exists(syspath(item.path)):
2261-
log.info("missing file: {}", item.filepath)
2261+
log.info("missing file: {.filepath}", item)
22622262
continue
22632263

22642264
# Get an Item object reflecting the "clean" (on-disk) state.
22652265
try:
22662266
clean_item = library.Item.from_path(item.path)
22672267
except library.ReadError as exc:
2268-
log.error("error reading {}: {}", item.filepath, exc)
2268+
log.error("error reading {.filepath}: {}", item, exc)
22692269
continue
22702270

22712271
# Check for and display changes.

beets/util/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ def log(self, logger):
126126
"""
127127
if self.tb:
128128
logger.debug(self.tb)
129-
logger.error("{}: {}", self.error_kind, self.args[0])
129+
logger.error("{.error_kind}: {}", self, self.args[0])
130130

131131

132132
class FilesystemError(HumanReadableError):

beets/util/artresizer.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -306,9 +306,9 @@ def get_size(self, path_in: bytes) -> tuple[int, int] | None:
306306
except subprocess.CalledProcessError as exc:
307307
log.warning("ImageMagick size query failed")
308308
log.debug(
309-
"`convert` exited with (status {}) when "
309+
"`convert` exited with (status {.returncode}) when "
310310
"getting size with command {}:\n{}",
311-
exc.returncode,
311+
exc,
312312
cmd,
313313
exc.output.strip(),
314314
)
@@ -441,8 +441,8 @@ def compare(
441441
convert_proc.wait()
442442
if convert_proc.returncode:
443443
log.debug(
444-
"ImageMagick convert failed with status {}: {!r}",
445-
convert_proc.returncode,
444+
"ImageMagick convert failed with status {.returncode}: {!r}",
445+
convert_proc,
446446
convert_stderr,
447447
)
448448
return None

beetsplug/acousticbrainz.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -153,7 +153,7 @@ def _get_data(self, mbid):
153153
try:
154154
data.update(res.json())
155155
except ValueError:
156-
self._log.debug("Invalid Response: {}", res.text)
156+
self._log.debug("Invalid Response: {.text}", res)
157157
return {}
158158

159159
return data

beetsplug/badfiles.py

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,12 +127,12 @@ def check_item(self, item):
127127
except CheckerCommandError as e:
128128
if e.errno == errno.ENOENT:
129129
self._log.error(
130-
"command not found: {} when validating file: {}",
131-
e.checker,
132-
e.path,
130+
"command not found: {.checker} when validating file: {.path}",
131+
e,
132+
e,
133133
)
134134
else:
135-
self._log.error("error invoking {}: {}", e.checker, e.msg)
135+
self._log.error("error invoking {.checker}: {.msg}", e, e)
136136
return []
137137

138138
error_lines = []

0 commit comments

Comments
 (0)