Exemplo n.º 1
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 err:
            logging.error("Can't initialize pyalpm: %s", err)
            self.metalinks = None
            return

        try:
            for package_name in self.package_names:
                metalink = ml.create(pacman, package_name, self.pacman_conf_file)
                if metalink is None:
                    logging.error("Error creating metalink for package %s. Installation will stop", 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]

                # 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 err:
            logging.error("Can't create download set: %s", err)
            self.metalinks = None
            return

        try:
            pacman.release()
            del pacman
        except Exception as err:
            logging.error("Can't release pyalpm: %s", err)
            self.metalinks = None
            return

        # Overwrite last event (to clean up the last message)
        self.queue_event('info', "")
Exemplo n.º 2
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', "")
Exemplo n.º 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', "")
Exemplo n.º 4
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 err:
            logging.error("Can't initialize pyalpm: %s", err)
            self.metalinks = None
            return

        try:
            for package_name in self.package_names:
                metalink = ml.create(pacman, package_name,
                                     self.pacman_conf_file)
                if metalink is None:
                    logging.error(
                        "Error creating metalink for package %s. Installation will stop",
                        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:
                        urls = metalink_info[key]['urls']
                        # Sort urls based on the mirrorlist we created earlier
                        sorted_urls = sorted(urls, key=self.url_sort_helper)
                        self.metalinks[key] = metalink_info[key]
                        # logging.debug(self.metalinks[key])
                        self.metalinks[key]['urls'] = sorted_urls
                        # logging.debug(self.metalinks[key])

                # 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 err:
            logging.error("Can't create download set: %s", err)
            self.metalinks = None
            return

        try:
            pacman.release()
            del pacman
        except Exception as err:
            logging.error("Can't release pyalpm: %s", err)
            self.metalinks = None
            return

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