core: use class based code

This commit is contained in:
2025-04-14 19:29:54 +02:00
parent c68f393703
commit 8a123180c5
5 changed files with 163 additions and 87 deletions

42
src/path.py Normal file
View File

@ -0,0 +1,42 @@
from __future__ import annotations
import os
class Path():
def __init__(self, *paths: str | Path):
self._absolute_path: str = ""
for path in paths:
self._absolute_path = os.path.join(self._absolute_path, path._absolute_path if isinstance(path, Path) else path)
self._name: str = os.path.basename(self._absolute_path)
self._dirpath: str = os.path.dirname(self._absolute_path)
def get_dirpath(self):
return self._dirpath
def get_absolute_path(self):
return self._absolute_path
def get_name(self):
if not self.exist():
return None
return self._name
def exist(self) -> bool:
return os.path.exists(self.get_absolute_path())
def get_dirs(self) -> list[Path]:
dirs: list[Path] = []
for element in os.listdir(self.get_absolute_path()):
path: Path = Path(self._absolute_path, element)
if (os.path.isdir(path.get_absolute_path())):
dirs.append(path)
return dirs
def get_files(self) -> list[Path]:
files: list[Path] = []
for element in os.listdir(self.get_absolute_path()):
path: Path = Path(self._absolute_path, element)
if (os.path.isfile(path.get_absolute_path())):
files.append(path)
return files