Created
February 20, 2014 01:29
-
-
Save bendikro/9105213 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/env python | |
import time | |
import os, sys | |
import argparse | |
import subprocess | |
import uuid | |
if __name__ == "__main__": | |
argparser = argparse.ArgumentParser(description="Create torrent files for test purposes") | |
argparser.add_argument("-c", "--count", help="Number of torrents to create.", required=False, default="100") | |
argparser.add_argument("-f", "--file", help="The file the torrents will contain.", required=False, default="test.txt") | |
argparser.add_argument("-d", "--dir", help="The output directory where the torrents are placed.", required=False, default="output") | |
args = argparser.parse_args() | |
testfile_name = "test_%d.txt" | |
if not os.path.isdir(args.dir): | |
os.makedirs(args.dir) | |
if not os.path.isdir("mediafiles"): | |
os.makedirs("mediafiles") | |
testfile_counter = 0 | |
for i in range(int(args.count)): | |
name = uuid.uuid4() | |
target_file = "mediafiles/%s.txt" % (name) | |
while True: | |
try: | |
os.link(testfile_name % testfile_counter, target_file) | |
break | |
except OSError as e: | |
testfile_counter += 1 | |
if not os.path.exists(testfile_name % testfile_counter): | |
f = open(testfile_name % testfile_counter, 'a+') | |
f.write("Test file %d\n" % testfile_counter) | |
f.close() | |
print "New test file: %s" % (testfile_name % testfile_counter) | |
else: | |
print "Exists:", testfile_name % testfile_counter | |
cmd = ["mktorrent", "-a", "https:/test.url", "-o", "%s/%s.torrent" % (args.dir, name), target_file] | |
#print "CMD:", cmd | |
p = subprocess.Popen(cmd, stdout=subprocess.PIPE) | |
ret = p.wait() | |
if i % 100 == 0: | |
print i | |
print "Created %s torrent files!" % args.count |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment