mirror of
https://git.srhtnin.garden/sarah/SaraSortd.git
synced 2026-10-13 18:38:11 +02:00
7.5: Windows support
This commit is contained in:
1 parent
4a52120b1a
commit
a6a5b28631
6 files changed
+19
-14
No files matched your search
+12
-7
@@ -6,7 +6,7 @@ import shutil
|
||||
import time
|
||||
import toml
|
||||
|
||||
# Version = "7.4"
|
||||
# Version = "7.5"
|
||||
|
||||
ConfPath = "./GlobalConf.toml"
|
||||
|
||||
@@ -235,16 +235,21 @@ def ConfFolder(PathText):
|
||||
return os.path.normpath(os.path.join(os.path.dirname(os.path.abspath(ConfPath)), PathText))
|
||||
|
||||
|
||||
def Slashes(Path):
|
||||
# Windows paths use "\\" (and configs may mix both); compare and name them with "/" only.
|
||||
return Path.replace("\\", "/")
|
||||
|
||||
|
||||
def FlatName(Path):
|
||||
# A directory's name for files kept outside it: its path below RootDir (or its whole path), "/" turned into "_".
|
||||
# E.G: "%RootDir%/Pictures/Cats" becomes "Pictures_Cats".
|
||||
Root = ParsePath(ConfDirs.get("RootDir", "")).rstrip("/")
|
||||
Path = Path.rstrip("/")
|
||||
# E.G: "%RootDir%/Pictures/Cats" becomes "Pictures_Cats". On Windows a drive's ":" is dropped (not allowed in names).
|
||||
Root = Slashes(ParsePath(ConfDirs.get("RootDir", ""))).rstrip("/")
|
||||
Path = Slashes(Path).rstrip("/")
|
||||
if Root and Path.startswith(Root + "/"):
|
||||
Relative = Path[len(Root) + 1:]
|
||||
else:
|
||||
Relative = Path.strip("/") or os.path.basename(Path)
|
||||
return Relative.replace("/", "_")
|
||||
return Relative.replace(":", "").replace("/", "_")
|
||||
|
||||
|
||||
def CentralConf(Path, Kind):
|
||||
@@ -252,7 +257,7 @@ def CentralConf(Path, Kind):
|
||||
# [DirConfs] names a file per directory ("dir" = "file", or "dir" = { In = "file", Out = "file" }),
|
||||
# and DirConfDir holds the configs of every directory [DirConfs] doesn't name. None means inside the directory.
|
||||
for Key, Value in (Conf.get("DirConfs") or {}).items():
|
||||
if ParsePath(Key).rstrip("/") == Path.rstrip("/"):
|
||||
if Slashes(ParsePath(Key)).rstrip("/") == Slashes(Path).rstrip("/"):
|
||||
if isinstance(Value, dict):
|
||||
Value = Value.get(Kind)
|
||||
if Value:
|
||||
@@ -301,7 +306,7 @@ def Clone(Source, Destination, NewName, Delete = False):
|
||||
with open(FileHistoryPath, "w", encoding = "utf-8") as HistoryFile:
|
||||
toml.dump(HistoryFileData, HistoryFile)
|
||||
|
||||
os.rename(Source, os.path.join(Destination, NewName))
|
||||
os.replace(Source, os.path.join(Destination, NewName)) # overwrites on Windows too, like rename on Linux
|
||||
return
|
||||
|
||||
Dir(Destination, Output = False, CopyConf = False)
|
||||
|
||||
Reference in new issue
Block a user