def assign_job(self): """Assing a job to a thread if possible""" if self.pause or not self.pyload.api.is_time_download(): return # if self.downloaded > 20: # if not self.clean_py_curl(): return free = [x for x in self.threads if not x.active] inuse = set([((x.active.plugintype, x.active.pluginname), self.get_limit(x)) for x in self.threads if x.active and isinstance(x.active, PyFile) and x.active.has_plugin() and x.active.plugin.account]) inuse = map(lambda x: ('.'.join(x[0]), x[1], len([y for y in self.threads if y.active and isinstance(y.active, PyFile) and y.active.plugintype == x[0][0] and y.active.pluginname == x[0][1]])), inuse) onlimit = [x[0] for x in inuse if x[1] > 0 and x[2] >= x[1]] occ = [x.active.plugintype + '.' + x.active.pluginname for x in self.threads if x.active and isinstance(x.active, PyFile) and x.active.has_plugin() and not x.active.plugin.multiDL] + onlimit occ.sort() occ = tuple(set(occ)) job = self.pyload.files.get_job(occ) if job: try: job.initPlugin() except Exception, e: self.pyload.log.critical(str(e)) if self.pyload.debug: traceback.print_exc() job.setStatus("failed") job.error = str(e) job.release() return if job.plugin.getPluginType() == "hoster": spaceLeft = free_space(self.pyload.config.get("general", "download_folder")) / 1024 / 1024 if spaceLeft < self.pyload.config.get("general", "min_free_space"): self.pyload.log.warning(_("Not enough space left on device")) self.pause = True if free and not self.pause: thread = free[0] # self.downloaded += 1 thread.put(job) else: # put job back if occ not in self.pyload.files.jobCache: self.pyload.files.jobCache[occ] = [] self.pyload.files.jobCache[occ].append(job.id) # check for decrypt jobs job = self.pyload.files.get_decrypt_job() if job: job.initPlugin() thread = DecrypterThread(self, job) else: thread = DecrypterThread(self, job)
def free_space(self): """ Available free space at download directory in bytes""" return free_space(self.pyload.config.get("general", "download_folder"))