Use subprocess

This commit is contained in:
Jeffrey Serio 2024-11-08 08:54:56 -06:00
parent 1fdb07e6c0
commit 2498fc3b1d

View File

@ -30,7 +30,7 @@ Examples:
""" """
import json import json
import shutil import subprocess
import tempfile import tempfile
from pathlib import Path from pathlib import Path
@ -78,16 +78,23 @@ if __name__ == "__main__":
# Create a NamedTemporaryFile and write all infohashes to it, one per line # Create a NamedTemporaryFile and write all infohashes to it, one per line
console.log("Creating temporary file to write infohashes to.") console.log("Creating temporary file to write infohashes to.")
with tempfile.NamedTemporaryFile() as ntf: with tempfile.NamedTemporaryFile() as ntf:
with open(ntf.name, "w") as tf: with open(ntf.name, "w") as tf:
tf.writelines(format_infohashes) 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. # directory, overwriting the whitelist.txt file.
console.log( console.log(
"Copying the temporary infohashes file to the torrent tracker's whitelist." "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 # Reannounce all torrents in each qBittorrent instance to their trackers
console.log("Reannouncing all torrents to their trackers.") console.log("Reannouncing all torrents to their trackers.")