mira_os.py

Bienvenue sur CFTPfr.fr Forums core mira_os.py

  • Ce sujet est vide.
Affichage de 1 message (sur 1 au total)
  • Auteur
    Messages
  • #210
    Mario Da Conceicao
    Maître des clés

    Sauvegarde de travail — version du 25/07/2026 (Windows, avant portage OS-MIRE). Contient os.system("dir") et eval() à corriger, voir Tome 2.

    import os
    import sys
    import json
    
    # Ajoute le chemin racine pour que Python trouve le module mira_ai
    sys.path.append("D:\\MIRA_Project")
    
    # Import du module IA
    from mira_ai.mira_ia import MiraIA
    
    print("MIRA_OS : Démarrage du système...")
    print("Version : 0.3 (Alpha)")
    print("Environnement : Python 3.13 + WinPython")
    
    # Mini-shell
    def mira_shell():
        print("\n--- MIRA_Shell (Tape 'exit' pour quitter) ---")
        while True:
            commande = input("mira> ")
            if commande.lower() == "exit":
                break
            elif commande.lower() == "help":
                print("Commandes disponibles : exit, help, version, [commandes système]")
            elif commande.lower() == "version":
                print("MIRA_OS Version : 0.3 (Alpha)")
            else:
                os.system(commande)
    
    # Gestion de fichiers
    def gestion_fichiers():
        print("\n--- Gestion de fichiers ---")
        print("1. Lister les fichiers")
        print("2. Créer un fichier")
        print("3. Supprimer un fichier")
        print("4. Retour au menu principal")
        while True:
            choix = input("Choisis une option (1-4) : ")
            if choix == "1":
                print("\n--- Fichiers dans MIRA_Project ---")
                os.system("dir")
            elif choix == "2":
                nom_fichier = input("Nom du fichier à créer : ")
                with open(nom_fichier, "w") as f:
                    f.write("")
                print(f"Fichier '{nom_fichier}' créé.")
            elif choix == "3":
                nom_fichier = input("Nom du fichier à supprimer : ")
                if os.path.exists(nom_fichier):
                    os.remove(nom_fichier)
                    print(f"Fichier '{nom_fichier}' supprimé.")
                else:
                    print(f"Fichier '{nom_fichier}' introuvable.")
            elif choix == "4":
                break
            else:
                print("Option invalide. Réessaye.")
    
    # Gestion des notes
    def gestion_notes():
        print("\n--- Gestion des notes ---")
        print("1. Créer une note")
        print("2. Lister les notes")
        print("3. Lire une note")
        print("4. Supprimer une note")
        print("5. Retour au menu principal")
    
        dossier_notes = "mira_notes"
        if not os.path.exists(dossier_notes):
            os.makedirs(dossier_notes)
    
        while True:
            choix = input("Choisis une option (1-5) : ")
            if choix == "1":
                titre = input("Titre de la note : ")
                contenu = input("Contenu de la note : ")
                with open(f"{dossier_notes}/{titre}.txt", "w", encoding="utf-8") as f:
                    f.write(contenu)
                print(f"Note '{titre}' créée.")
            elif choix == "2":
                print("\n--- Liste des notes ---")
                os.system(f"dir {dossier_notes}")
            elif choix == "3":
                titre = input("Titre de la note à lire : ")
                chemin_note = f"{dossier_notes}/{titre}.txt"
                if os.path.exists(chemin_note):
                    with open(chemin_note, "r", encoding="utf-8") as f:
                        print(f"\n--- {titre} ---\n{f.read()}")
                else:
                    print(f"Note '{titre}' introuvable.")
            elif choix == "4":
                titre = input("Titre de la note à supprimer : ")
                chemin_note = f"{dossier_notes}/{titre}.txt"
                if os.path.exists(chemin_note):
                    os.remove(chemin_note)
                    print(f"Note '{titre}' supprimée.")
                else:
                    print(f"Note '{titre}' introuvable.")
            elif choix == "5":
                break
            else:
                print("Option invalide. Réessaye.")
    
    # Calculatrice
    def calculatrice():
        print("\n--- Calculatrice MIRA_OS ---")
        print("Opérations disponibles : +, -, *, /")
        while True:
            try:
                expression = input("Entrez une opération (ex: 2+2) ou 'exit' pour quitter : ")
                if expression.lower() == "exit":
                    break
                resultat = eval(expression)
                print(f"Résultat : {resultat}")
            except:
                print("Erreur : expression invalide. Réessayez.")
    
    # Fonction pour gérer l'IA
    def gerer_ia():
        """Fonction pour interagir avec l'IA."""
        ia = MiraIA(version_actuelle="0.3")
        print("\n--- MIRA_OS IA ---")
        print("1. Vérifier les mises à jour")
        print("2. Proposer une amélioration")
        print("3. Voir les propositions de l'IA")
        print("4. Chat avec l'IA")  # NOUVELLE OPTION
        print("5. Retour au menu")
        choix_ia = input("Choisis une option (1-5) : ")
    
        if choix_ia == "1":
            mise_a_jour = ia.verifier_mises_a_jour()
            if mise_a_jour:
                print(f"Mise à jour disponible : Version {mise_a_jour['version']} - {mise_a_jour['description']}")
                appliquer = input("Appliquer la mise à jour ? (o/n) : ")
                if appliquer.lower() == "o":
                    ia.appliquer_mise_a_jour(mise_a_jour)
            else:
                print("Aucune mise à jour disponible.")
        elif choix_ia == "2":
            suggestion = input("Entrez votre suggestion d'amélioration : ")
            ia.proposer_amelioration(suggestion)
        elif choix_ia == "3":
            propositions = ia.get_propositions()
            if not propositions:
                print("Aucune proposition d'amélioration pour le moment.")
            else:
                print("\n--- Propositions de l'IA ---")
                for i, prop in enumerate(propositions, 1):
                    print(f"{i}. {prop['description']}")
                    print(f"   Explication : {prop['explication']}")
                    print(f"   Fichiers à modifier : {', '.join(prop['fichiers_a_modifier'])}")
                    print(f"   Date : {prop['date']}\n")
                choix_prop = input("Choisis une proposition à appliquer (ou '0' pour revenir) : ")
                if choix_prop != "0":
                    try:
                        prop = propositions[int(choix_prop) - 1]
                        print(f"\nProposition sélectionnée : {prop['description']}")
                        print(f"Explication : {prop['explication']}")
                        print(f"Fichiers à modifier : {', '.join(prop['fichiers_a_modifier'])}")
                        appliquer = input("Appliquer cette amélioration ? (o/n) : ")
                        if appliquer.lower() == "o":
                            with open("D:\\MIRA_Project\\mira_ai\\amelioration_a_appliquer.json", "w", encoding="utf-8") as f:
                                json.dump(prop, f, indent=4, ensure_ascii=False)
                            print("Amélioration validée ! Un fichier 'amelioration_a_appliquer.json' a été créé.")
                    except (ValueError, IndexError):
                        print("Proposition invalide.")
        elif choix_ia == "4":
            ia.chat_ia()  # Lance le chat
        elif choix_ia == "5":
            return
        else:
            print("Option invalide.")
    
    # Menu principal
    while True:
        print("\n--- MIRA_OS Menu ---")
        print("1. Afficher la version")
        print("2. Lancer MIRA_Shell")
        print("3. Gérer les fichiers")
        print("4. Gérer les notes")
        print("5. Calculatrice")
        print("6. Interagir avec l'IA")
        print("7. Quitter")
        choix = input("Choisis une option (1-7) : ")
    
        if choix == "1":
            print("MIRA_OS Version : 0.3 (Alpha)")
        elif choix == "2":
            mira_shell()
        elif choix == "3":
            gestion_fichiers()
        elif choix == "4":
            gestion_notes()
        elif choix == "5":
            calculatrice()
        elif choix == "6":
            gerer_ia()
        elif choix == "7":
            print("MIRA_OS : Arrêt du système.")
            break
        else:
            print("Option invalide. Réessaye.")
Affichage de 1 message (sur 1 au total)
  • Vous devez être connecté pour répondre à ce sujet.
Retour en haut