mirror of
https://git.srhtnin.garden/sarah/SaraSort.git
synced 2026-10-13 18:28:18 +02:00
Windows support
This commit is contained in:
1 parent
f1935a119b
commit
6cb2bd74cc
13 files changed
+207
-25
No files matched your search
@@ -22,6 +22,11 @@ from typing import Any, Optional
|
||||
import tomlkit
|
||||
from tomlkit.items import AoT
|
||||
|
||||
|
||||
def _Slashes(PathText: str) -> str:
|
||||
"""Windows paths use "\\" (and configs may mix both); SaraSortd 7.5 names and compares with "/"."""
|
||||
return PathText.replace("\\", "/")
|
||||
|
||||
from Core import AppConfig
|
||||
|
||||
TemplateNames = {"In": "InputDirConf.toml", "Out": "OutputDirConf.toml"}
|
||||
@@ -276,20 +281,21 @@ class Setup:
|
||||
return Path(os.path.normpath(self.GlobalPath.parent / Parsed))
|
||||
|
||||
def FlatName(self, DirPath: str) -> str:
|
||||
"""SaraSortd's FlatName: "%RootDir%/Pictures/Cats" -> "Pictures_Cats"."""
|
||||
Root = self.ParsePath(str(self.Dirs.get("RootDir", ""))).rstrip("/")
|
||||
DirPath = DirPath.rstrip("/")
|
||||
"""SaraSortd's FlatName: "%RootDir%/Pictures/Cats" -> "Pictures_Cats".
|
||||
Like SaraSortd 7.5, "\\" counts as "/" and a drive's ":" is dropped (Windows)."""
|
||||
Root = _Slashes(self.ParsePath(str(self.Dirs.get("RootDir", "")))).rstrip("/")
|
||||
DirPath = _Slashes(DirPath).rstrip("/")
|
||||
if Root and DirPath.startswith(Root + "/"):
|
||||
Relative = DirPath[len(Root) + 1:]
|
||||
else:
|
||||
Relative = DirPath.strip("/") or os.path.basename(DirPath)
|
||||
return Relative.replace("/", "_")
|
||||
return Relative.replace(":", "").replace("/", "_")
|
||||
|
||||
def CentralConf(self, DirPath: str, Kind: str) -> Optional[Path]:
|
||||
"""SaraSortd 7.2: a config named in [DirConfs], or one in DirConfDir.
|
||||
None when the config lives inside the directory."""
|
||||
for Key, Value in (self.Data.get("DirConfs") or {}).items():
|
||||
if self.ParsePath(str(Key)).rstrip("/") == DirPath.rstrip("/"):
|
||||
if _Slashes(self.ParsePath(str(Key))).rstrip("/") == _Slashes(DirPath).rstrip("/"):
|
||||
if isinstance(Value, dict):
|
||||
Value = Value.get(Kind)
|
||||
if Value:
|
||||
@@ -338,7 +344,7 @@ class Setup:
|
||||
After = Setup(self.Config, NewDoc)
|
||||
Folder = After.CentralFolder()
|
||||
for InputPath in self.Inputs:
|
||||
if Folder and (Folder == Path(InputPath) or str(Folder).startswith(InputPath.rstrip("/") + "/")):
|
||||
if Folder and Folder.is_relative_to(Path(InputPath)):
|
||||
raise SortdError(f"{Folder} is inside the input {InputPath}; SaraSortd would sort its own configs away.")
|
||||
Plan: dict[Path, Path] = {}
|
||||
for DirPath in dict.fromkeys(self.Inputs + self.Outputs):
|
||||
@@ -919,7 +925,7 @@ class Setup:
|
||||
f"which SaraSortd {Daemon} doesn't know about. Update SaraSortd to 7.2."))
|
||||
if Central:
|
||||
for InputPath in Inputs:
|
||||
if Central == Path(InputPath) or str(Central).startswith(InputPath.rstrip("/") + "/"):
|
||||
if Central.is_relative_to(Path(InputPath)):
|
||||
Found.append(("Error", f"DirConfDir ({Central}) is inside the input {InputPath}, so SaraSortd "
|
||||
"would sort its own configs away."))
|
||||
if UsesOwnInputs and Daemon and not VersionAtLeast(Daemon, (7, 1)):
|
||||
|
||||
Reference in new issue
Block a user