def completedir(files, url, flag = Event(), vc = dummy, fc = dummy, piece_len_pow2 = None): files.sort() ext = '.torrent' togen = [] for f in files: if f[-len(ext):] != ext: togen.append(f) total = 0 for i in togen: total += calcsize(i) subtotal = [0] def callback(x, subtotal = subtotal, total = total, vc = vc): subtotal[0] += x vc(float(subtotal[0]) / total) for i in togen: t = split(i) if t[1] == '': i = t[0] fc(i) try: make_meta_file(i, url, flag = flag, progress = callback, progress_percent=0, piece_len_exp = piece_len_pow2) except ValueError: print_exc()
def create_bittorrent(self): ''' This is where the bittorrent files are created and transmission is controlled''' flag = Event() make_meta_file(str(self.originalFile.path), settings.BITTORRENT_TRACKER_ANNOUNCE_URL, flag = flag, progress_percent=0, piece_len_exp = 18, target = settings.BITTORRENT_FILES_DIR + self.slug + '.torrent') self.torrentURL = settings.BITTORRENT_FILES_BASE_URL + self.slug + '.torrent' shutil.copy(str(self.originalFile.path), settings.BITTORRENT_DOWNLOADS_DIR) self.published = True try: tc = transmissionrpc.Client(settings.TRANSMISSION_HOST, port=settings.TRANSMISSION_PORT) tc.add_uri(self.torrentURL, download_dir=settings.BITTORRENT_DOWNLOADS_DIR) except Exception, e: print "Error:", e
def completedir(files, url, flag=Event(), vc=dummy, fc=dummy, piece_len_pow2=None): files.sort() ext = '.torrent' togen = [] for f in files: if f[-len(ext):] != ext: togen.append(f) total = 0 for i in togen: total += calcsize(i) subtotal = [0] def callback(x, subtotal=subtotal, total=total, vc=vc): subtotal[0] += x vc(float(subtotal[0]) / total) for i in togen: t = split(i) if t[1] == '': i = t[0] fc(i) try: make_meta_file(i, url, flag=flag, progress=callback, progress_percent=0, piece_len_exp=piece_len_pow2) except ValueError: print_exc()