From b550740738547be7c045d94881a824a3de51265d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Erik=20=C3=96rtenberg?= Date: Wed, 12 Mar 2025 17:27:52 +0100 Subject: [PATCH] added remove functionality of libraries --- scripts/project_man.py | 22 ++++++++++++++++++---- 1 file changed, 18 insertions(+), 4 deletions(-) diff --git a/scripts/project_man.py b/scripts/project_man.py index bdd1484..425ad20 100644 --- a/scripts/project_man.py +++ b/scripts/project_man.py @@ -1,5 +1,4 @@ import os -import re from typing import Any import toml import datetime @@ -66,6 +65,23 @@ def writeProjectFile(projectDict: dict[str, Any]) -> tuple[bool, str]: except: return (False, "Reading Project file failed, permissions may be set wrong") +def removeLibraryInProject(lib: str) -> tuple[bool, str]: + [exists, output] = loadProjectFile() + if not exists: + return (False, "Project doesn't exist.") + projectDict = {} + if isinstance(output, dict): + projectDict = output + else: + return (False, "Output wasn't a dictionary") + if "libraries" not in projectDict.keys(): + return (False, "No libraries are declared in this project.") + if lib in projectDict["libraries"].keys(): + projectDict["libraries"].pop(lib) + [wentWell, _] = writeProjectFile(projectDict) + return (wentWell, "") + return (False, "Library with this name is not declared") + def addLibraryInProject(lib: str, std: str) -> tuple[bool, str]: [exists, output] = loadProjectFile() @@ -86,9 +102,6 @@ def addLibraryInProject(lib: str, std: str) -> tuple[bool, str]: return (wentWell, "") return (False, "Library with this name is already declared") - - - def createProjectFileTemplate(projectName: str) -> str: return f""" title = "{projectName}" @@ -106,3 +119,4 @@ if __name__ == "__main__": print(findProjectFile()) print(findProjectRoot()) print(addLibraryInProject("ganimede", "93")) + print(removeLibraryInProject("ganimede"))