mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-07-20 07:14:25 +02:00
Optimized sound for cli
This commit is contained in:
parent
c23624e30c
commit
c1da74de3f
@ -16,11 +16,12 @@ def run_ansible_playbook(
|
|||||||
skip_tests=False,
|
skip_tests=False,
|
||||||
skip_validation=False,
|
skip_validation=False,
|
||||||
skip_build=False,
|
skip_build=False,
|
||||||
|
cleanup=False
|
||||||
):
|
):
|
||||||
start_time = datetime.datetime.now()
|
start_time = datetime.datetime.now()
|
||||||
print(f"\n▶️ Script started at: {start_time.isoformat()}\n")
|
print(f"\n▶️ Script started at: {start_time.isoformat()}\n")
|
||||||
|
|
||||||
if not skip_build:
|
if cleanup:
|
||||||
print("\n🧹 Cleaning up project (make clean)...\n")
|
print("\n🧹 Cleaning up project (make clean)...\n")
|
||||||
subprocess.run(["make", "clean"], check=True)
|
subprocess.run(["make", "clean"], check=True)
|
||||||
else:
|
else:
|
||||||
@ -202,7 +203,8 @@ def main():
|
|||||||
verbose=args.verbose,
|
verbose=args.verbose,
|
||||||
skip_tests=args.skip_tests,
|
skip_tests=args.skip_tests,
|
||||||
skip_validation=args.skip_validation,
|
skip_validation=args.skip_validation,
|
||||||
skip_build=args.skip_build # Pass the new param
|
skip_build=args.skip_build,
|
||||||
|
cleanup=args.cleanup
|
||||||
)
|
)
|
||||||
|
|
||||||
|
|
||||||
|
47
main.py
47
main.py
@ -8,6 +8,8 @@ import threading
|
|||||||
import signal
|
import signal
|
||||||
from datetime import datetime
|
from datetime import datetime
|
||||||
import pty
|
import pty
|
||||||
|
from module_utils.sounds import Sound
|
||||||
|
import time
|
||||||
|
|
||||||
# Color support
|
# Color support
|
||||||
try:
|
try:
|
||||||
@ -18,25 +20,6 @@ except ImportError:
|
|||||||
def __getattr__(self, name): return ''
|
def __getattr__(self, name): return ''
|
||||||
Fore = Back = Style = Dummy()
|
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):
|
def color_text(text, color):
|
||||||
return f"{color}{text}{Style.RESET_ALL}"
|
return f"{color}{text}{Style.RESET_ALL}"
|
||||||
@ -113,18 +96,29 @@ def play_start_intro():
|
|||||||
Sound.play_cymais_intro_sound()
|
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:
|
if not no_signal:
|
||||||
Sound.play_finished_failed_sound()
|
Sound.play_finished_failed_sound()
|
||||||
print(color_text("Warning: command failed. Press Ctrl+C to stop warnings.", Fore.RED))
|
print(color_text("Warning: command failed. Press Ctrl+C to stop warnings.", Fore.RED))
|
||||||
|
start = time.monotonic()
|
||||||
try:
|
try:
|
||||||
while True:
|
while True:
|
||||||
if not no_signal:
|
if not no_signal:
|
||||||
Sound.play_warning_sound()
|
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:
|
except KeyboardInterrupt:
|
||||||
print(color_text("Warnings stopped by user.", Fore.YELLOW))
|
print(color_text("Warnings stopped by user.", Fore.YELLOW))
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if __name__ == "__main__":
|
||||||
# Parse flags
|
# Parse flags
|
||||||
sound_enabled = '--sound' in sys.argv and (sys.argv.remove('--sound') or True)
|
sound_enabled = '--sound' in sys.argv and (sys.argv.remove('--sound') or True)
|
||||||
@ -132,6 +126,15 @@ if __name__ == "__main__":
|
|||||||
log_enabled = '--log' in sys.argv and (sys.argv.remove('--log') or True)
|
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)
|
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)
|
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
|
# Segfault handler
|
||||||
def segv_handler(signum, frame):
|
def segv_handler(signum, frame):
|
||||||
@ -317,7 +320,7 @@ if __name__ == "__main__":
|
|||||||
log_file.close()
|
log_file.close()
|
||||||
|
|
||||||
if rc != 0:
|
if rc != 0:
|
||||||
failure_with_warning_loop(no_signal, sound_enabled)
|
failure_with_warning_loop(no_signal, sound_enabled, alarm_timeout)
|
||||||
sys.exit(rc)
|
sys.exit(rc)
|
||||||
else:
|
else:
|
||||||
if not no_signal:
|
if not no_signal:
|
||||||
@ -325,7 +328,7 @@ if __name__ == "__main__":
|
|||||||
return True
|
return True
|
||||||
except Exception as e:
|
except Exception as e:
|
||||||
print(color_text(f"Exception running command: {e}", Fore.RED))
|
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)
|
sys.exit(1)
|
||||||
|
|
||||||
if infinite:
|
if infinite:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user