diff --git a/src/Package.py b/src/Package.py index c78bf78..6c47de6 100644 --- a/src/Package.py +++ b/src/Package.py @@ -1,6 +1,10 @@ +import shutil +import stat import os import json import Command +import ToolChaine +import webbrowser def add(author, package) -> None: f_conf = open("./config.json", "r") @@ -14,6 +18,26 @@ def add(author, package) -> None: install(author, package) +def remove(package) -> None: + f_conf = open("./config.json", "r") + conf = json.loads(f_conf.read()) + f_conf.close() + conf["packages"] = [pkg for pkg in conf["packages"] if pkg['name'] != package] + r_remove(package) + f_conf = open("./config.json", "w") + f_conf.write(json.dumps(conf, indent=4)) + f_conf.close() + +def r_remove(package) -> None: + print(f"Removing {package}") + if not os.path.exists(f"./vendor/{package}/") : raise Exception(f"Package {package} not the dependencies") + if os.path.exists(f"./vendor/{package}/config.json") : + r_pkgs = json.loads(open(f"./vendor/{package}/config.json", "r").read())["packages"] + for r_pkg in r_pkgs: + r_remove(r_pkg["name"]) + os.chmod(f"./vendor/{package}/", stat.S_IRUSR | stat.S_IWUSR | stat.S_IXUSR) + shutil.rmtree(f"./vendor/{package}/", ignore_errors=True) + def install_root() -> None: if not os.path.exists("./config.json"): raise Exception("No package config file") @@ -26,7 +50,8 @@ def install_root() -> None: def install(author, package) -> None: if os.path.exists(f"./vendor/{package}"): return - + if not ToolChaine.tool_exist("git"): + raise Exception("Tool missing git") Command.exec(f"git clone https://github.com/{author}/{package} ./vendor/{package}") if os.path.exists(f"./vendor/{package}/config.json"): @@ -49,8 +74,14 @@ def install(author, package) -> None: dep = open(f"./deps.lua", "a") dep.write("\n" + pkg_deps) dep.close() - - - +def load_doc(package) -> None: + if not ToolChaine.tool_exist("doxygen"): + raise Exception("Tool missing doxygen") + Command.exec(f"doxygen ./vendor/{package}") + webbrowser.open("file://" + os.path.realpath(f"./vendor/{package}/html/index.html")) + + + + \ No newline at end of file diff --git a/src/Project.py b/src/Project.py index 24b1286..87b351a 100644 --- a/src/Project.py +++ b/src/Project.py @@ -20,7 +20,6 @@ class Project: def create(self) -> None: self.create_folder() self.config() - if not self.as_git_repo(): self.init_git_repo() def config(self) -> None: conf = { @@ -70,6 +69,7 @@ class Project: return os.path.exists("./.git") def init_git_repo(self) -> None: + if not self.as_git_repo(): return Command.exec("git init --initial-branch=main") Command.exec("git add .") Command.exec('git commit -m "Initial commit"') diff --git a/src/Buildtools.py b/src/ToolChaine.py similarity index 59% rename from src/Buildtools.py rename to src/ToolChaine.py index af49485..b4c6d64 100644 --- a/src/Buildtools.py +++ b/src/ToolChaine.py @@ -1,5 +1,6 @@ import platform import os +import json import Command def tool_exist(name: str) -> bool: @@ -13,7 +14,7 @@ def search_tools(tools: str) -> str: none_tools.append(tool) return none_tools -def verifie_tools() -> None: +def verifie_build_tools() -> None: none_tools: str = [] match platform.system(): case "Windows": @@ -25,10 +26,18 @@ def verifie_tools() -> None: if len(none_tools) > 0: raise Exception(f"Tools missing {none_tools}") +def run(config) -> None: + if not os.path.exists("./config.json"): raise Exception("Project not found") + conf = json.loads(open("./config.json").read()) + name = conf["name"].lower() + print(f"./bin/{platform.system().lower()}-{platform.machine().lower()}-{config.lower()}/{name}/{name}") + if not os.path.exists(f"./bin/{platform.system().lower()}-{platform.machine().lower()}-{config.lower()}/{name}/{name}"): + raise Exception("Executable not found") + Command.exec(f"./bin/{platform.system().lower()}-{platform.machine().lower()}-{config.lower()}/{name}/{name}") -def build() -> None: - verifie_tools() +def build(config) -> None: + verifie_build_tools() match platform.system(): case "Windows": Command.exec("premake5 vs2022") diff --git a/src/main.py b/src/main.py index 3922221..bd23053 100644 --- a/src/main.py +++ b/src/main.py @@ -1,46 +1,78 @@ import os -import sys import argparse import Package -from Buildtools import verifie_tools +import ToolChaine from Project import Project def init(args) -> None: - if not os.path.exists(args.path): os.mkdir(args.path) - os.chdir(args.path) + print(f"Initialising new project : {args.name} by {args.owner}") + print(f"Path to the project : {args.path}") + print(f"Git repository : {args.repo}") project = Project(args.name, args.repo, args.owner) project.create() + if args.git_init: + print("Initialising local git folder") + project.init_git_repo() def add(args) -> None: Package.add(args.author, args.name) +def remove(args) -> None: + Package.remove(args.name) + def install(args) -> None: Package.install_root() +def doc(args) -> None: + Package.load_doc(args.package) + +def build(args) -> None: + ToolChaine.build(args.config) + +def run(args) -> None: + ToolChaine.run(args.config) + def bakasable() -> None: program_parser = argparse.ArgumentParser(prog="bakasable", description="baka developpement enviromment") + program_parser.add_argument("-p", "--path", type=str, default="./", dest="path", help="path to the project") sub_parsers = program_parser.add_subparsers(title="subcommmands", help="operations on your project") init_parser = sub_parsers.add_parser("init", help="initialise a new project") - init_parser.add_argument("-n", "--name", type=str, required=True, dest="name") - init_parser.add_argument("-p", "--path", type=str, default="./", dest="path") - init_parser.add_argument("-r", "--repo", type=str, default="", dest="repo") - init_parser.add_argument("-o", "--owner", type=str, default="", dest="owner") + init_parser.add_argument("-n", "--name", type=str, required=True, dest="name", help="name of your") + init_parser.add_argument("-r", "--repo", type=str, default="", dest="repo", help="git repository where project is stored") + init_parser.add_argument("-o", "--owner", type=str, default="", dest="owner", help="owner of the project") + init_parser.add_argument("-g", "--git-init", action="store_const", const=True, default=False, dest="git_init", help="initialise a local git folder") init_parser.set_defaults(func=init) - add_parser = sub_parsers.add_parser("add", help="add a module to your project") - add_parser.add_argument("-n", "--name", type=str, required=True, dest="name") - add_parser.add_argument("-a", "--author", type=str, required=True, dest="author") + add_parser = sub_parsers.add_parser("add", help="add a module to your project from github") + add_parser.add_argument("-n", "--name", type=str, required=True, dest="name", help="name of the github repository") + add_parser.add_argument("-a", "--author", type=str, required=True, dest="author", help="name of the github user") add_parser.set_defaults(func=add) - install_parser = sub_parsers.add_parser("install", help="add a module to your project") + remove_parser = sub_parsers.add_parser("remove", help="remove a module from your project") + remove_parser.add_argument("-n", "--name", type=str, required=True, dest="config", help="name of the github repository") + remove_parser.set_defaults(func=remove) + + install_parser = sub_parsers.add_parser("install", help="installs the dependencies of your project") install_parser.set_defaults(func=install) + build_parser = sub_parsers.add_parser("build", help="") + build_parser.add_argument("-c", "--config", type=str, required=True, dest="config", help="", choices=["Debug", "Release"]) + build_parser.set_defaults(func=build) + + run_parser = sub_parsers.add_parser("run", help="") + run_parser.add_argument("-c", "--config", type=str, required=True, dest="config", help="", choices=["Debug", "Release"]) + run_parser.set_defaults(func=run) + args = program_parser.parse_args() + if not os.path.exists(args.path): os.mkdir(args.path) + os.chdir(args.path) args.func(args) if __name__ == "__main__": - print(""" ____ _ _ __ _ ____ _ ____ _ _____ + print( +""" + ____ _ _ __ _ ____ _ ____ _ _____ | __ ) / \\ | |/ / / \\ / ___| / \\ | __ )| | | ____| | _ \\ / _ \\ | ' / / _ \\ \\___ \\ / _ \\ | _ \\| | | _| | |_) / ___ \\| . \\ / ___ \\ ___) / ___ \\| |_) | |___| |___