diff --git a/.aliases b/.aliases index cfd7c284..eb60c71d 100644 --- a/.aliases +++ b/.aliases @@ -93,7 +93,8 @@ alias gw-spotless='./gradlew spotlessApply -x pitest -x test -x :processResource alias gw-test='. .aliases; ./gradlew test' alias gw-check='. .aliases; gw test check -x pitest' -alias cas-curl='bin/cas-curl' +alias howto=bin/howto +alias cas-curl=bin/cas-curl # etc/docker-compose.yml limits CPUs+MEM and includes a PostgreSQL config for analysing slow queries alias gw-importOfficeData-in-docker-compose=' @@ -108,3 +109,4 @@ source .environment alias scenario-reports-upload='./gradlew scenarioTests convertMarkdownToHtml && ssh hsh03-hsngdev@h50.hostsharing.net "rm -f doms/hsngdev.hs-example.de/htdocs-ssl/scenarios/office/*.html" && scp build/doc/scenarios/*.html hsh03-hsngdev@h50.hostsharing.net:doms/hsngdev.hs-example.de/htdocs-ssl/scenarios/office' alias scenario-reports-open='open https://hsngdev.hs-example.de/scenarios/office' + diff --git a/README.md b/README.md index a015f73c..e9f40f79 100644 --- a/README.md +++ b/README.md @@ -617,6 +617,11 @@ Besides the following *How Tos* you can also find several *How Tos* in the sourc grep -r HOWTO src ``` +also try this (assumed you've sourced .aliases): +```sh +howto +``` + ### How to Configure .pgpass for the Default PostgreSQL Database? To access the default database schema as used during development, add this line to your `.pgpass` file in your users home directory: diff --git a/bin/howto b/bin/howto new file mode 100755 index 00000000..0a3b6404 --- /dev/null +++ b/bin/howto @@ -0,0 +1,86 @@ +#!/usr/bin/python3 +import os +import sys +from urllib.parse import urljoin, quote + +def path_to_file_uri(path): + """ + Converts a file path to a file URI. + Handles absolute and relative paths. + """ + abs_path = os.path.abspath(path) + return urljoin("file://", quote(abs_path)) + +def is_binary_file(filepath, chunk_size=1024): + """ + Prüft, ob eine Datei binär ist, indem sie den Inhalt der Datei auf nicht-druckbare Zeichen untersucht. + """ + try: + with open(filepath, "rb") as file: + chunk = file.read(chunk_size) + if b"\0" in chunk: # Nullbyte ist ein typisches Zeichen für Binärdateien + return True + return False + except Exception as e: + print(f"Fehler beim Prüfen, ob Datei binär ist: {filepath}: {e}") + return True + +def search_keywords_in_files(keywords): + if not keywords: + print("Bitte geben Sie mindestens ein Stichwort an.") + sys.exit(1) + + # Allowed comment symbols + comment_symbols = {"//", "#", ";"} + + for root, dirs, files in os.walk("."): + # Ausschließen bestimmter Verzeichnisse + dirs[:] = [d for d in dirs if d not in {".git", "build"}] + + for file in files: + filepath = os.path.join(root, file) + + # Überspringen von Binärdateien + if is_binary_file(filepath): + continue + + try: + with open(filepath, "r", encoding="utf-8") as f: + lines = f.readlines() + + for line_number, line in enumerate(lines, start=1): + stripped_line = line.lstrip() # Entfernt führende Leerzeichen + for symbol in comment_symbols: + if stripped_line.startswith(symbol): + # Entfernt das Kommentarzeichen und nachfolgende Leerzeichen + howtoMatch = stripped_line[len(symbol):].lstrip() + if howtoMatch.startswith(("HOWTO ", "HOWTO: ", "How to ")): + if all(keyword in howtoMatch.lower() for keyword in keywords): + + # Titelzeile ohne Kommentarzeichen + print(howtoMatch.rstrip()) + + # Ausgabe nachfolgender Zeilen mit dem gleichen Kommentar-Präfix + for subsequent_line in lines[line_number:]: + subsequent_line = subsequent_line.lstrip() + if subsequent_line.startswith(symbol): + # Entfernt Kommentarzeichen aus Folgezeilen + print("\t" + subsequent_line[len(symbol):].strip()) + else: + break + + # Link mit Zeilennummer + print(f"--> {path_to_file_uri(filepath)}:{line_number}") + + # Abstand zwischen Matches + print() + break + except Exception as e: + print(f"Fehler beim Lesen der Datei {filepath}: {e}") + +if __name__ == "__main__": + if len(sys.argv) < 2: + print("Verwendung: bin/howto ...") + sys.exit(1) + + search_keywords_in_files([arg.lower() for arg in sys.argv[1:]]) diff --git a/build.gradle b/build.gradle index 984388d9..28fbe7c6 100644 --- a/build.gradle +++ b/build.gradle @@ -12,6 +12,9 @@ plugins { id 'com.github.ben-manes.versions' version '0.51.0' } +// HOWTO: find out which dependency versions are managed by Spring Boot: +// https://docs.spring.io/spring-boot/appendix/dependency-versions/coordinates.html + group = 'net.hostsharing' version = '0.0.1-SNAPSHOT'