Export and import all of SaraSortd's configs

Settings > SaraSortd can export GlobalConf.toml, both templates and every
directory's config as one file, and import it again. An import backs up
the current configs first; directories that don't exist can be given a new
path (InputDir/OutputDir, ValidInputDirs and the config's own name follow)
or made.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
This commit is contained in:
sarahandClaude Opus 5.5 committed 2026-10-07 22:44:39 +02:00
1 parent e90f59bc16
commit 60da6dd9ab
4 files changed
+337 -8

No files matched your search

+11 -6
View File
@@ -114,16 +114,21 @@ class Setup:
"""GlobalConf.toml plus everything reachable from it. Cheap to reload:
pages just make a new one after each change."""
def __init__(self, Config: AppConfig):
def __init__(self, Config: AppConfig, Document: Optional[tomlkit.TOMLDocument] = None):
"""Document: a GlobalConf.toml that isn't on disk yet (an import being
checked); otherwise it's read from SortdConfigDir."""
self.Config = Config
self.ConfDir = Path(Config.SortdConfigDir).expanduser()
self.GlobalPath = Config.GlobalConfPath
if not self.GlobalPath.exists():
if Document is not None:
self.Global = Document
elif not self.GlobalPath.exists():
raise SortdError(f"No GlobalConf.toml at {self.GlobalPath}")
try:
self.Global = ReadToml(self.GlobalPath)
except tomlkit.exceptions.TOMLKitError as Error:
raise SortdError(f"GlobalConf.toml can't be read: {Error}") from Error
else:
try:
self.Global = ReadToml(self.GlobalPath)
except tomlkit.exceptions.TOMLKitError as Error:
raise SortdError(f"GlobalConf.toml can't be read: {Error}") from Error
self.Data = self.Global.unwrap()
self.Vars = self.Data.get("Variables", {})
self.Dirs = self.Data.get("DirectoryPaths", {})