68 lines
1.6 KiB
Python
68 lines
1.6 KiB
Python
import os
|
||
import streamlit as st
|
||
|
||
# Dossier des logs
|
||
LOG_DIR = "/home/debian/Gestion_sondes/Logs"
|
||
|
||
st.title("Gestion des logs - Gestion_sondes")
|
||
|
||
# --- Vérification du dossier ---
|
||
if not os.path.isdir(LOG_DIR):
|
||
st.error(f"Le dossier {LOG_DIR} n'existe pas.")
|
||
st.stop()
|
||
|
||
# Liste des fichiers
|
||
files = sorted([f for f in os.listdir(LOG_DIR) if os.path.isfile(os.path.join(LOG_DIR, f))])
|
||
|
||
if not files:
|
||
st.warning("Aucun fichier de log trouvé.")
|
||
st.stop()
|
||
|
||
# Sélection du fichier
|
||
selected_file = st.selectbox("Choisissez un fichier log :", files)
|
||
|
||
file_path = os.path.join(LOG_DIR, selected_file)
|
||
|
||
st.subheader(f"Contenu de : {selected_file}")
|
||
|
||
# Lecture du contenu
|
||
def read_file():
|
||
try:
|
||
with open(file_path, "r") as f:
|
||
return f.read()
|
||
except Exception as err:
|
||
return f"Erreur lors de la lecture : {err}"
|
||
|
||
content = read_file()
|
||
st.text_area("", content, height=400)
|
||
|
||
|
||
# --- Boutons d’action ---
|
||
col1, col2, col3 = st.columns(3)
|
||
|
||
# Rafraîchir
|
||
with col1:
|
||
if st.button("🔄 Rafraîchir"):
|
||
st.rerun()
|
||
|
||
# Vider
|
||
with col2:
|
||
if st.button("🧹 Vider le fichier"):
|
||
try:
|
||
with open(file_path, "w") as f:
|
||
f.write("")
|
||
st.success(f"Le fichier '{selected_file}' a été vidé.")
|
||
st.rerun()
|
||
except Exception as e:
|
||
st.error(f"Erreur : {e}")
|
||
|
||
# Supprimer
|
||
with col3:
|
||
if st.button("🗑️ Supprimer le fichier"):
|
||
try:
|
||
os.remove(file_path)
|
||
st.success(f"Le fichier '{selected_file}' a été supprimé.")
|
||
st.rerun()
|
||
except Exception as e:
|
||
st.error(f"Erreur : {e}")
|