Windows-Werkzeug, das die Sprechtaste in Squad haelt, solange man redet. - Hauptprogramm mit tkinter-Oberflaeche, Pegelanzeige und Diagnose - Auto-Updater gegen https://sva.tyrveil.com/version.json mit SHA-256-Pruefung - Inno-Setup-Installer und Build-Skript werkzeuge/baue_release.py - Projektuebergabe mit den bekannten Fallstricken Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
49 lines
1.4 KiB
Python
49 lines
1.4 KiB
Python
"""Entfernt Kommentarzeilen, laesst Docstrings und Code unangetastet."""
|
|
import io
|
|
import sys
|
|
import tokenize
|
|
|
|
|
|
def strip_comments(quelle: str) -> str:
|
|
ergebnis = []
|
|
tokens = list(tokenize.generate_tokens(io.StringIO(quelle).readline))
|
|
entfernt = 0
|
|
for tok in tokens:
|
|
if tok.type == tokenize.COMMENT:
|
|
entfernt += 1
|
|
continue
|
|
ergebnis.append(tok)
|
|
text = tokenize.untokenize(ergebnis)
|
|
return text, entfernt
|
|
|
|
|
|
def aufraeumen(text: str) -> str:
|
|
zeilen = text.split("\n")
|
|
raus = []
|
|
for zeile in zeilen:
|
|
# Zeilen, die nur noch aus Leerzeichen bestehen, komplett leeren
|
|
raus.append("" if not zeile.strip() else zeile.rstrip())
|
|
# hoechstens zwei Leerzeilen hintereinander
|
|
kompakt = []
|
|
leer = 0
|
|
for zeile in raus:
|
|
if zeile == "":
|
|
leer += 1
|
|
if leer > 2:
|
|
continue
|
|
else:
|
|
leer = 0
|
|
kompakt.append(zeile)
|
|
while kompakt and kompakt[0] == "":
|
|
kompakt.pop(0)
|
|
while kompakt and kompakt[-1] == "":
|
|
kompakt.pop()
|
|
return "\n".join(kompakt) + "\n"
|
|
|
|
|
|
if __name__ == "__main__":
|
|
pfad = sys.argv[1]
|
|
quelle = io.open(pfad, encoding="utf-8").read()
|
|
text, anzahl = strip_comments(quelle)
|
|
io.open(pfad, "w", encoding="utf-8", newline="\n").write(aufraeumen(text))
|
|
print(f"{pfad}: {anzahl} Kommentare entfernt")
|