def update_active_downloads(self):
     """
     Roba ciclos.
     This may change the active_downloads dict, you should get a dict copy before calling this method.
     """
     for id_item, download_item in self.active_downloads.items():
         item_data = self.get_thread_update(id_item) #threadmanager
         download_item.update(*item_data)
         limit_exceeded = self.is_limit_exceeded(id_item) #threadmanager
         old_status = download_item.status
         if old_status in (cons.STATUS_STOPPED, cons.STATUS_FINISHED, cons.STATUS_ERROR):
             if old_status == cons.STATUS_STOPPED:
                 self.stopped_downloads[id_item] = download_item
             elif old_status == cons.STATUS_FINISHED:
                 self.complete_downloads[id_item] = download_item
             else: #status == cons.STATUS_ERROR
                 download_item.fail_count += 1
                 if download_item.fail_count > conf.get_retries_limit():
                     download_item.status = cons.STATUS_STOPPED
                     self.stopped_downloads[id_item] = download_item
                 else:
                     download_item.status = cons.STATUS_QUEUE
                     self.queue_downloads[id_item] = download_item
             self.delete_thread(id_item) #threadmanager
             del self.active_downloads[id_item]
             self.global_slots.remove_slot()
             self.next_download()
             if old_status == cons.STATUS_FINISHED:
                 events.download_complete.emit(download_item)
             if not self.active_downloads and old_status != cons.STATUS_STOPPED:
                 events.all_downloads_complete.emit()
             if limit_exceeded and self.active_downloads and old_status == cons.STATUS_ERROR:
                 events.limit_exceeded.emit()
예제 #2
0
    def get_items_update(self):
        """
        Roba ciclos.
        """
        result_list = []
        for id_item, download_item in self.active_downloads.items():
            item_data = self.get_thread_status(
                id_item)  #Metodo de threadManager heredado
            if item_data is not None:
                download_item.update(*item_data)
                limit_exceeded = self.is_limit_exceeded(download_item.id)
            else:
                download_item.status = cons.STATUS_ERROR
                limit_exceeded = False
            status = download_item.status
            result_list.append(download_item)
            if status in (cons.STATUS_STOPPED, cons.STATUS_FINISHED,
                          cons.STATUS_ERROR):
                if status == cons.STATUS_FINISHED:
                    self.complete_downloads[id_item] = download_item
                elif status == cons.STATUS_ERROR:
                    logger.warning("status error: {0}".format(
                        download_item.host))
                    download_item.fail_count += 1
                    if download_item.fail_count > conf.get_retries_limit():
                        download_item.status = cons.STATUS_STOPPED
                        self.stopped_downloads[id_item] = download_item
                    else:
                        download_item.status = cons.STATUS_QUEUE
                        self.queue_downloads[id_item] = download_item
                else:  #stopped
                    self.stopped_downloads[id_item] = download_item
                self.delete_thread(id_item)  #metodo de threadmanager heredado
                del self.active_downloads[id_item]
                self.global_slots.remove_slot(
                )  #remove the slot, so the next download can start.
                self.next_download()
                if status == cons.STATUS_FINISHED:
                    events.trigger_download_complete(download_item)
                if not self.active_downloads and status != cons.STATUS_STOPPED:
                    events.trigger_all_downloads_complete()
                elif limit_exceeded:  #cons.STATUS_ERROR
                    events.trigger_limit_exceeded()

        return result_list
예제 #3
0
 def get_items_update(self):
     """
     Roba ciclos.
     """
     result_list = []
     for id_item, download_item in self.active_downloads.items():
         item_data = self.get_thread_status(id_item) #Metodo de threadManager heredado
         if item_data is not None:
             download_item.update(*item_data)
             limit_exceeded = self.is_limit_exceeded(download_item.id)
         else:
             download_item.status = cons.STATUS_ERROR
             limit_exceeded = False
         status = download_item.status
         result_list.append(download_item)
         if status in (cons.STATUS_STOPPED, cons.STATUS_FINISHED, cons.STATUS_ERROR):
             if status == cons.STATUS_FINISHED:
                 self.complete_downloads[id_item] = download_item
             elif status == cons.STATUS_ERROR:
                 logger.warning("status error: {0}".format(download_item.host))
                 download_item.fail_count += 1
                 if download_item.fail_count > conf.get_retries_limit():
                     download_item.status = cons.STATUS_STOPPED
                     self.stopped_downloads[id_item] = download_item
                 else:
                     download_item.status = cons.STATUS_QUEUE
                     self.queue_downloads[id_item] = download_item
             else: #stopped
                 self.stopped_downloads[id_item] = download_item
             self.delete_thread(id_item) #metodo de threadmanager heredado
             del self.active_downloads[id_item]
             self.global_slots.remove_slot() #remove the slot, so the next download can start.
             self.next_download()
             if status == cons.STATUS_FINISHED:
                 events.trigger_download_complete(download_item)
             if not self.active_downloads and status != cons.STATUS_STOPPED:
                 events.trigger_all_downloads_complete()
             elif limit_exceeded: #cons.STATUS_ERROR
                 events.trigger_limit_exceeded()
     
     return result_list