Add: --force option to delete existing package
This commit is contained in:
parent
6a6d439aa2
commit
56bd015690
5 changed files with 69 additions and 10 deletions
8
Makefile
8
Makefile
|
|
@ -19,10 +19,10 @@ up:
|
|||
rebuild: docker-build up
|
||||
|
||||
clean:
|
||||
find . -name "*.pyc" -delete
|
||||
find . -name "__pycache__" -type d -exec rm -rf {} +
|
||||
find . -name "*.egg-info" -type d -exec rm -rf {} +
|
||||
find . -name ".pytest_cache" -type d -exec rm -rf {} +
|
||||
sudo find . -name "*.pyc" -delete
|
||||
sudo find . -name "__pycache__" -type d -exec rm -rf {} +
|
||||
sudo find . -name "*.egg-info" -type d -exec rm -rf {} +
|
||||
sudo find . -name ".pytest_cache" -type d -exec rm -rf {} +
|
||||
|
||||
build-all: fmt test docker-build
|
||||
|
||||
|
|
|
|||
|
|
@ -13,6 +13,9 @@ from erminig.core.config import Config
|
|||
from erminig.controllers.govel.pakva import Pakva
|
||||
from erminig.controllers.govel.build import run_build_function, run_pak_function
|
||||
from erminig.core.package import Package
|
||||
from erminig.core.security import run_as_user
|
||||
import os
|
||||
import subprocess
|
||||
|
||||
|
||||
def main():
|
||||
|
|
@ -21,6 +24,17 @@ def main():
|
|||
|
||||
build_parser = subparsers.add_parser("build")
|
||||
build_parser.add_argument("--name", help="Nom du paquet à builder")
|
||||
build_parser.add_argument(
|
||||
"--force",
|
||||
action="store_true",
|
||||
help="Force le build même si le dossier existe déjà",
|
||||
)
|
||||
|
||||
new_parser = subparsers.add_parser("new")
|
||||
new_parser.add_argument("--name", required=True, help="Nom du paquet")
|
||||
|
||||
edit_parser = subparsers.add_parser("edit")
|
||||
edit_parser.add_argument("--name", required=True, help="Nom du paquet à éditer")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
|
|
@ -36,6 +50,19 @@ def main():
|
|||
|
||||
pak_success = False
|
||||
|
||||
tmp_path = Path(f"{Config.BUILD_DIR}/{pakva.name}-{pakva.version}")
|
||||
if tmp_path.exists():
|
||||
if not args.force:
|
||||
print(
|
||||
f"[GOVEL] Erreur : {tmp_path} existe déjà. Utilisez --force pour écraser."
|
||||
)
|
||||
return
|
||||
else:
|
||||
print(f"[GOVEL] Build forcé activé. Suppression de {tmp_path}…")
|
||||
import shutil
|
||||
|
||||
shutil.rmtree(tmp_path)
|
||||
|
||||
build_success = run_build_function(pakva.path, pakva.name, pakva.version)
|
||||
if build_success:
|
||||
pak_success = run_pak_function(pakva.path, pakva.name, pakva.version)
|
||||
|
|
@ -51,6 +78,21 @@ def main():
|
|||
else:
|
||||
print(f"[GOVEL] Build échoué pour {pakva.name}")
|
||||
|
||||
elif args.command == "new":
|
||||
if args.name:
|
||||
pakva = Pakva(args.name)
|
||||
pakva.save()
|
||||
|
||||
elif args.command == "edit":
|
||||
pakva = Pakva.load_from_name(args.name)
|
||||
open_editor(pakva.path)
|
||||
|
||||
|
||||
@run_as_user("pak")
|
||||
def open_editor(path):
|
||||
editor = os.getenv("EDITOR", "nvim")
|
||||
subprocess.run([editor, str(path)])
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
|
|
|
|||
|
|
@ -14,7 +14,7 @@ from erminig.core.security import run_as_user
|
|||
|
||||
class Pakva:
|
||||
|
||||
def __init__(self, name, version, archive):
|
||||
def __init__(self, name, version=None, archive=None):
|
||||
self.name = name
|
||||
self.version = version
|
||||
self.archive = archive
|
||||
|
|
|
|||
|
|
@ -27,12 +27,13 @@ class Package:
|
|||
def generate_manifest(self):
|
||||
install_root = self.tmp_dir / "tmp"
|
||||
for path in install_root.rglob("*"):
|
||||
rel_path = Path("/") / path.relative_to(install_root)
|
||||
stat = path.lstat()
|
||||
user = pwd.getpwuid(stat.st_uid).pw_name
|
||||
group = grp.getgrgid(stat.st_gid).gr_name
|
||||
|
||||
if path.is_file():
|
||||
rel_path = Path("/") / path.relative_to(install_root)
|
||||
stat = path.stat()
|
||||
md5 = hashlib.md5(path.read_bytes()).hexdigest()
|
||||
user = pwd.getpwuid(stat.st_uid).pw_name
|
||||
group = grp.getgrgid(stat.st_gid).gr_name
|
||||
self.manifest.append(
|
||||
{
|
||||
"path": str(rel_path),
|
||||
|
|
@ -40,6 +41,18 @@ class Package:
|
|||
"mode": oct(stat.st_mode & 0o777),
|
||||
"user": user,
|
||||
"group": group,
|
||||
"type": "file",
|
||||
}
|
||||
)
|
||||
elif path.is_dir():
|
||||
self.manifest.append(
|
||||
{
|
||||
"path": str(rel_path),
|
||||
"md5": "-", # pas de hash pour les dossiers
|
||||
"mode": oct(stat.st_mode & 0o777),
|
||||
"user": user,
|
||||
"group": group,
|
||||
"type": "dir",
|
||||
}
|
||||
)
|
||||
|
||||
|
|
@ -48,7 +61,7 @@ class Package:
|
|||
with open(manifest_path, "w") as f:
|
||||
for entry in self.manifest:
|
||||
f.write(
|
||||
f"{entry['path']} {entry['md5']} {entry['mode']} {entry['user']} {entry['group']}\n"
|
||||
f"{entry['type']} {entry['path']} {entry['md5']} {entry['mode']} {entry['user']} {entry['group']}\n"
|
||||
)
|
||||
|
||||
def copy_pakva(self, pakva_path):
|
||||
|
|
|
|||
|
|
@ -53,6 +53,10 @@ def run_as_user(username):
|
|||
os.setgid(user_gid)
|
||||
os.setuid(user_uid)
|
||||
|
||||
os.environ["HOME"] = pw_record.pw_dir
|
||||
os.environ["LOGNAME"] = pw_record.pw_name
|
||||
os.environ["USER"] = pw_record.pw_name
|
||||
|
||||
result = func(*args, **kwargs)
|
||||
os._exit(0 if result is None else int(bool(result)))
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue