Les choses sérieuses commencent
This commit is contained in:
parent
7a9fe18463
commit
c63f62721b
41 changed files with 1270 additions and 0 deletions
0
erminig/cli/__init__.py
Normal file
0
erminig/cli/__init__.py
Normal file
54
erminig/cli/evezh.py
Normal file
54
erminig/cli/evezh.py
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
import argparse
|
||||
import json
|
||||
from erminig.controllers.evezh import check
|
||||
from erminig.models.db import init_db
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Evezh – Veille logicielle artisanale")
|
||||
subparsers = parser.add_subparsers(dest="command")
|
||||
|
||||
init_parser = subparsers.add_parser("init", help="Initialiser la base de données")
|
||||
|
||||
check_parser = subparsers.add_parser("check")
|
||||
check_parser.add_argument("--config")
|
||||
check_parser.add_argument("--output")
|
||||
check_parser.add_argument("--stdout", action="store_true")
|
||||
|
||||
sync_parser = subparsers.add_parser("sync")
|
||||
sync_parser.add_argument("--config", required=True)
|
||||
sync_parser.add_argument("--db", required=True)
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "init":
|
||||
init_db()
|
||||
|
||||
if args.command == "check":
|
||||
state = check.load_state(args.output) if args.output else {}
|
||||
results = check.check_versions(args.config, state)
|
||||
new_state = {}
|
||||
updated = []
|
||||
|
||||
for r in results:
|
||||
name, version, url = r["name"], r["version"], r["url"]
|
||||
if state.get(name, {}).get("version") != version:
|
||||
updated.append(r)
|
||||
new_state[name] = {"version": version, "url": url}
|
||||
|
||||
if args.output:
|
||||
check.save_state(args.output, new_state)
|
||||
|
||||
if updated:
|
||||
print(f"\n{len(updated)} mise(s) à jour détectée(s) :")
|
||||
for r in updated:
|
||||
print(f" - {r['name']} → {r['version']}")
|
||||
else:
|
||||
print("Aucun changement détecté.")
|
||||
|
||||
if args.stdout:
|
||||
print("\n--- Résultat complet ---")
|
||||
print(json.dumps(results, indent=2))
|
||||
|
||||
elif args.command == "sync":
|
||||
check.sync_db(args.config)
|
||||
37
erminig/cli/govel.py
Normal file
37
erminig/cli/govel.py
Normal file
|
|
@ -0,0 +1,37 @@
|
|||
import argparse
|
||||
from erminig.config import Config
|
||||
from erminig.controllers.govel.pakva import Pakva
|
||||
from erminig.controllers.govel.build import run_build_function
|
||||
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Govel – Build artisanal Erminig")
|
||||
subparsers = parser.add_subparsers(dest="command")
|
||||
|
||||
build_parser = subparsers.add_parser("build")
|
||||
build_parser.add_argument("--name", help="Nom du paquet à builder")
|
||||
|
||||
args = parser.parse_args()
|
||||
|
||||
if args.command == "build":
|
||||
if args.name:
|
||||
pakva = Pakva(name=args.name, version=None, archive=None)
|
||||
pakva.read()
|
||||
else:
|
||||
if not Config.PAKVA_DIR.exists():
|
||||
print("[GOVEL] Erreur : Aucun Pakva trouvé ici.")
|
||||
return
|
||||
pakva = Pakva(name="local", version=None, archive=None)
|
||||
pakva.path = Config.PAKVA_DIR
|
||||
pakva.read()
|
||||
|
||||
build_success = run_build_function(pakva.path)
|
||||
|
||||
if build_success:
|
||||
print(f"[GOVEL] Build réussi pour {pakva.name}")
|
||||
else:
|
||||
print(f"[GOVEL] Build échoué pour {pakva.name}")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
56
erminig/cli/init.py
Normal file
56
erminig/cli/init.py
Normal file
|
|
@ -0,0 +1,56 @@
|
|||
import os
|
||||
import subprocess
|
||||
import sys
|
||||
from pathlib import Path
|
||||
from erminig.system.security import check_root, check_user_exists
|
||||
from erminig.config import Config # Voilà la différence clé !
|
||||
|
||||
PAK_USER = Config.PAK_USER
|
||||
|
||||
|
||||
def create_user_pak():
|
||||
"""Crée l'utilisateur pak si nécessaire."""
|
||||
if check_user_exists(PAK_USER):
|
||||
print(f"[INIT] Utilisateur '{PAK_USER}' existe déjà.")
|
||||
return
|
||||
|
||||
print(f"[INIT] Création de l'utilisateur '{PAK_USER}'...")
|
||||
subprocess.run(
|
||||
[
|
||||
"useradd",
|
||||
"-r",
|
||||
"-d",
|
||||
str(Config.LIB_DIR),
|
||||
"-s",
|
||||
"/usr/sbin/nologin",
|
||||
PAK_USER,
|
||||
],
|
||||
check=True,
|
||||
)
|
||||
print(f"[INIT] Utilisateur '{PAK_USER}' créé.")
|
||||
|
||||
|
||||
def setup_directories():
|
||||
"""Crée les dossiers nécessaires et assigne les permissions."""
|
||||
for directory in [Config.LIB_DIR, Config.CACHE_DIR]:
|
||||
if not directory.exists():
|
||||
print(f"[INIT] Création du dossier {directory}...")
|
||||
directory.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
print(f"[INIT] Attribution de {directory} à '{PAK_USER}'...")
|
||||
subprocess.run(
|
||||
["chown", "-R", f"{PAK_USER}:{PAK_USER}", str(directory)], check=True
|
||||
)
|
||||
|
||||
|
||||
def main():
|
||||
check_root()
|
||||
|
||||
create_user_pak()
|
||||
setup_directories()
|
||||
|
||||
print("[INIT] Environnement Erminig initialisé avec succès.")
|
||||
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Loading…
Add table
Add a link
Reference in a new issue