Esempio n. 1
0
    def _do_grab(self, fileURI, dest, total_size):
        bs, tt, = 1024, int(time())
        s_time = time()
        Tdiff = lambda: time() - s_time
        downloaded_size = exist_size = self.exist_size
        symbol = "B/s"
        st = time()
        chunk = fileURI.read(bs)
        downloaded_size += len(chunk)

        if self.progress:
            p = self.progress(total_size, exist_size)
            self.percent = p.update(downloaded_size)
            self.complete = False

        while chunk:
            dest.write(chunk)
            chunk = fileURI.read(bs)
            downloaded_size += len(chunk)
            ct = time()
            if int(tt) != int(ct):
                self.rate = (downloaded_size - exist_size) / (ct - st)

                if self.percent:
                    self.eta = "%02d:%02d:%02d" % tuple(
                        [i for i in gmtime((Tdiff() * (100 - self.percent)) / self.percent)[3:6]]
                    )

                self.rate, symbol = util.human_readable_rate(self.rate)

                tt = time()

            if self.progress:
                if p.update(downloaded_size):
                    self.percent = p.percent
                    if not self.complete:
                        ctx.ui.display_progress(
                            operation="fetching",
                            percent=self.percent,
                            filename=self.url.filename(),
                            total_size=total_size,
                            downloaded_size=downloaded_size,
                            rate=self.rate,
                            eta=self.eta,
                            symbol=symbol,
                        )
                        if self.percent == 100:  # FIXME: will be superseded by a
                            self.complete = True  # working progress interface

        dest.close()
Esempio n. 2
0
    def update(self, size):
        self.size = size

        if self.total_size:
            self.percent = (size * 100.0) / self.total_size
        else:
            self.percent = 0

        if int(self.now()) != int(self.last_updated) and size > 0:
            self.rate, self.symbol = util.human_readable_rate((size - self.exist_size) / (self.now() - self.s_time))
            if self.total_size:
                self.eta  = '%02d:%02d:%02d' %\
                    tuple([i for i in time.gmtime((self.t_diff() * (100 - self.percent)) / self.percent)[3:6]])

        self._update_ui()
Esempio n. 3
0
    def _do_grab(self, fileURI, dest, total_size):
        ctx.ui.notify(pisi.ui.downloading, url=fileURI)
        bs, tt, = 1024, int(time())
        s_time = time()
        Tdiff = lambda: time() - s_time
        downloaded_size = exist_size = self.exist_size
        symbol = 'B/s'
        st = time()
        chunk = fileURI.read(bs)
        downloaded_size += len(chunk)

        if self.progress:
            p = self.progress(total_size, exist_size)
            self.percent = p.update(downloaded_size)
            self.complete = False

        while chunk:
            dest.write(chunk)
            chunk = fileURI.read(bs)
            downloaded_size += len(chunk)
            ct = time()
            if int(tt) != int(ct):
                self.rate = (downloaded_size - exist_size) / (ct - st)

                if self.percent:
                    self.eta  = '%02d:%02d:%02d' %\
                    tuple([i for i in gmtime((Tdiff() * (100 - self.percent)) / self.percent)[3:6]])

                self.rate, symbol = util.human_readable_rate(self.rate)

                tt = time()

            if self.progress:
                if p.update(downloaded_size):
                    self.percent = p.percent
                    if not self.complete:
                        ctx.ui.display_progress(
                            filename=self.url.filename(),
                            percent=self.percent,
                            total_size=total_size,
                            downloaded_size=downloaded_size,
                            rate=self.rate,
                            eta=self.eta,
                            symbol=symbol)
                        if self.percent == 100:  #FIXME: will be superseded by a
                            self.complete = True  # working progress interface

        dest.close()
Esempio n. 4
0
    def update(self, size):
        self.size = size

        if self.total_size:
            self.percent = (size * 100.0) / self.total_size
        else:
            self.percent = 0

        if int(self.now()) != int(self.last_updated) and size > 0:
            self.rate, self.symbol = util.human_readable_rate(
                (size - self.exist_size) / (self.now() - self.s_time))
            if self.total_size:
                self.eta  = '%02d:%02d:%02d' %\
                    tuple([i for i in time.gmtime((self.t_diff() * (100 - self.percent)) / self.percent)[3:6]])

        self._update_ui()
Esempio n. 5
0
    def update(self, blocknum, bs, size):
        self.total_size = size + self.exist_size
        self.size = blocknum * bs + self.exist_size
        if self.total_size:
            self.percent = self.size * 100 / self.total_size
            if self.percent > 100:
                self.percent = 100
        else:
            self.percent = 0

        if int(self.now()) != int(self.last_updated) and self.size > 0:
            try:
                self.rate, self.symbol = util.human_readable_rate(
                    self.size / (self.now() - self.s_time))
            except ZeroDivisionError:
                return
            if self.total_size:
                self.eta = '%02d:%02d:%02d' %\
                    tuple([i for i in time.gmtime((self.t_diff() * (100 - self.percent)) / self.percent)[3:6]])

        self._update_ui()
        self._limit_bandwidth()