Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

added --symlink feature #280

Open
wants to merge 8 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 9 additions & 0 deletions mnamer/setting_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -217,6 +217,15 @@ class SettingStore:
help="--episode-format: set episode renaming format specification",
).as_dict(),
)
symlink: bool = dataclasses.field(
default=False,
metadata=SettingSpec(
action="store_true",
flags=["--symlink"],
group=SettingType.PARAMETER,
help="--symlink: leaves a trailing symlink",
).as_dict(),
)

# directive attributes -----------------------------------------------------

Expand Down
8 changes: 8 additions & 0 deletions mnamer/target.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

import datetime as dt
from os import path
from os import symlink
from pathlib import Path
from shutil import move
from typing import Any, ClassVar, Type
Expand Down Expand Up @@ -242,7 +243,14 @@ def relocate(self) -> None:
"""Performs the action of renaming and/or moving a file."""
destination_path = Path(self.destination).resolve()
destination_path.parent.mkdir(parents=True, exist_ok=True)
if path.isLink(destination_path) == True:
print("Skipped symlink")
return
try:
move(str(self.source), destination_path)
if self._settings.symlink:
if path.islink(destination_path) == False:
symlink(destination_path, str(self.source))

except OSError: # pragma: no cover
raise MnamerException
2 changes: 2 additions & 0 deletions mnamer/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,8 @@ def is_subtitle(container: str | Path | None) -> bool:
return False
return str(container).endswith(tuple(SUBTITLE_CONTAINERS))

def is_symlink(path: Path) -> str:
return os.path.islink(str(Path))

def get_session() -> requests_cache.CachedSession:
"""Convenience function that returns request-cache session singleton."""
Expand Down