checkpoint: before ai yeets it again
This commit is contained in:
@@ -55,19 +55,32 @@ class PresetManager:
|
||||
data["presets"][preset.name] = preset.to_dict()
|
||||
self._save_file(path, data)
|
||||
|
||||
def delete_preset(self, name: str, scope: str = "project") -> None:
|
||||
"""Deletes a preset by name from the specified scope."""
|
||||
path = self.global_path if scope == "global" else self.project_path
|
||||
if not path:
|
||||
if scope == "project":
|
||||
raise ValueError("Project scope requested but no project_root provided.")
|
||||
path = self.global_path
|
||||
|
||||
def delete_preset(self, name: str, scope: str) -> None:
|
||||
if scope == "project" and self.project_root:
|
||||
path = get_project_presets_path(self.project_root)
|
||||
else:
|
||||
path = get_global_presets_path()
|
||||
|
||||
data = self._load_file(path)
|
||||
if "presets" in data and name in data["presets"]:
|
||||
if name in data.get("presets", {}):
|
||||
del data["presets"][name]
|
||||
self._save_file(path, data)
|
||||
|
||||
def get_preset_scope(self, name: str) -> str:
|
||||
"""Returns the scope ('global' or 'project') of a preset by name."""
|
||||
if self.project_root:
|
||||
project_p = get_project_presets_path(self.project_root)
|
||||
project_data = self._load_file(project_p)
|
||||
if name in project_data.get("presets", {}):
|
||||
return "project"
|
||||
|
||||
global_p = get_global_presets_path()
|
||||
global_data = self._load_file(global_p)
|
||||
if name in global_data.get("presets", {}):
|
||||
return "global"
|
||||
|
||||
return "project"
|
||||
|
||||
def _load_file(self, path: Path) -> Dict[str, Any]:
|
||||
if not path.exists():
|
||||
return {"presets": {}}
|
||||
@@ -85,8 +98,7 @@ class PresetManager:
|
||||
|
||||
def _save_file(self, path: Path, data: Dict[str, Any]) -> None:
|
||||
if path.parent.exists() and path.parent.is_file():
|
||||
raise ValueError(f"Cannot save to {path}: Parent directory {path.parent} is a file. The project root seems to be a file.")
|
||||
raise ValueError(f"Cannot save to {path}: Parent directory {path.parent} is a file.")
|
||||
path.parent.mkdir(parents=True, exist_ok=True)
|
||||
with open(path, "wb") as f:
|
||||
f.write(tomli_w.dumps(data).encode("utf-8"))
|
||||
|
||||
|
||||
Reference in New Issue
Block a user