From 2498fc3b1d9ec00661ebe1f04b2da5d19e821f07 Mon Sep 17 00:00:00 2001 From: Jeffrey Serio Date: Fri, 8 Nov 2024 08:54:56 -0600 Subject: [PATCH] Use subprocess --- update_tracker.py | 13 ++++++++++--- 1 file changed, 10 insertions(+), 3 deletions(-) diff --git a/update_tracker.py b/update_tracker.py index 91fed7e..eb51510 100755 --- a/update_tracker.py +++ b/update_tracker.py @@ -30,7 +30,7 @@ Examples: """ import json -import shutil +import subprocess import tempfile from pathlib import Path @@ -78,16 +78,23 @@ if __name__ == "__main__": # Create a NamedTemporaryFile and write all infohashes to it, one per line console.log("Creating temporary file to write infohashes to.") + with tempfile.NamedTemporaryFile() as ntf: with open(ntf.name, "w") as tf: tf.writelines(format_infohashes) - # Use shutil.copy to copy the infohashes file to the torrent tracker's config + # Use `sudo cp -f` to copy the infohashes file to the torrent tracker's config # directory, overwriting the whitelist.txt file. console.log( "Copying the temporary infohashes file to the torrent tracker's whitelist." ) - shutil.copy(ntf.name, "/etc/opentracker/whitelist.txt") + subprocess.run( + ["sudo", "cp", "-f", ntf.name, "/etc/opentracker/whitelist.txt"] + ) + + # Run `sudo systemctl restart opentracker.service` + console.log("Restarting opentracker.service") + subprocess.run(["sudo", "systemctl", "restart", "opentracker.service"]) # Reannounce all torrents in each qBittorrent instance to their trackers console.log("Reannouncing all torrents to their trackers.")