From c1da74de3fd134c5c257d11b681bf0d01bb28da8 Mon Sep 17 00:00:00 2001 From: Kevin Veen-Birkenbach Date: Fri, 18 Jul 2025 14:43:09 +0200 Subject: [PATCH] Optimized sound for cli --- cli/deploy.py | 6 ++++-- main.py | 49 ++++++++++++++++++++++++++----------------------- 2 files changed, 30 insertions(+), 25 deletions(-) diff --git a/cli/deploy.py b/cli/deploy.py index 83b682b6..255d7d22 100644 --- a/cli/deploy.py +++ b/cli/deploy.py @@ -16,11 +16,12 @@ def run_ansible_playbook( skip_tests=False, skip_validation=False, skip_build=False, + cleanup=False ): start_time = datetime.datetime.now() print(f"\n▶️ Script started at: {start_time.isoformat()}\n") - if not skip_build: + if cleanup: print("\n🧹 Cleaning up project (make clean)...\n") subprocess.run(["make", "clean"], check=True) else: @@ -202,7 +203,8 @@ def main(): verbose=args.verbose, skip_tests=args.skip_tests, skip_validation=args.skip_validation, - skip_build=args.skip_build # Pass the new param + skip_build=args.skip_build, + cleanup=args.cleanup ) diff --git a/main.py b/main.py index 6dfae6d0..1fa59da9 100755 --- a/main.py +++ b/main.py @@ -8,6 +8,8 @@ import threading import signal from datetime import datetime import pty +from module_utils.sounds import Sound +import time # Color support try: @@ -18,25 +20,6 @@ except ImportError: def __getattr__(self, name): return '' Fore = Back = Style = Dummy() -_IN_DOCKER = os.path.exists('/.dockerenv') - -if _IN_DOCKER: - class Quiet: - @staticmethod - def play_start_sound(): pass - @staticmethod - def play_cymais_intro_sound(): pass - @staticmethod - def play_finished_successfully_sound(): pass - @staticmethod - def play_finished_failed_sound(): pass - @staticmethod - def play_warning_sound(): pass - - Sound = Quiet -else: - from module_utils.sounds import Sound - def color_text(text, color): return f"{color}{text}{Style.RESET_ALL}" @@ -113,18 +96,29 @@ def play_start_intro(): Sound.play_cymais_intro_sound() -def failure_with_warning_loop(no_signal, sound_enabled): +import time + +def failure_with_warning_loop(no_signal, sound_enabled, alarm_timeout=60): + """ + On failure: Plays warning sound in a loop. + Aborts after alarm_timeout seconds and exits with code 1. + """ if not no_signal: Sound.play_finished_failed_sound() print(color_text("Warning: command failed. Press Ctrl+C to stop warnings.", Fore.RED)) + start = time.monotonic() try: while True: if not no_signal: Sound.play_warning_sound() + if time.monotonic() - start > alarm_timeout: + print(color_text(f"Alarm aborted after {alarm_timeout} seconds.", Fore.RED)) + sys.exit(1) except KeyboardInterrupt: print(color_text("Warnings stopped by user.", Fore.YELLOW)) + if __name__ == "__main__": # Parse flags sound_enabled = '--sound' in sys.argv and (sys.argv.remove('--sound') or True) @@ -132,7 +126,16 @@ if __name__ == "__main__": log_enabled = '--log' in sys.argv and (sys.argv.remove('--log') or True) git_clean = '--git-clean' in sys.argv and (sys.argv.remove('--git-clean') or True) infinite = '--infinite' in sys.argv and (sys.argv.remove('--infinite') or True) - + alarm_timeout = 60 + if '--alarm-timeout' in sys.argv: + i = sys.argv.index('--alarm-timeout') + try: + alarm_timeout = int(sys.argv[i+1]) + del sys.argv[i:i+2] + except Exception: + print(color_text("Invalid --alarm-timeout value!", Fore.RED)) + sys.exit(1) + # Segfault handler def segv_handler(signum, frame): if not no_signal: @@ -317,7 +320,7 @@ if __name__ == "__main__": log_file.close() if rc != 0: - failure_with_warning_loop(no_signal, sound_enabled) + failure_with_warning_loop(no_signal, sound_enabled, alarm_timeout) sys.exit(rc) else: if not no_signal: @@ -325,7 +328,7 @@ if __name__ == "__main__": return True except Exception as e: print(color_text(f"Exception running command: {e}", Fore.RED)) - failure_with_warning_loop(no_signal, sound_enabled) + failure_with_warning_loop(no_signal, sound_enabled, alarm_timeout) sys.exit(1) if infinite: