Esempio n. 1
0
        def chunk_read(self, response, chunk_size=1024*100, report_hook=None):

            if report_hook is None:
                report_hook = self.chunk_report

            total_size = response.info().getheader('Content-Length').strip()
            total_size = int(total_size)
            bytes_so_far = 0

            while True:
                chunk = response.read(chunk_size)
                bytes_so_far += len(chunk)

                if not chunk:
                    self.temp_file_handler.close()
                    break

                if self.progress:
                    if self.progress.iscanceled():
                        self.temp_file_handler.close()
                        vfs.delete(self.temp_file_path)
                        self.progress.close()

                if report_hook:
                    self.temp_file_handler.write( chunk )
                    report_hook(bytes_so_far, total_size)

            return bytes_so_far
Esempio n. 2
0
            def download(request):
                response = urllib2.urlopen(request)
                self.size = self.chunk_read(response)

                if progress:
                    self.progress = xbmcgui.DialogProgress()
                    self.progress.create("Move", self.destination_file_name)

                xbmc.log("move %s -> %s" % (self.temp_file_path, self.destination_file_path))
                vfs.rename(self.temp_file_path, self.destination_file_path)
                if vfs.exists(self.temp_file_path):
                    vfs.copy(self.temp_file_path, self.destination_file_path)
                    vfs.delete(self.temp_file_path)

                self.progress.close()
Esempio n. 3
0
    def deleteLocalEpgidPath(self, epgid=False, file=False):

        if epgid:
            path = self.__getLocalEpgidPath(epgid, mkdir=False)
            json_file = self.__getEpgidJsonFile(epgid)
        elif file:
            path = file
            json_file = path + '.json.v1'
        else:
            return False

        if not vfs.exists(json_file):
            xbmc.log('could not delete %s, no info file found' % path)
            return False

        else:
            try:
                if file:
                    if vfs.exists(path):
                        vfs.delete(path)
                    if vfs.exists(json_file):
                        vfs.delete(json_file)
                elif epgid and vfs.exists(path):
                    for file_name in vfs.listdir(path)[1]:
                        file_path = vfs.path.join(path, file_name)
                        vfs.delete(file_path)
                    vfs.rmdir(path)
            except Exception, e:
                xbmc.log("failed to delete %s (%s)" % (path, str(e)))
            else:
Esempio n. 4
0
    def deleteLocalEpgidPath(self, epgid=False, file=False):

        if epgid:
            path = self.__getLocalEpgidPath(epgid, mkdir=False)
            json_file = self.__getEpgidJsonFile(epgid)
        elif file:
            path = file
            json_file = path + '.json.v1'
        else:
            return False

        if not vfs.exists(json_file):
            xbmc.log('could not delete %s, no info file found' % path)
            return False

        else:
            try:
                if file:
                    if vfs.exists(path):
                        vfs.delete(path)
                    if vfs.exists(json_file):
                        vfs.delete(json_file)
                elif epgid and vfs.exists(path):
                    for file_name in vfs.listdir(path)[1]:
                        file_path = vfs.path.join(path, file_name)
                        vfs.delete(file_path)
                    vfs.rmdir(path)
            except Exception, e:
                xbmc.log("failed to delete %s (%s)" % (path, str(e)))
            else: