예제 #1
0
    def start(self, metalinks=None):
        """ Begin download """
        if metalinks:
            self.metalinks = metalinks

        # Create downloads list from package list
        if self.metalinks is None:
            self.create_metalinks_list()

        if self.metalinks is None:
            # Still None? Error!
            txt = _("Can't create download package list.")
            raise misc.InstallError(txt)

        download = download_requests.Download(self.pacman_cache_dir,
                                              self.xz_cache_dirs,
                                              self.callback_queue)

        if not download.start(self.metalinks):
            # When we can't download (even one package), we stop right here
            txt = _("Can't download needed packages. Cnchi can't continue.")
            raise misc.InstallError(txt)
예제 #2
0
    def create_metalinks_list(self):
        """ Create metalinks list """
        self.pkg = pack.SelectPackages(self.settings, self.callback_queue)
        self.pkg.create_package_list()

        if not self.pkg.packages:
            txt = _("Cannot create package list.")
            raise misc.InstallError(txt)

        # Won't download anything here. It's just to create the metalinks list
        self.down = download.DownloadPackages(
            package_names=self.pkg.packages,
            pacman_conf_file='/etc/pacman.conf',
            pacman_cache_dir='/var/cache/pacman/pkg',
            settings=self.settings,
            callback_queue=self.callback_queue)

        # Create metalinks list
        self.down.create_metalinks_list()

        if not self.down.metalinks:
            txt = _("Cannot create download package list (metalinks).")
            raise misc.InstallError(txt)
예제 #3
0
    def create_metalinks_list(self):
        """ Creates a downloads list (metalinks) from the package list """

        self.queue_event('percent', '0')
        self.queue_event('info', _('Creating the list of packages to download...'))
        processed_packages = 0
        total_packages = len(self.package_names)

        self.metalinks = {}

        try:
            pacman = pac.Pac(
                conf_path=self.pacman_conf_file,
                callback_queue=self.callback_queue)
            if pacman is None:
                return None
        except Exception as ex:
            self.metalinks = None
            template = "Can't initialize pyalpm. An exception of type {0} occured. Arguments:\n{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            logging.error(message)
            return

        try:
            for package_name in self.package_names:
                metalink = ml.create(pacman, package_name, self.pacman_conf_file)
                if metalink is None:
                    txt = "Error creating metalink for package %s. Installation will stop"
                    logging.error(txt, package_name)
                    txt = _("Error creating metalink for package {0}. "
                            "Installation will stop").format(package_name)
                    raise misc.InstallError(txt)

                # Get metalink info
                metalink_info = ml.get_info(metalink)

                # Update downloads list with the new info from
                # the processed metalink
                for key in metalink_info:
                    if key not in self.metalinks:
                        self.metalinks[key] = metalink_info[key]
                        urls = metalink_info[key]['urls']
                        if self.settings:
                            # Sort urls based on the mirrorlist
                            # we created earlier
                            sorted_urls = sorted(
                                urls,
                                key=self.url_sort_helper)
                            self.metalinks[key]['urls'] = sorted_urls
                        else:
                            # When testing, settings is not available
                            self.metalinks[key]['urls'] = urls

                # Show progress to the user
                processed_packages += 1
                percent = round(float(processed_packages / total_packages), 2)
                self.queue_event('percent', str(percent))
        except Exception as ex:
            template = "Can't create download set. An exception of type {0} occured. Arguments:\n{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            logging.error(message)
            self.metalinks = None
            return

        try:
            pacman.release()
            del pacman
        except Exception as ex:
            self.metalinks = None
            template = "Can't release pyalpm. An exception of type {0} occured. Arguments:\n{1!r}"
            message = template.format(type(ex).__name__, ex.args)
            logging.error(message)
            return

        # Overwrite last event (to clean up the last message)
        self.queue_event('info', "")