def completedir(dir, url, flag = Event(), vc = dummy, fc = dummy, piece_len_pow2 = None): files = listdir(dir) files.sort() ext = '.torrent' togen = [] for f in files: if f[-len(ext):] != ext and (f + ext) not in files: togen.append(join(dir, 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: fc(i) try: t = split(i)[-1] if t not in ignore and t[0] != '.': make_meta_file(i, url, flag = flag, progress = callback, progress_percent=0, piece_len_exp = piece_len_pow2) except ValueError: print_exc()
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 complete(self): if self.parent.fileInfoPanel.startnow.GetValue(): targeted = self.parent.fileInfoPanel.getTargeted() self.startnow = True else: self.startnow = False try: if self.separatetorrents: completedir(self.d, self.a, self.params, self.doneflag, self.valCallback, self.fileCallback, gethash = self.gethash, filelist = self.filelist) else: make_meta_file(self.d, self.a, self.params, self.doneflag, self.valCallback, progress_percent = 1, fileCallback = self.fileCallback, gethash = self.gethash, filelist = self.filelist) if not self.doneflag.isSet(): self.completeCallback() if self.startnow: # When seeding immediately, copy torrents to config dir for list in self.generatedfiles: torrentfile = list[1] copy2(normpath(torrentfile), os.path.join(utility.getConfigPath(), "torrent")) torrentfile4seed = os.path.join(utility.getConfigPath(), "torrent", split(normpath(torrentfile))[1]) list.append(torrentfile4seed) except (OSError, IOError), e: self.errorCallback(e)