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