Skip to content

Commit

Permalink
Merge pull request #88 from geigerzaehler/update-dependencies
Browse files Browse the repository at this point in the history
Use typed beets release and refine typesUpdate lockfile dependencies
  • Loading branch information
geigerzaehler authored Jun 25, 2024
2 parents a749647 + 1326855 commit dbafbc5
Show file tree
Hide file tree
Showing 2 changed files with 218 additions and 210 deletions.
25 changes: 20 additions & 5 deletions beetsplug/alternatives.py
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@
import traceback
from concurrent import futures
from enum import Enum
from typing import Iterator, List, Optional, Tuple
from typing import Iterator, List, Optional, Tuple, cast

import beets
from beets import art, util
Expand Down Expand Up @@ -276,25 +276,32 @@ def update(self, create: Optional[bool] = None):
path = self._get_stored_path(item)
for action in actions:
if action == Action.MOVE:
assert path is not None # action guarantees that `path` is not none
print_(f">{displayable_path(path)} -> {displayable_path(dest)}")
util.mkdirall(dest)
util.move(path, dest)
assert path is not None
util.prune_dirs(os.path.dirname(path), root=self.directory)
util.prune_dirs(
# Although the types for `prune_dirs()` require a `str`
# argument the function accepts a `bytes` argument.
cast(str, os.path.dirname(path)),
root=self.directory,
)
self._set_stored_path(item, dest)
item.store()
path = dest
elif action == Action.WRITE:
assert path is not None # action guarantees that `path` is not none
print_(f"*{displayable_path(path)}")
item.write(path=path)
elif action == Action.SYNC_ART:
assert path is not None # action guarantees that `path` is not none
print_(f"~{displayable_path(path)}")
assert path is not None
self._sync_art(item, path)
elif action == Action.ADD:
print_(f"+{displayable_path(dest)}")
converter.submit(item)
elif action == Action.REMOVE:
assert path is not None # action guarantees that `path` is not none
print_(f"-{displayable_path(path)}")
self._remove_file(item)
item.store()
Expand Down Expand Up @@ -326,8 +333,14 @@ def _get_stored_path(self, item: Item) -> Optional[bytes]:
def _remove_file(self, item: Item):
"""Remove the external file for `item`."""
path = self._get_stored_path(item)
assert path, "File to remove does not have a path"
_remove(path)
util.prune_dirs(path, root=self.directory)
util.prune_dirs(
# Although the types for `prune_dirs()` require a `str`
# argument the function accepts a `bytes` argument.
cast(str, path),
root=self.directory,
)
del item[self.path_key]

def _converter(self) -> "Worker":
Expand Down Expand Up @@ -440,6 +453,7 @@ def update(self, create=None):
path = self._get_stored_path(item)
for action in actions:
if action == Action.MOVE:
assert path is not None # action guarantees that `path` is not none
print_(f">{displayable_path(path)} -> {displayable_path(dest)}")
self._remove_file(item)
self._create_symlink(item)
Expand All @@ -449,6 +463,7 @@ def update(self, create=None):
self._create_symlink(item)
self._set_stored_path(item, dest)
elif action == Action.REMOVE:
assert path is not None # action guarantees that `path` is not none
print_(f"-{displayable_path(path)}")
self._remove_file(item)
else:
Expand Down
Loading

0 comments on commit dbafbc5

Please sign in to comment.