mirror of
https://github.com/kevinveenbirkenbach/computer-playbook.git
synced 2025-05-18 10:40:33 +02:00
Added warning sound
This commit is contained in:
parent
624566d34e
commit
d4f9aa21e5
63
main.py
63
main.py
@ -5,6 +5,9 @@ import os
|
|||||||
import subprocess
|
import subprocess
|
||||||
import sys
|
import sys
|
||||||
import textwrap
|
import textwrap
|
||||||
|
import threading
|
||||||
|
|
||||||
|
from cli.sounds import Sound
|
||||||
|
|
||||||
def format_command_help(name, description, indent=2, col_width=36, width=80):
|
def format_command_help(name, description, indent=2, col_width=36, width=80):
|
||||||
prefix = " " * indent + f"{name:<{col_width - indent}}"
|
prefix = " " * indent + f"{name:<{col_width - indent}}"
|
||||||
@ -31,13 +34,11 @@ def extract_description_via_help(cli_script_path):
|
|||||||
check=True
|
check=True
|
||||||
)
|
)
|
||||||
lines = result.stdout.splitlines()
|
lines = result.stdout.splitlines()
|
||||||
|
|
||||||
# Skip until first empty line after usage block
|
# Skip until first empty line after usage block
|
||||||
for i, line in enumerate(lines):
|
for i, line in enumerate(lines):
|
||||||
if line.strip().startswith("usage:"):
|
if line.strip().startswith("usage:"):
|
||||||
continue
|
continue
|
||||||
if line.strip() == "":
|
if line.strip() == "":
|
||||||
# description usually comes after usage and empty line
|
|
||||||
for j in range(i+1, len(lines)):
|
for j in range(i+1, len(lines)):
|
||||||
desc = lines[j].strip()
|
desc = lines[j].strip()
|
||||||
if desc:
|
if desc:
|
||||||
@ -46,7 +47,20 @@ def extract_description_via_help(cli_script_path):
|
|||||||
except Exception:
|
except Exception:
|
||||||
return "-"
|
return "-"
|
||||||
|
|
||||||
def main():
|
def play_start_intro():
|
||||||
|
Sound.play_start_sound()
|
||||||
|
Sound.play_cymais_intro_sound()
|
||||||
|
|
||||||
|
if __name__ == "__main__":
|
||||||
|
# Detect --no-sound option
|
||||||
|
no_sound = '--no-sound' in sys.argv
|
||||||
|
if no_sound:
|
||||||
|
sys.argv.remove('--no-sound')
|
||||||
|
|
||||||
|
# Start intro sounds in background if enabled
|
||||||
|
if not no_sound:
|
||||||
|
threading.Thread(target=play_start_intro, daemon=True).start()
|
||||||
|
|
||||||
script_dir = os.path.dirname(os.path.realpath(__file__))
|
script_dir = os.path.dirname(os.path.realpath(__file__))
|
||||||
cli_dir = os.path.join(script_dir, "cli")
|
cli_dir = os.path.join(script_dir, "cli")
|
||||||
os.chdir(script_dir)
|
os.chdir(script_dir)
|
||||||
@ -73,14 +87,39 @@ def main():
|
|||||||
sys.exit(0)
|
sys.exit(0)
|
||||||
|
|
||||||
# Default flow
|
# Default flow
|
||||||
parser = argparse.ArgumentParser(add_help=False)
|
try:
|
||||||
parser.add_argument("cli_command", choices=available_cli_commands)
|
parser = argparse.ArgumentParser(add_help=False)
|
||||||
parser.add_argument("cli_args", nargs=argparse.REMAINDER)
|
parser.add_argument("cli_command", choices=available_cli_commands)
|
||||||
args = parser.parse_args()
|
parser.add_argument("cli_args", nargs=argparse.REMAINDER)
|
||||||
|
args = parser.parse_args()
|
||||||
|
|
||||||
cli_script_path = os.path.join(cli_dir, f"{args.cli_command}.py")
|
cli_script_path = os.path.join(cli_dir, f"{args.cli_command}.py")
|
||||||
full_cmd = [sys.executable, cli_script_path] + args.cli_args
|
full_cmd = [sys.executable, cli_script_path] + args.cli_args
|
||||||
subprocess.run(full_cmd, check=True)
|
result = subprocess.run(full_cmd)
|
||||||
|
retcode = result.returncode
|
||||||
|
|
||||||
if __name__ == "__main__":
|
if retcode != 0:
|
||||||
main()
|
if not no_sound:
|
||||||
|
Sound.play_finished_failed_sound()
|
||||||
|
print("Command failed. Press Enter to stop warnings.")
|
||||||
|
while True:
|
||||||
|
if not no_sound:
|
||||||
|
Sound.play_warning_sound()
|
||||||
|
if input() == "":
|
||||||
|
break
|
||||||
|
sys.exit(retcode)
|
||||||
|
else:
|
||||||
|
if not no_sound:
|
||||||
|
Sound.play_finished_successfully_sound()
|
||||||
|
sys.exit(0)
|
||||||
|
|
||||||
|
except Exception:
|
||||||
|
if not no_sound:
|
||||||
|
Sound.play_finished_failed_sound()
|
||||||
|
print("An error occurred. Press Enter to stop warnings.")
|
||||||
|
while True:
|
||||||
|
if not no_sound:
|
||||||
|
Sound.play_warning_sound()
|
||||||
|
if input() == "":
|
||||||
|
break
|
||||||
|
sys.exit(1)
|
||||||
|
Loading…
x
Reference in New Issue
Block a user