assing a job to a thread if possible
(self)
| 253 | |
| 254 | #---------------------------------------------------------------------- |
| 255 | def assignJob(self): |
| 256 | """assing a job to a thread if possible""" |
| 257 | |
| 258 | if self.pause or not self.core.api.isTimeDownload(): return |
| 259 | |
| 260 | #if self.downloaded > 20: |
| 261 | # if not self.cleanPyCurl(): return |
| 262 | |
| 263 | free = [x for x in self.threads if not x.active] |
| 264 | |
| 265 | inuse = set([(x.active.pluginname,self.getLimit(x)) for x in self.threads if x.active and x.active.hasPlugin() and x.active.plugin.account]) |
| 266 | inuse = map(lambda x : (x[0], x[1], len([y for y in self.threads if y.active and y.active.pluginname == x[0]])) ,inuse) |
| 267 | onlimit = [x[0] for x in inuse if x[1] > 0 and x[2] >= x[1]] |
| 268 | |
| 269 | occ = [x.active.pluginname for x in self.threads if x.active and x.active.hasPlugin() and not x.active.plugin.multiDL] + onlimit |
| 270 | |
| 271 | occ.sort() |
| 272 | occ = tuple(set(occ)) |
| 273 | job = self.core.files.getJob(occ) |
| 274 | if job: |
| 275 | try: |
| 276 | job.initPlugin() |
| 277 | except Exception, e: |
| 278 | self.log.critical(str(e)) |
| 279 | print_exc() |
| 280 | job.setStatus("failed") |
| 281 | job.error = str(e) |
| 282 | job.release() |
| 283 | return |
| 284 | |
| 285 | if job.plugin.__type__ == "hoster": |
| 286 | spaceLeft = freeSpace(self.core.config["general"]["download_folder"]) / 1024 / 1024 |
| 287 | if spaceLeft < self.core.config["general"]["min_free_space"]: |
| 288 | self.log.warning(_("Not enough space left on device")) |
| 289 | self.pause = True |
| 290 | |
| 291 | if free and not self.pause: |
| 292 | thread = free[0] |
| 293 | #self.downloaded += 1 |
| 294 | |
| 295 | thread.put(job) |
| 296 | else: |
| 297 | #put job back |
| 298 | if occ not in self.core.files.jobCache: |
| 299 | self.core.files.jobCache[occ] = [] |
| 300 | self.core.files.jobCache[occ].append(job.id) |
| 301 | |
| 302 | #check for decrypt jobs |
| 303 | job = self.core.files.getDecryptJob() |
| 304 | if job: |
| 305 | job.initPlugin() |
| 306 | thread = PluginThread.DecrypterThread(self, job) |
| 307 | |
| 308 | |
| 309 | else: |
| 310 | thread = PluginThread.DecrypterThread(self, job) |
| 311 | |
| 312 | def getLimit(self, thread): |
no test coverage detected