added python tool inital version
This commit is contained in:
72
buzzer_tool/buzzer.py
Normal file
72
buzzer_tool/buzzer.py
Normal file
@@ -0,0 +1,72 @@
|
||||
# buzzer.py
|
||||
import argparse
|
||||
import sys
|
||||
from core.config import load_config
|
||||
from core.connection import BuzzerConnection, BuzzerError
|
||||
from core.commands import info, ls
|
||||
|
||||
def main():
|
||||
parser = argparse.ArgumentParser(description="Edis Buzzer Host Tool")
|
||||
|
||||
# Globale Argumente (gelten für alle Befehle)
|
||||
parser.add_argument("-p", "--port", type=str, help="Serielle Schnittstelle (z.B. COM15)")
|
||||
parser.add_argument("-b", "--baudrate", type=int, help="Verbindungsgeschwindigkeit")
|
||||
parser.add_argument("-t", "--timeout", type=float, help="Timeout in Sekunden (Standard: 5.0)")
|
||||
|
||||
# Subkommandos einrichten
|
||||
subparsers = parser.add_subparsers(dest="command", help="Verfügbare Befehle")
|
||||
|
||||
# Befehl: info (expliziter Aufruf, obwohl es ohnehin immer angezeigt wird)
|
||||
subparsers.add_parser("info", help="Zeigt nur die Systeminformationen an")
|
||||
|
||||
# Befehl: ls
|
||||
ls_parser = subparsers.add_parser("ls", help="Listet Dateien und Verzeichnisse auf")
|
||||
ls_parser.add_argument("path", nargs="?", default="/", help="Zielpfad (Standard: /)")
|
||||
ls_parser.add_argument("-r", "--recursive", action="store_true", help="Rekursiv auflisten")
|
||||
|
||||
# Argumente parsen
|
||||
args = parser.parse_args()
|
||||
config = load_config(args)
|
||||
|
||||
print("--- Aktuelle Verbindungsparameter ---------------------")
|
||||
print(f"Port: {config.get('port', 'Nicht definiert')}")
|
||||
print(f"Baudrate: {config.get('baudrate')}")
|
||||
print(f"Timeout: {config.get('timeout')}s")
|
||||
print("-" * 55)
|
||||
|
||||
if not config.get("port"):
|
||||
print("Abbruch: Es muss ein Port in der config.yaml oder via --port definiert werden.")
|
||||
sys.exit(1)
|
||||
|
||||
try:
|
||||
with BuzzerConnection(config) as conn:
|
||||
# 1. Immer die Info holen und anzeigen
|
||||
sys_info = info.execute(conn)
|
||||
print(f"Buzzer Firmware: v{sys_info['app_version']} (Protokoll v{sys_info['protocol_version']})")
|
||||
print(f"LittleFS Status: {sys_info['used_kb']:.1f} KB / {sys_info['total_kb']:.1f} KB belegt ({sys_info['percent_used']:.1f}%)")
|
||||
print("-" * 55)
|
||||
|
||||
# 2. Spezifisches Kommando ausführen
|
||||
if args.command == "ls":
|
||||
print(f"Inhalt von '{args.path}':\n")
|
||||
tree = ls.get_file_tree(conn, target_path=args.path, recursive=args.recursive)
|
||||
if not tree:
|
||||
print(" (Leer)")
|
||||
else:
|
||||
ls.print_tree(tree, path=args.path )
|
||||
elif args.command == "info" or args.command is None:
|
||||
# Wurde kein Befehl oder explizit 'info' angegeben, sind wir hier schon fertig
|
||||
pass
|
||||
|
||||
except TimeoutError as e:
|
||||
print(f"Fehler: {e}")
|
||||
sys.exit(1)
|
||||
except BuzzerError as e:
|
||||
print(f"Buzzer hat die Aktion abgelehnt: {e}")
|
||||
sys.exit(1)
|
||||
except Exception as e:
|
||||
print(f"Verbindungsfehler auf {config.get('port')}: {e}")
|
||||
sys.exit(1)
|
||||
|
||||
if __name__ == "__main__":
|
||||
main()
|
||||
Reference in New Issue
Block a user