added remove functionality of libraries

This commit is contained in:
Erik Örtenberg 2025-03-12 17:27:52 +01:00
parent 07576d14a4
commit b550740738

View File

@ -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"))