Squad Voice Activation 3.2 - Ausgangsstand
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>
This commit is contained in:
commit
f986c3ad11
22 changed files with 3288 additions and 0 deletions
49
werkzeuge/strip.py
Normal file
49
werkzeuge/strip.py
Normal file
|
|
@ -0,0 +1,49 @@
|
|||
"""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")
|
||||
Loading…
Add table
Add a link
Reference in a new issue