diff --git a/.gitea/ISSUE_TEMPLATE/bug.yml b/.gitea/ISSUE_TEMPLATE/bug.yml new file mode 100644 index 0000000..8f78e72 --- /dev/null +++ b/.gitea/ISSUE_TEMPLATE/bug.yml @@ -0,0 +1,34 @@ +name: Bug Report +description: Report a bug in this project +labels: + - kind/bug + - triage +body: + + - type: textarea + id: bug + attributes: + label: Describe the bug + description: | + A clear and concise description of what the bug is. + What did you expect to happen? What happened instead? + Include screenshots if applicable. + validations: + required: true + - type: textarea + id: reproduction + attributes: + label: Steps to reproduce + description: | + A clear and concise description of how to reproduce the bug. + Include steps, code snippets, or screenshots if applicable. + validations: + required: true + - type: textarea + id: additional-info + attributes: + label: Additional information + description: | + Add any other context or screenshots about the bug here. + + \ No newline at end of file diff --git a/.gitea/ISSUE_TEMPLATE/feature.yml b/.gitea/ISSUE_TEMPLATE/feature.yml new file mode 100644 index 0000000..cb6338e --- /dev/null +++ b/.gitea/ISSUE_TEMPLATE/feature.yml @@ -0,0 +1,23 @@ +name: Feature request +description: Suggest an idea for this project +labels: + - kind/feature + - triage + +body: + - type: textarea + id: feature + attributes: + label: Describe the feature + description: | + A clear and concise description of what the feature is. + What is the problem it solves? What are you trying to accomplish? + Include screenshots if applicable. + validations: + required: true + - type: textarea + id: additional-info + attributes: + label: Additional information + description: | + Add any other context or screenshots about the feature request here. \ No newline at end of file diff --git a/.gitea/workflows/build.yaml b/.gitea/workflows/build.yaml index ffd38ec..47550ab 100644 --- a/.gitea/workflows/build.yaml +++ b/.gitea/workflows/build.yaml @@ -5,6 +5,7 @@ on: push: branches: - main + jobs: build: runs-on: ubuntu-latest diff --git a/src/komconfig/__init__.py b/src/komconfig/__init__.py index 088a728..721bd96 100644 --- a/src/komconfig/__init__.py +++ b/src/komconfig/__init__.py @@ -1 +1,2 @@ +CONFIG_PATH = "~/.config/KomSuite/" from .config import Settings as KomConfig diff --git a/src/komconfig/config.py b/src/komconfig/config.py index 090814a..0c3adad 100644 --- a/src/komconfig/config.py +++ b/src/komconfig/config.py @@ -1,8 +1,11 @@ from dataclasses import dataclass from typing import List, Optional import os -from omegaconf import OmegaConf -from omegaconf import DictConfig +from omegaconf import OmegaConf, DictConfig +from pathlib import Path +from komconfig import CONFIG_PATH + +SETTINGS_PATH = os.path.join(CONFIG_PATH, "config.yaml") @dataclass @@ -14,6 +17,7 @@ class Komga: password: str media_path: str api_key: str = None + libraries: dict[str, str] = None def getattr(self, name): return getattr(self, name) @@ -58,20 +62,93 @@ class Aria2: @dataclass -class KomGrabber: - """KomGrabber settings.""" +class EbookSettings: + min_filesize: int + max_filesize: int + data_directory: str + skip_parameters: List[str] + valid_file_extensions: List[str] - download_location: str + def __post_init__(self): + self.skip_parameters = [ + param.lower() for param in self.skip_parameters if param is not None + ] + + def getattr(self, name): + return getattr(self, name) + + def _setattr(self, name, value): + setattr(self, name, value) + + +@dataclass +class ComicSettings: + min_filesize: int + max_filesize: int + data_directory: str + valid_file_extensions: List[str] + + skip_parameters: List[str] + + def __post_init__(self): + self.skip_parameters = [ + param.lower() for param in self.skip_parameters if param is not None + ] + + def getattr(self, name): + return getattr(self, name) + + def _setattr(self, name, value): + setattr(self, name, value) + + +@dataclass +class KomGrabber: + """ + Configs used by the KomGrabber. + + Attributes + ---------- + download_location : str | Path + The location to download the files to. + get_chapters : bool + Whether to get chapters or not. + skip_parameters : List[str] + A list of parameters to skip. + aria2 : Aria2 + The aria2 settings. see Aria2 class. + tag_interactive : bool + Whether to use interactive tagging or not. + ebook : EbookSettings + The ebook settings. see EbookSettings class. + manga : ComicSettings + The manga settings. see ComicSettings class. + check_interval : int + The interval to check for new files. + use_cache : bool + Whether to use cache or not. + cache_check_interval : int + The days an entry will not be checked based on the last change in the cache. + + """ + + download_location: Path get_chapters: bool skip_parameters: List[str] aria2: Aria2 tag_interactive: bool - min_filesize: int + ebook: EbookSettings + manga: ComicSettings + check_interval: int + use_cache: bool + cache_check_interval: int def __post_init__(self): self.skip_parameters = [param.lower() for param in self.skip_parameters] if "~" in self.download_location: self.download_location = os.path.expanduser(self.download_location) + if isinstance(self.download_location, str): + self.download_location = Path(self.download_location) def getattr(self, name): return getattr(self, name) @@ -186,7 +263,7 @@ class Settings: _config: Optional[DictConfig] = None - def __init__(self, config_path: str = "~/.config/KomSuite/config.yaml"): + def __init__(self, config_path: str = SETTINGS_PATH): """ Loads the configuration file and stores it for future access. @@ -196,7 +273,9 @@ class Settings: Raises: FileNotFoundError: Configuration file not found """ - if not os.path.exists(os.path.expanduser(config_path)): + if "~" in config_path: + config_path = os.path.expanduser(config_path) + if not os.path.exists(config_path): raise FileNotFoundError(f"Configuration file not found: {config_path}") self._config = OmegaConf.load(os.path.expanduser(config_path)) self.config_path = config_path