Removal of gantry from this repo #14
@ -1,8 +1,16 @@
|
|||||||
import os
|
import os
|
||||||
|
import re
|
||||||
from typing import Any
|
from typing import Any
|
||||||
import toml
|
import toml
|
||||||
import datetime
|
import datetime
|
||||||
|
|
||||||
|
|
||||||
|
def findProjectRoot() -> tuple[bool, str]:
|
||||||
|
[exists, projectFile] = findProjectFile()
|
||||||
|
if not exists:
|
||||||
|
return (False, "")
|
||||||
|
return (True, "/".join(projectFile.split("/")[0:-1]))
|
||||||
|
|
||||||
def findProjectFile() -> tuple[bool, str]:
|
def findProjectFile() -> tuple[bool, str]:
|
||||||
cwd = os.getcwd().split("/")
|
cwd = os.getcwd().split("/")
|
||||||
for i in range(len(cwd) - 2):
|
for i in range(len(cwd) - 2):
|
||||||
@ -43,14 +51,48 @@ def loadProjectFile() -> tuple[bool, str | dict[str, Any]] :
|
|||||||
with open(path, "r") as f:
|
with open(path, "r") as f:
|
||||||
toml.load
|
toml.load
|
||||||
parsedTOML = toml.load(f)
|
parsedTOML = toml.load(f)
|
||||||
print(parsedTOML)
|
|
||||||
return (True, parsedTOML)
|
return (True, parsedTOML)
|
||||||
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 writeProjectFile(projectDict: dict[str, Any]) -> tuple[bool, str]:
|
||||||
|
[exists, path] = findProjectFile()
|
||||||
|
if not exists:
|
||||||
|
return (False, "")
|
||||||
|
try:
|
||||||
|
with open(path, "w") as f:
|
||||||
|
toml.dump(projectDict, f)
|
||||||
|
return (True, "")
|
||||||
|
except:
|
||||||
|
return (False, "Reading Project file failed, permissions may be set wrong")
|
||||||
|
|
||||||
|
|
||||||
|
def addLibraryInProject(lib: str, std: 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():
|
||||||
|
projectDict["libraries"] = {}
|
||||||
|
if lib not in projectDict["libraries"].keys():
|
||||||
|
projectDict["libraries"][lib] = {}
|
||||||
|
projectDict["libraries"][lib]["vhdl-version"] = std
|
||||||
|
projectDict["libraries"][lib]["path"] = os.path.join(os.getcwd(), lib)
|
||||||
|
[wentWell, _] = writeProjectFile(projectDict)
|
||||||
|
return (wentWell, "")
|
||||||
|
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}"
|
||||||
createdAt = "{datetime.time()}"
|
createdAt = "{datetime.date.today()}"
|
||||||
maintainer = ""
|
maintainer = ""
|
||||||
email = ""
|
email = ""
|
||||||
version = "0.0.1"
|
version = "0.0.1"
|
||||||
@ -59,5 +101,8 @@ version = "0.0.1"
|
|||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
|
print(initProjectFile("test"))
|
||||||
print(loadProjectFile())
|
print(loadProjectFile())
|
||||||
print(findProjectFile())
|
print(findProjectFile())
|
||||||
|
print(findProjectRoot())
|
||||||
|
print(addLibraryInProject("ganimede", "93"))
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user