Functionnal packet manager

dev
anulax1225 ago%!(EXTRA string=12 months)
parent e39362ddf1
commit b18457acad
  1. 2
      src/Command.py
  2. 30
      src/Log.py
  3. 145
      src/Package.py
  4. 3
      src/Premake/App.py
  5. 2
      src/Premake/Wks.py
  6. 7
      src/Project.py
  7. 22
      src/ToolChaine.py
  8. 48
      src/main.py

@ -2,4 +2,4 @@ import os
import sys
def exec(command):
os.system(f"{command} > bakasable.log")
os.system(f"{command}")

@ -0,0 +1,30 @@
class ShColors:
HEADER = '\033[95m'
OKBLUE = '\033[94m'
OKCYAN = '\033[96m'
OKGREEN = '\033[92m'
WARNING = '\033[93m'
FAIL = '\033[91m'
ENDC = '\033[0m'
BOLD = '\033[1m'
UNDERLINE = '\033[4m'
def logo() -> None:
print(
f"""
{ShColors.BOLD}____ _ _ __ _ ____ _ ____ _ _____
| __ ) / \\ | |/ / / \\ / ___| / \\ | __ )| | | ____|
| _ \\ / _ \\ | ' / / _ \\ \\___ \\ / _ \\ | _ \\| | | _|
| |_) / ___ \\| . \\ / ___ \\ ___) / ___ \\| |_) | |___| |___
|____/_/ \\_\\_|\\_\\/_/ \\_\\____/_/ \\_\\____/|_____|_____|
{ShColors.ENDC}""")
def info(message) -> None:
print(f"{ShColors.OKGREEN}[INFO] :{message}{ShColors.ENDC}")
def warning(message) -> None:
print(f"{ShColors.WARNING}[WARNING] : {message}{ShColors.ENDC}")
def error(message) -> None:
print(f"{ShColors.FAIL}[ERROR] : {ShColors.UNDERLINE}{message}{ShColors.ENDC}")
exit(1)

@ -5,81 +5,142 @@ import json
import Command
import ToolChaine
import webbrowser
import Log
def config(package):
if os.path.exists(f"./vendor/{package}/dependencies"):
dep = open(f"./vendor/{package}/dependencies", "r")
pkg_deps = dep.read()
dep.close()
if not os.path.exists("./dependencies.lua"):
dep = open("./dependencies.lua", "w")
dep.write("IncludeDirs = {}")
dep.write("\n" + pkg_deps)
dep.close()
else:
dep = open(f"./dependencies.lua", "a")
dep.write("\n" + pkg_deps)
dep.close()
linker = []
if os.path.exists(f"./vendor/{package}/package.json"):
f_conf = open(f"./vendor/{package}/package.json", "r")
conf = json.loads(f_conf.read())
f_conf.close()
linker.append({
"links": conf["links"],
"includes": conf["includes"]
})
if len(conf["packages"]):
for pkg in conf["packages"]:
linker += config(pkg["name"])
return linker
def reconfig():
f_conf = open("./package.json", "r")
conf = json.loads(f_conf.read())
f_conf.close()
if os.path.exists("./dependencies.lua"): os.remove("./dependencies.lua")
if os.path.exists("./app/linker.lua"): os.remove("./app/linker.lua")
linkers = []
for package in conf["packages"]:
linkers += config(package["name"])
links = "\nlinks\n{\n"
includes = "\nincludedirs\n{\n"
for linker in linkers:
if len(linker["links"]):
for link in linker["links"]:
if len(link): links += '\t"%{' + link + '}",\n'
if len(linker["includes"]):
for include in linker["includes"]:
if len(include): includes += '\t"%{' + include + '}",\n'
links += "}\n"
includes += "}\n"
f_linker= open("./app/linker.lua", "w")
f_linker.write(includes + links)
f_linker.close()
def install(author, package) -> None:
Log.info(f"Installing {package}")
if os.path.exists(f"./vendor/{package}"):
Log.warning("Package already added")
return
if not ToolChaine.tool_exist("git"):
Log.error("Tool missing git")
Command.exec(f"git clone --depth 5 https://github.com/{author}/{package} ./vendor/{package}")
if os.path.exists(f"./vendor/{package}/package.json"):
conf = open(f"./vendor/{package}/package.json", "r").read()
conf = json.loads(conf)
if len(conf["packages"]) > 0:
for pkg in conf["packages"]:
install(pkg["author"], pkg["name"])
def add(author, package) -> None:
f_conf = open("./config.json", "r")
f_conf = open("./package.json", "r")
conf = json.loads(f_conf.read())
f_conf.close()
if package in conf["packages"]: raise Exception("Package already added")
f_conf = open("./config.json", "w")
if package in conf["packages"]: Log.error("Package already added")
f_conf = open("./package.json", "w")
conf["packages"].append({ "author": author, "name": package})
f_conf.write(json.dumps(conf, indent=4))
f_conf.close()
install(author, package)
reconfig()
def update(package) -> None:
if not os.path.exists(f"./vendor/{package}"): Log.error("Package not found")
os.chdir(f"./vendor/{package}")
Command.exec("git pull")
reconfig()
def save(package, message) -> None:
if not os.path.exists(f"./vendor/{package}"): Log.error("Package not found")
os.chdir(f"./vendor/{package}")
Command.exec("git add .")
Command.exec(f'git commit -m "{message}"')
Command.exec("git push")
def remove(package) -> None:
f_conf = open("./config.json", "r")
f_conf = open("./package.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 = open("./package.json", "w")
f_conf.write(json.dumps(conf, indent=4))
f_conf.close()
reconfig()
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"]
Log.info(f"Removing {package}")
if not os.path.exists(f"./vendor/{package}/") : Log.error(f"Package {package} not the dependencies")
if os.path.exists(f"./vendor/{package}/package.json") :
r_pkgs = json.loads(open(f"./vendor/{package}/package.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")
f_conf = open("./config.json", "r")
if not os.path.exists("./package.json"):
Log.error("No package config file")
f_conf = open("./package.json", "r")
conf = json.loads(f_conf.read())
f_conf.close()
for pkg in conf["packages"]:
install(pkg["author"], pkg["name"])
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"):
conf = open(f"./vendor/{package}/config.json", "r").read()
conf = json.loads(conf)
if len(conf["packages"]) > 0:
for pkg in conf["packages"]:
install(pkg["author"], pkg["name"])
if os.path.exists(f"./vendor/{package}/dependencies.lua"):
dep = open(f"./vendor/{package}/dependencies.lua", "r")
pkg_deps = dep.read()
dep.close()
if not os.path.exists("./deps.lua"):
dep = open("./deps.lua", "w")
dep.write("IncludeDirs = {}")
dep.write("\n" + pkg_deps)
dep.close()
else:
dep = open(f"./deps.lua", "a")
dep.write("\n" + pkg_deps)
dep.close()
reconfig()
def load_doc(package) -> None:
if not ToolChaine.tool_exist("doxygen"):
raise Exception("Tool missing doxygen")
Log.error("Tool missing doxygen")
if not os.path.exists(f"./vendor/{package}/Doxyfile"):
Log.error("Doxygen config file not found")
Command.exec(f"doxygen ./vendor/{package}")
webbrowser.open("file://" + os.path.realpath(f"./vendor/{package}/html/index.html"))
webbrowser.open("file://" + os.path.realpath(f"./vendor/{package}/docs/html/index.html"))

@ -8,6 +8,8 @@ def get() -> str:
targetdir("%{wks.location}/bin/" .. outputdir .. "/%{prj.name}")
objdir("%{wks.location}/bin-int/" .. outputdir .. "/%{prj.name}")
include "linker.lua"
files
{
"src/**.h",
@ -46,5 +48,4 @@ filter "system:linux"
{
"BK_PLATFORM_LINUX"
}
filter ""
"""

@ -12,7 +12,7 @@ def get(name) -> str:
linkgroups "On"
outputdir = "%{cfg.system}-%{cfg.architecture}-%{cfg.buildcfg}"
include "deps.lua"
include "dependencies.lua"
group "App"
include "app"

@ -3,7 +3,7 @@ import json
import Premake
import Command
class Project:
class Builder:
def __init__(self, conf) -> None:
self.owner = conf["owner"]
self.name = conf["name"]
@ -28,7 +28,7 @@ class Project:
"git": self.git_repo,
"packages": []
}
file_conf = open("./config.json", "w")
file_conf = open("./package.json", "w")
file_conf.write(json.dumps(conf, indent=4))
file_conf.close()
wks = open("./premake5.lua", "w")
@ -58,11 +58,10 @@ class Project:
os.mkdir("./vendor")
os.mkdir("./app/src")
except: raise Exception("Directory already exists.")
create_file("./dependencies.lua")
create_file("./app/src/app.cpp")
create_file("./premake5.lua")
create_file("./app/premake5.lua")
create_file("./config.json")
create_file("./package.json")
create_file("./.gitignore")
def as_git_repo(self) -> bool:

@ -2,6 +2,7 @@ import platform
import os
import json
import Command
import Log
def tool_exist(name: str) -> bool:
from shutil import which
@ -22,18 +23,16 @@ def verifie_build_tools() -> None:
case "Linux":
none_tools = search_tools(["git", "g++", "premake5", "make"])
case _:
raise Exception("Platform not supported")
Log.error("Platform not supported")
if len(none_tools) > 0:
raise Exception(f"Tools missing {none_tools}")
Log.error(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}")
Log.info("Running app")
Log.info(f"./bin/{platform.system().lower()}-{platform.machine().lower()}-{config}/App/App")
if not os.path.exists(f"./bin/{platform.system().lower()}-{platform.machine().lower()}-{config}/App/App"):
Log.error("Executable not found")
Command.exec(f"chmod +x ./bin/{platform.system().lower()}-{platform.machine().lower()}-{config}/App/App && ./bin/{platform.system().lower()}-{platform.machine().lower()}-{config}/App/App")
def build(config) -> None:
@ -43,8 +42,7 @@ def build(config) -> None:
Command.exec("premake5 vs2022")
Command.exec("dotnet build")
case "Linux":
Command.exec("premake5 gmake2")
Command.exec("make")
Command.exec(f"premake5 gmake2 && make config={config.lower()}")
case _:
raise Exception("Platform not supported")
Log.error("Platform not supported")

@ -2,24 +2,32 @@ import os
import argparse
import Package
import ToolChaine
from Project import Project
import Log
import Project
def init(args) -> None:
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)
Log.info(f"Initialising new project : {args.name} by {args.owner}")
Log.info(f"Path to the project : {args.path}")
Log.info(f"Git repository : {args.repo}")
project = Project.Builder(args.name, args.repo, args.owner)
project.create()
if args.git_init:
print("Initialising local git folder")
Log.info("Initialising local git folder")
project.init_git_repo()
def add(args) -> None:
Package.add(args.author, args.name)
Package.reconfig()
def remove(args) -> None:
Package.remove(args.name)
def update(args) -> None:
Package.update(args.name)
def save(args) -> None:
Package.save(args.name, args.message)
def install(args) -> None:
Package.install_root()
@ -28,6 +36,7 @@ def doc(args) -> None:
def build(args) -> None:
ToolChaine.build(args.config)
if (args.run): ToolChaine.run(args.config)
def run(args) -> None:
ToolChaine.run(args.config)
@ -35,7 +44,7 @@ def run(args) -> None:
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")
sub_parsers = program_parser.add_subparsers(title="subcommmands", required=True, 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", help="name of your")
@ -50,14 +59,28 @@ def bakasable() -> None:
add_parser.set_defaults(func=add)
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.add_argument("-n", "--name", type=str, required=True, dest="name", help="name of the github repository")
remove_parser.set_defaults(func=remove)
update_parser = sub_parsers.add_parser("update", help="updates a module from your project")
update_parser.add_argument("-n", "--name", type=str, required=True, dest="name", help="name of the github repository")
update_parser.set_defaults(func=update)
save_parser = sub_parsers.add_parser("save", help="saves a module to it's repo")
save_parser.add_argument("-n", "--name", type=str, required=True, dest="name", help="name of the github repository")
save_parser.add_argument("-m", "--message", type=str, required=True, dest="message", help="message of the git commit")
save_parser.set_defaults(func=save)
install_parser = sub_parsers.add_parser("install", help="installs the dependencies of your project")
install_parser.set_defaults(func=install)
doc_parser = sub_parsers.add_parser("doc", help="documents a module from your project if it as one")
doc_parser.add_argument("-n", "--name", type=str, required=True, dest="name", help="name of the github repository")
doc_parser.set_defaults(func=doc)
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.add_argument("-r", "--run", action="store_const", const=True, default=False, dest="run", help="")
build_parser.set_defaults(func=build)
run_parser = sub_parsers.add_parser("run", help="")
@ -70,12 +93,5 @@ def bakasable() -> None:
args.func(args)
if __name__ == "__main__":
print(
"""
____ _ _ __ _ ____ _ ____ _ _____
| __ ) / \\ | |/ / / \\ / ___| / \\ | __ )| | | ____|
| _ \\ / _ \\ | ' / / _ \\ \\___ \\ / _ \\ | _ \\| | | _|
| |_) / ___ \\| . \\ / ___ \\ ___) / ___ \\| |_) | |___| |___
|____/_/ \\_\\_|\\_\\/_/ \\_\\____/_/ \\_\\____/|_____|_____|
""")
Log.logo()
bakasable()
Loading…
Cancel
Save