Total Complexity | 5 |
Total Lines | 32 |
Duplicated Lines | 0 % |
Changes | 0 |
1 | from pathlib import Path |
||
|
|||
2 | from typing import Optional |
||
3 | |||
4 | from pocketutils.tools.path_tools import PathTools |
||
5 | |||
6 | from mandos import logger |
||
7 | from mandos.model.searches import Search |
||
8 | from mandos.model.settings import SETTINGS |
||
9 | |||
10 | |||
11 | class EntryPaths: |
||
12 | @classmethod |
||
13 | def output_path_of(cls, what: Search, input_path: Path, to: Optional[Path]) -> Path: |
||
14 | if to is None: |
||
15 | return cls.default_path_of(what, input_path) |
||
16 | elif str(to).startswith("."): |
||
17 | return cls.default_path_of(what, input_path).with_suffix(str(to)) |
||
18 | else: |
||
19 | return to |
||
20 | |||
21 | @classmethod |
||
22 | def default_path_of(cls, what: Search, input_path: Path) -> Path: |
||
23 | parent = input_path.parent / (input_path.stem + "-output") |
||
24 | child = what.key + SETTINGS.table_suffix |
||
25 | node = PathTools.sanitize_path_node(child) |
||
26 | if (parent / node).resolve() != (parent / child).resolve(): |
||
27 | logger.debug(f"Path {child} sanitized to {node}") |
||
28 | return parent / node |
||
29 | |||
30 | |||
31 | __all__ = ["EntryPaths"] |
||
32 |