PyExplorer/src/items/Symlink.py
2026-06-30 22:27:29 +02:00

28 lines
770 B
Python

from pathlib import Path
from .AItems import AItem
from .File import File
from .Folder import Folder
class Symlink(AItem):
COLOR = 3
def __init__(self, path: Path) -> None:
super().__init__(path)
self._point_to = path.resolve()
if False == self._point_to.exists():
self._point_to = None
def __str__(self) -> str:
return f"{self.name} -> {'(broken)' if None == self.point_to else self.point_to.name}"
@staticmethod
def target_color(point_to: Path | None) -> int:
if point_to is None:
return 5
elif point_to.is_dir():
return Folder.COLOR
else:
return File.COLOR
@property
def point_to(self) -> Path:
return self._point_to