Files
library/back/core/command.py
2023-09-13 20:37:14 +03:00

36 lines
1012 B
Python

from os import mkdir
def create_project(name: str) -> None:
"""
Creates project folder and all required files.
from core import command; command.create_project("project")
Args:
name (str): The desired project name.
"""
def _create_file(
file_name: str, # Literal["__init__", "config", "create_schema", "model", "schema"],
content: str = None, # Optional[str] = None,
) -> None:
file = open("config/module/" + name + "/" + file_name, "w")
if content:
file.write(content)
file.close()
mkdir("config/module/" + name)
files_without_content = ("__init__.py", "config.yaml")
files_with_content = ("create_schema.py", "model.py", "schema.py")
content = "from core.util import update_module_locals\n\nupdate_module_locals(__name__, locals())\n"
for file_name in files_without_content:
_create_file(file_name)
for file_name in files_with_content:
_create_file(file_name, content)