Example #1
0
    def run(self):
        t1 = time.time()

        while not self.obj.pool.done():
            self.dl_speed = self.calcDownloadSpeed(self.shared_var.value)
            if self.dl_speed > 0:
                self.eta = self.calcETA(
                    (self.obj.filesize - self.shared_var.value) /
                    self.dl_speed)

            if self.progress_bar:
                if self.obj.filesize:
                    status = r"[%s Threads] %s / %s @ %s/s %s [%3.1f%%, %s left]   " % (
                        self.obj.actual_threads_used,
                        utils.sizeof_human(self.shared_var.value),
                        utils.sizeof_human(self.obj.filesize),
                        utils.sizeof_human(self.dl_speed),
                        utils.progress_bar(
                            1.0 * self.shared_var.value / self.obj.filesize),
                        self.shared_var.value * 100.0 / self.obj.filesize,
                        utils.time_human(self.eta, fmt_short=True))
                else:
                    status = r"[%s Threads] %s / ??? MB @ %s/s   " % (
                        self.obj.actual_threads_used,
                        utils.sizeof_human(self.shared_var.value),
                        utils.sizeof_human(self.dl_speed))
                status = status + chr(8) * (len(status) + 1)
                print status,

            time.sleep(0.1)

        if self.obj._killed:
            self.logger.debug("File download process has been stopped.")
            return

        if self.progress_bar:
            if self.obj.filesize:
                print r"[%s Threads] %s / %s @ %s/s %s [100%%, 0s left]    " % (
                    self.obj.actual_threads_used,
                    utils.sizeof_human(self.obj.filesize),
                    utils.sizeof_human(self.obj.filesize),
                    utils.sizeof_human(self.dl_speed), utils.progress_bar(1.0))
            else:
                print r"[%s Threads] %s / %s @ %s/s    " % (
                    self.obj.actual_threads_used,
                    utils.sizeof_human(self.shared_var.value),
                    self.shared_var.value / 1024.0**2,
                    utils.sizeof_human(self.dl_speed))

        t2 = time.time()
        self.dl_time = float(t2 - t1)

        while self.obj.post_threadpool_thread.is_alive():
            time.sleep(0.1)

        self.obj.pool.shutdown()
        self.obj.status = "finished"
        if not self.obj.errors:
            self.logger.debug("File downloaded within %.2f seconds." %
                              self.dl_time)
Example #2
0
    def get_dl_time(self, human=False):
        '''
        Returns how much time did the download take, in seconds. Returns
        `-1` if the download task is not finished yet.

        :param human: If true, returns a human-readable formatted string. Else, returns an int type number
        :type human: bool
        :rtype: int/string
        '''
        if human:
            return utils.time_human(self.control_thread.get_dl_time())
        return self.control_thread.get_dl_time()
Example #3
0
    def get_dl_time(self, human=False):
        '''
        Returns how much time did the download take, in seconds. Returns
        `-1` if the download task is not finished yet.

        :param human: If true, returns a human-readable formatted string. Else, returns an int type number
        :type human: bool
        :rtype: int/string
        '''
        if not self.control_thread:
            return 0
        if human:
            return utils.time_human(self.control_thread.get_dl_time())
        return self.control_thread.get_dl_time()
Example #4
0
 def get_eta(self, human=False):
     '''
     Get estimated time of download completion, in seconds. Returns `0` if there is
     no enough data to calculate the estimated time (this will happen on the approx.
     first 5 seconds of each download).
     
     :param human: If true, returns a human-readable formatted string. Else, returns an int type number
     :type human: bool
     :rtype: int/string
     '''
     if human:
         s = utils.time_human(self.control_thread.get_eta())
         return s if s else "TBD"
     return self.control_thread.get_eta()
Example #5
0
 def get_eta(self, human=False):
     '''
     Get estimated time of download completion, in seconds. Returns `0` if there is
     no enough data to calculate the estimated time (this will happen on the approx.
     first 5 seconds of each download).
     
     :param human: If true, returns a human-readable formatted string. Else, returns an int type number
     :type human: bool
     :rtype: int/string
     '''
     if human:
         s = utils.time_human(self.control_thread.get_eta())
         return s if s else "TBD"
     return self.control_thread.get_eta()
Example #6
0
 def run(self):
     t1 = time.time()
     
     while not self.obj.pool.done():
         self.dl_speed = self.calcDownloadSpeed(self.shared_var.value)
         if self.dl_speed > 0:
             self.eta = self.calcETA((self.obj.filesize-self.shared_var.value)/self.dl_speed)
             
         if self.progress_bar:
             if self.obj.filesize:
                 status = r"[*] %s / %s @ %s/s %s [%3.1f%%, %s left]   " % (utils.sizeof_human(self.shared_var.value), utils.sizeof_human(self.obj.filesize), utils.sizeof_human(self.dl_speed), utils.progress_bar(1.0*self.shared_var.value/self.obj.filesize), self.shared_var.value * 100.0 / self.obj.filesize, utils.time_human(self.eta, fmt_short=True))
             else:
                 status = r"[*] %s / ??? MB @ %s/s   " % (utils.sizeof_human(self.shared_var.value), utils.sizeof_human(self.dl_speed))
             status = status + chr(8)*(len(status)+1)
             print status,
         
         time.sleep(0.1)
         
     if self.obj._killed:
         self.logger.debug("File download process has been stopped.")
         return
         
     if self.progress_bar:
         if self.obj.filesize:
             print r"[*] %s / %s @ %s/s %s [100%%, 0s left]    " % (utils.sizeof_human(self.obj.filesize), utils.sizeof_human(self.obj.filesize), utils.sizeof_human(self.dl_speed), utils.progress_bar(1.0))
         else:
             print r"[*] %s / %s @ %s/s    " % (utils.sizeof_human(self.shared_var.value), self.shared_var.value / 1024.0**2, utils.sizeof_human(self.dl_speed))
             
     t2 = time.time()
     self.dl_time = float(t2-t1)
     
     while self.obj.post_threadpool_thread.is_alive():
         time.sleep(0.1)
         
     self.obj.pool.shutdown()
     self.obj.status = "finished"
     if not self.obj.errors:
         self.logger.debug("File downloaded within %.2f seconds." % self.dl_time)
Example #7
0
 def get_dl_time(self, human=False):
     if not self.control_thread:
         return 0
     if human:
         return utils.time_human(self.control_thread.get_dl_time())
     return self.control_thread.get_dl_time()
Example #8
0
 def get_eta(self, human=False):
     if human:
         s = utils.time_human(self.control_thread.get_eta())
         return s if s else "TBD"
     return self.control_thread.get_eta()