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:
+9
-6
@@ -28,6 +28,13 @@ def is_wecker_ringing() -> bool:
|
|||||||
return False
|
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
|
@strawberry.type
|
||||||
class Alarm:
|
class Alarm:
|
||||||
id: str
|
id: str
|
||||||
@@ -68,9 +75,7 @@ class Mutation:
|
|||||||
id: Optional[str] = None,
|
id: Optional[str] = None,
|
||||||
) -> Alarm:
|
) -> Alarm:
|
||||||
if command is None:
|
if command is None:
|
||||||
project_root = Path(__file__).parent.parent.absolute()
|
command = _default_command()
|
||||||
python_exec = sys.executable
|
|
||||||
command = f"cd {project_root} && {python_exec} wecker.py >> wecker.log 2>&1"
|
|
||||||
|
|
||||||
manager = get_manager()
|
manager = get_manager()
|
||||||
new_id = manager.set_alarm(
|
new_id = manager.set_alarm(
|
||||||
@@ -103,9 +108,7 @@ class Mutation:
|
|||||||
Returns True if started, False if already ringing."""
|
Returns True if started, False if already ringing."""
|
||||||
if is_wecker_ringing():
|
if is_wecker_ringing():
|
||||||
return False
|
return False
|
||||||
project_root = Path(__file__).parent.parent.absolute()
|
cmd = _default_command()
|
||||||
python_exec = sys.executable
|
|
||||||
cmd = f"cd {project_root} && {python_exec} wecker.py >> wecker.log 2>&1"
|
|
||||||
subprocess.Popen(cmd, shell=True)
|
subprocess.Popen(cmd, shell=True)
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user