Skip to content

Commit

Permalink
refactor(convert): factorize multiple logic tests
Browse files Browse the repository at this point in the history
Nest and combine some logic tests by:
1. Only check for destination file existence once.
2. Use `original` instead of `item.path` in the `refresh` conditional
   such that this option will be compatible with `keep_new`.
  • Loading branch information
pierreay committed Feb 20, 2025
1 parent b96def1 commit a956a10
Showing 1 changed file with 14 additions and 23 deletions.
37 changes: 14 additions & 23 deletions beetsplug/convert.py
Original file line number Diff line number Diff line change
Expand Up @@ -383,30 +383,21 @@ def convert_item(
with _fs_lock:
util.mkdirall(dest)

# Delete existing destination files when original files have been
# modified since the last conversion. NOTE: Only when not using the
# --keep-new option because I'm not sure what to do in this case.
if (
(refresh and not keep_new)
and (os.path.exists(dest))
and (
os.path.getmtime(item.path)
> os.path.getmtime(dest)
)
):
self._log.info(
"Removing {0} (original file modified)",
util.displayable_path(dest),
)
if not pretend:
util.remove(dest)

if os.path.exists(dest):
self._log.info(
"Skipping {0} (target file exists)",
util.displayable_path(item.path),
)
continue
# Delete existing destination files when original files have been modified since the last convert run.
if refresh and os.path.getmtime(original) > os.path.getmtime(dest):
self._log.info(
"Removing {0} (original file modified)",
util.displayable_path(dest),
)
if not pretend:
util.remove(dest)
else
self._log.info(
"Skipping {0} (target file exists)",

Check failure on line 397 in beetsplug/convert.py

View workflow job for this annotation

GitHub Actions / Check linting

Ruff (E501)

beetsplug/convert.py:397:89: E501 Line too long (118 > 88)
util.displayable_path(item.path),
)
continue

if keep_new:
if pretend:
Expand Down

0 comments on commit a956a10

Please sign in to comment.