2025-04-29 17:35:21 +02:00
|
|
|
|
#
|
|
|
|
|
|
# Erminig - Analyse d'arguments pour evezh
|
|
|
|
|
|
# Copyright (C) 2025 L0m1g
|
|
|
|
|
|
# Sous licence DOUARN - Voir le fichier LICENCE pour les détails
|
|
|
|
|
|
#
|
|
|
|
|
|
# Ce fichier fait partie du projet Erminig.
|
|
|
|
|
|
# Libre comme l’air, stable comme un menhir, et salé comme le beurre.
|
|
|
|
|
|
#
|
|
|
|
|
|
|
2025-04-29 17:15:19 +02:00
|
|
|
|
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)
|