def copy_from_archive(self):
        if self.archive and xbmcvfs.exists(self.archive_tar_path):
            log.log("Skipping download and decompression")

            archive = xbmcvfs.File(self.archive_tar_path)
            try:
                with progress.FileProgress(L10n(32016),
                                           archive, self.update_tar_path, archive.size(),
                                           self.background) as extractor:
                    extractor.start()
            except script_exceptions.Canceled:
                funcs.remove_file(self.tar_path)
                sys.exit(0)
            except script_exceptions.WriteError:
                sys.exit(1)
            return True
        return False
Example #2
0
    def copy_from_archive(self):
        if self.archive and xbmcvfs.exists(self.archive_tar_path):
            log.log("Skipping download and decompression")

            archive = xbmcvfs.File(self.archive_tar_path)
            try:
                with progress.FileProgress(L10n(32016),
                                           archive, self.update_tar_path,
                                           archive.size(),
                                           self.background) as extractor:
                    extractor.start()
            except script_exceptions.Canceled:
                funcs.remove_file(self.tar_path)
                sys.exit(0)
            except script_exceptions.WriteError:
                sys.exit(1)
            return True
        return False
Example #3
0
    def maybe_verify(self):
        if not self.verify_files:
            return

        log.log("Verifying update file")
        with closing(tarfile.open(self.update_tar_path, 'r')) as tf:
            tar_names = tf.getnames()

            for update_image in libreelec.UPDATE_IMAGES:
                path_in_tar = next(
                    name for name in tar_names
                    if name.endswith(os.path.join('target', update_image)))
                ti = tf.extractfile(path_in_tar)
                temp_image_path = os.path.join(TEMP_PATH, update_image)
                try:
                    with progress.FileProgress(L10n(32018), ti,
                                               temp_image_path, ti.size,
                                               self.background) as extractor:
                        extractor.start()
                    log.log("Extracted " + temp_image_path)
                except script_exceptions.Canceled:
                    return
                except script_exceptions.WriteError as e:
                    utils.write_error(temp_image_path, str(e))
                    return

                md5sum = tf.extractfile(path_in_tar + '.md5').read().split()[0]
                log.log("{}.md5 file = {}".format(update_image, md5sum))

                if not progress.md5sum_verified(md5sum, temp_image_path,
                                                self.background):
                    log.log("{} md5 mismatch!".format(update_image))
                    utils.ok(
                        L10n(32019).format(update_image),
                        self.selected_build.filename,
                        L10n(32020).format(update_image), L10n(32021))
                    utils.remove_update_files()
                    return
                else:
                    log.log("{} md5 is correct".format(update_image))

                funcs.remove_file(temp_image_path)
    def maybe_verify(self):
        if not self.verify_files:
            return

        log.log("Verifying update file")
        with closing(tarfile.open(self.update_tar_path, 'r')) as tf:
            tar_names = tf.getnames()

            for update_image in openelec.UPDATE_IMAGES:
                path_in_tar = next(name for name in tar_names
                                   if name.endswith(os.path.join('target', update_image)))
                ti = tf.extractfile(path_in_tar)
                temp_image_path = os.path.join(TEMP_PATH, update_image)
                try:
                    with progress.FileProgress(L10n(32018), ti, temp_image_path, ti.size,
                                               self.background) as extractor:
                        extractor.start()
                    log.log("Extracted " + temp_image_path)
                except script_exceptions.Canceled:
                    return
                except script_exceptions.WriteError as e:
                    utils.write_error(temp_image_path, str(e))
                    return

                md5sum = tf.extractfile(path_in_tar + '.md5').read().split()[0]
                log.log("{}.md5 file = {}".format(update_image, md5sum))
        
                if not progress.md5sum_verified(md5sum, temp_image_path,
                                                self.background):
                    log.log("{} md5 mismatch!".format(update_image))
                    utils.ok(L10n(32019).format(update_image),
                             self.selected_build.filename,
                             L10n(32020).format(update_image), L10n(32021))
                    utils.remove_update_files()
                    return
                else:
                    log.log("{} md5 is correct".format(update_image))

                funcs.remove_file(temp_image_path)
Example #5
0
    def maybe_download(self):
        try:
            remote_file = self.selected_build.remote_file()
        except requests.RequestException as e:
            utils.url_error(self.selected_build.url, str(e))
            sys.exit(1)

        filename = self.selected_build.filename
        tar_name = self.selected_build.tar_name
        size = self.selected_build.size

        self.download_path = os.path.join(TEMP_PATH, filename)
        self.temp_tar_path = os.path.join(TEMP_PATH, tar_name)
        self.update_tar_path = os.path.join(libreelec.UPDATE_DIR, tar_name)
        if self.archive:
            self.archive_tar_path = os.path.join(self.archive_dir, tar_name)

        if not self.copy_from_archive():
            if (os.path.isfile(self.download_path)
                    and os.path.getsize(self.download_path) == size):
                # Skip the download if the file exists with the correct size.
                log.log("Skipping download")
            else:
                try:
                    log.log("Starting download of {} to {}".format(
                        self.selected_build.url, self.download_path))
                    with progress.FileProgress(L10n(32014), remote_file,
                                               self.download_path, size,
                                               self.background) as downloader:
                        downloader.start()
                    log.log("Completed download")
                except script_exceptions.Canceled:
                    sys.exit(0)
                except requests.RequestException as e:
                    utils.url_error(self.selected_build.url, str(e))
                    sys.exit(1)
                except script_exceptions.WriteError as e:
                    utils.write_error(self.download_path, str(e))
                    sys.exit(1)

            if self.selected_build.compressed:
                try:
                    bf = open(self.download_path, 'rb')
                    log.log("Starting decompression of " + self.download_path)
                    with progress.DecompressProgress(
                            L10n(32015), bf, self.temp_tar_path, size,
                            self.background) as decompressor:
                        decompressor.start()
                    log.log("Completed decompression")
                except script_exceptions.Canceled:
                    sys.exit(0)
                except script_exceptions.WriteError as e:
                    utils.write_error(self.temp_tar_path, str(e))
                    sys.exit(1)
                except script_exceptions.DecompressError as e:
                    utils.decompress_error(self.download_path, str(e))
                    sys.exit(1)
                finally:
                    funcs.remove_file(self.download_path)

            self.maybe_copy_to_archive()

            log.log("Moving tar file to " + self.update_tar_path)
            os.renames(self.temp_tar_path, self.update_tar_path)

        addon.set_setting('update_pending', 'true')
    def maybe_download(self):
        try:
            remote_file = self.selected_build.remote_file()
        except requests.RequestException as e:
            utils.url_error(self.selected_build.url, str(e))
            sys.exit(1)

        filename = self.selected_build.filename
        tar_name = self.selected_build.tar_name
        size = self.selected_build.size
        
        self.download_path = os.path.join(TEMP_PATH, filename)
        self.temp_tar_path = os.path.join(TEMP_PATH, tar_name)
        self.update_tar_path = os.path.join(openelec.UPDATE_DIR, tar_name)
        if self.archive:
            self.archive_tar_path = os.path.join(self.archive_dir, tar_name)
        
        if not self.copy_from_archive():
            if (os.path.isfile(self.download_path) and
                    os.path.getsize(self.download_path) == size):
                    # Skip the download if the file exists with the correct size.
                log.log("Skipping download")
            else:
                try:
                    log.log("Starting download of {} to {}".format(self.selected_build.url,
                                                                   self.download_path))
                    with progress.FileProgress(L10n(32014), remote_file, self.download_path,
                                               size, self.background) as downloader:
                        downloader.start()
                    log.log("Completed download")
                except script_exceptions.Canceled:
                    sys.exit(0)
                except requests.RequestException as e:
                    utils.url_error(self.selected_build.url, str(e))
                    sys.exit(1)
                except script_exceptions.WriteError as e:
                    utils.write_error(self.download_path, str(e))
                    sys.exit(1)

            if self.selected_build.compressed:
                try:
                    bf = open(self.download_path, 'rb')
                    log.log("Starting decompression of " + self.download_path)
                    with progress.DecompressProgress(L10n(32015),
                                                     bf, self.temp_tar_path, size,
                                                     self.background) as decompressor:
                        decompressor.start()
                    log.log("Completed decompression")
                except script_exceptions.Canceled:
                    sys.exit(0)
                except script_exceptions.WriteError as e:
                    utils.write_error(self.temp_tar_path, str(e))
                    sys.exit(1)
                except script_exceptions.DecompressError as e:
                    utils.decompress_error(self.download_path, str(e))
                    sys.exit(1)
                finally:
                    funcs.remove_file(self.download_path)

            self.maybe_copy_to_archive()
        
            log.log("Moving tar file to " + self.update_tar_path)
            os.renames(self.temp_tar_path, self.update_tar_path)

        addon.set_setting('update_pending', 'true')