refactor: extract _default_command() to eliminate DRY violation

The default wecker.py shell command was duplicated across set_alarm()
and start_ringing(). Extracted a shared _default_command() helper so
both callers use the same definition.
This commit is contained in:
Markus Graf
2026-05-19 15:31:24 +02:00
parent 41d8ffc404
commit 75b56e2f1e
+9 -6
View File
@@ -28,6 +28,13 @@ def is_wecker_ringing() -> bool:
return False
def _default_command() -> str:
"""Return the default shell command to run wecker.py."""
project_root = Path(__file__).parent.parent.absolute()
python_exec = sys.executable
return f"cd {project_root} && {python_exec} wecker.py >> wecker.log 2>&1"
@strawberry.type
class Alarm:
id: str
@@ -68,9 +75,7 @@ class Mutation:
id: Optional[str] = None,
) -> Alarm:
if command is None:
project_root = Path(__file__).parent.parent.absolute()
python_exec = sys.executable
command = f"cd {project_root} && {python_exec} wecker.py >> wecker.log 2>&1"
command = _default_command()
manager = get_manager()
new_id = manager.set_alarm(
@@ -103,9 +108,7 @@ class Mutation:
Returns True if started, False if already ringing."""
if is_wecker_ringing():
return False
project_root = Path(__file__).parent.parent.absolute()
python_exec = sys.executable
cmd = f"cd {project_root} && {python_exec} wecker.py >> wecker.log 2>&1"
cmd = _default_command()
subprocess.Popen(cmd, shell=True)
return True