From 75b56e2f1e1069fe92d449acaf2c02711be71ec8 Mon Sep 17 00:00:00 2001 From: Markus Graf Date: Tue, 19 May 2026 15:31:24 +0200 Subject: [PATCH] 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. --- api/schema.py | 15 +++++++++------ 1 file changed, 9 insertions(+), 6 deletions(-) diff --git a/api/schema.py b/api/schema.py index c4238a8..976383b 100644 --- a/api/schema.py +++ b/api/schema.py @@ -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