added remove functionality of libraries
This commit is contained in:
parent
07576d14a4
commit
b550740738
@ -1,5 +1,4 @@
|
|||||||
import os
|
import os
|
||||||
import re
|
|
||||||
from typing import Any
|
from typing import Any
|
||||||
import toml
|
import toml
|
||||||
import datetime
|
import datetime
|
||||||
@ -66,6 +65,23 @@ def writeProjectFile(projectDict: dict[str, Any]) -> tuple[bool, str]:
|
|||||||
except:
|
except:
|
||||||
return (False, "Reading Project file failed, permissions may be set wrong")
|
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]:
|
def addLibraryInProject(lib: str, std: str) -> tuple[bool, str]:
|
||||||
[exists, output] = loadProjectFile()
|
[exists, output] = loadProjectFile()
|
||||||
@ -86,9 +102,6 @@ def addLibraryInProject(lib: str, std: str) -> tuple[bool, str]:
|
|||||||
return (wentWell, "")
|
return (wentWell, "")
|
||||||
return (False, "Library with this name is already declared")
|
return (False, "Library with this name is already declared")
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
def createProjectFileTemplate(projectName: str) -> str:
|
def createProjectFileTemplate(projectName: str) -> str:
|
||||||
return f"""
|
return f"""
|
||||||
title = "{projectName}"
|
title = "{projectName}"
|
||||||
@ -106,3 +119,4 @@ if __name__ == "__main__":
|
|||||||
print(findProjectFile())
|
print(findProjectFile())
|
||||||
print(findProjectRoot())
|
print(findProjectRoot())
|
||||||
print(addLibraryInProject("ganimede", "93"))
|
print(addLibraryInProject("ganimede", "93"))
|
||||||
|
print(removeLibraryInProject("ganimede"))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user