Ejemplo n.º 1
0
    def __makeSubWorks(self):
        curr_size = 0
        size = self.__get_content_len(self.url)
        clip_ranges = HttpFetcher.div_file(size, self.npf)

        if not self.__is_inter_file:
            self.__fp = self.out
            self.retrans = False
        else:
            self.tmp_file = self.out + '!'
            if os.path.exists(self.tmp_file):
                self.__fp = open(self.tmp_file, 'rb+')
            else:
                self.__fp = open(self.tmp_file, 'wb')

        if size and self.retrans:
            self.__history_file = HistoryFile()
            clip_ranges, curr_size = self.__history_file.load(
                self.tmp_file, clip_ranges, size)

        # can not retransmission
        if clip_ranges is None or size is None or size == 0:
            self.retrans = False
            self.log.debug('[DownloadUrl] can not retransmission, %s',
                           self.url)
            clip_ranges = [None]
            size = 0

        if self.progress_bar:
            self.progress_bar.set(total_size=size, curr_size=curr_size)

        subworks = []
        syn_file = util.SynFileContainer(self.__fp)
        for clip_range in clip_ranges:
            work = UrlTask.HttpSubWork(url=self.url,
                                       fp=syn_file,
                                       data_range=clip_range,
                                       parent=self,
                                       headers=self.headers,
                                       proxy=self.proxy,
                                       callback=self.__update,
                                       log=self.log)
            subworks.append(work)
        self.addSubWorks(subworks)
Ejemplo n.º 2
0
    def __makeSubWorks(self):
        curr_size = 0
        size = self.__get_content_len(self.url)
        clip_ranges = HttpFetcher.div_file(size, self.npf)

        if not self.__is_inter_file:
            self.__fp = self.out
            self.retrans = False
        else:
            self.tmp_file = self.out + '!'
            if os.path.exists(self.tmp_file):
                self.__fp = open(self.tmp_file, 'rb+')
            else:
                self.__fp = open(self.tmp_file, 'wb')

        if size and self.retrans:
            self.__history_file = HistoryFile()
            clip_ranges, curr_size = self.__history_file.load(
                self.tmp_file, clip_ranges, size)

        # can not retransmission
        if clip_ranges is None or size is None or size == 0:
            self.retrans = False
            self.log.debug('[DownloadUrl] can not retransmission, %s', self.url)
            clip_ranges = [None]
            size = 0

        if self.progress_bar:
            self.progress_bar.set(total_size=size, curr_size=curr_size)

        subworks = []
        syn_file = util.SynFileContainer(self.__fp)
        for clip_range in clip_ranges:
            work = UrlTask.HttpSubWork(
                url=self.url, fp=syn_file, data_range=clip_range, parent=self,
                headers=self.headers, proxy=self.proxy, callback=self.__update, log=self.log
            )
            subworks.append(work)
        self.addSubWorks(subworks)