mirror of
https://codeberg.org/hyperreal/admin-scripts
synced 2024-11-25 09:03:41 +01:00
Use subprocess
This commit is contained in:
parent
1fdb07e6c0
commit
2498fc3b1d
@ -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.")
|
||||
|
Loading…
Reference in New Issue
Block a user