From 718220f889ac3b70f96dbc18fcbbef1d061a37c6 Mon Sep 17 00:00:00 2001 From: Tim Van Baak Date: Wed, 6 Nov 2024 21:27:48 -0800 Subject: [PATCH] Fix crontab on systems with crontab --- intake/crontab.py | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/intake/crontab.py b/intake/crontab.py index 7d01691..41dde55 100644 --- a/intake/crontab.py +++ b/intake/crontab.py @@ -1,5 +1,6 @@ from pathlib import Path import os +import shutil import subprocess import sys @@ -28,15 +29,13 @@ def update_crontab_entries(data_path: Path): Update the intake-managed section of the user's crontab. """ # If there is no crontab command available, quit early. - cmd = ("command", "-v", "crontab") - print("Executing", *cmd, file=sys.stderr) - crontab_exists = subprocess.run(cmd, shell=True, stdout=subprocess.PIPE) - if not crontab_exists.stdout: - print("Could not update crontab", file=sys.stderr) + crontab = shutil.which("crontab") + if not crontab: + print("No crontab found, skipping", file=sys.stderr) return # Get the current crontab - cmd = ["crontab", "-e"] + cmd = [crontab, "-e"] print("Executing", *cmd, file=sys.stderr) get_crontab = subprocess.run( cmd, @@ -77,7 +76,7 @@ def update_crontab_entries(data_path: Path): print("Updating", len(new_crontab_lines) - 2, "crontab entries", file=sys.stderr) # Save the updated crontab - cmd = ["crontab", "-"] + cmd = [crontab, "-"] print("Executing", *cmd, file=sys.stderr) new_crontab: bytes = "\n".join(new_crontab_lines).encode("utf8") save_crontab = subprocess.Popen(