From 032e0ac0c928f98b268b82429d1ad4b4aeacaf63 Mon Sep 17 00:00:00 2001 From: Nemo Date: Wed, 29 Sep 2021 13:40:22 +0530 Subject: [PATCH] Add some more comments --- create-new-torrent | 29 ++++++++++++++++++++--------- 1 file changed, 20 insertions(+), 9 deletions(-) diff --git a/create-new-torrent b/create-new-torrent index 35c1055..86d7e4e 100755 --- a/create-new-torrent +++ b/create-new-torrent @@ -16,25 +16,36 @@ Most common options you might want to overwrite are --name """ +# Remove the script name arguments = sys.argv del arguments[0] +# Last argument must be the directory or file directory = sys.argv[-1] comment = None -for file in ["README.txt", "readme.txt", "README.md", "readme.md", "README.nfo"]: - file_path = directory + "/" + file - if os.path.exists(file_path): - with open(file_path, 'r') as f: - comment = f.read() -if !comment: - print("Could not find a readme file in %s" % directory) +# Only try for a comment if we have a directory +if os.path.isdir(directory) + for file in ["README.txt", "readme.txt", "README.md", "readme.md", "README.nfo"]: + file_path = directory + "/" + file + if os.path.exists(file_path): + with open(file_path, 'r') as f: + comment = f.read() + if !comment + print("Could not find a readme file in %s" % directory) +# Add all trackers tracker_file = os.path.expanduser('~/.config/trackers.txt') with open(tracker_file, 'r') as t: - list = ["mktorrent"] + ["--announce=%s" % x for x in t.read().split("\n")] + ['--no-date'] + trackers = t.read().split("\n") + list = ["mktorrent"] + ["--announce=%s" % tracker_url for tracker_url in trackers] + ['--no-date'] + +# Add a comment if we found one if comment: - list+=["--comment=\"%s\""%comment] + list+=["--comment=\"%s\"" % comment] + +# Append any extra arguments we got, including the directory list += arguments +# Run and passthrough stdout (default) subprocess.run(args=list) \ No newline at end of file