예제 #1
0
    def get_available_updates(self):
        """Gets available updates, as Appliation instances, through yum.

        Returns:

            - A list of Applications.

        """

        logger.info('Getting available updates.')

        updates = []

        try:

            yum.renew_repo_cache()
            updates_available = yum.list_updates()
            rd = RepoData()
            primary_files = {}

            # For logging
            i = 1
            total = len(updates_available)

            for update in updates_available:

                application = None

                try:

                    #deps = yum.get_needed_dependencies(update)

                    repo = rd.get_repo(update.repo)

                    if not repo.id:

                        logger.info(
                            "No primary.xml data for {0}. Skipping.".format(
                                update.name))

                        continue

                    if repo.id not in primary_files:

                        primary_files[repo.id] = get_primary_file(repo.id, rd)

                    meta_packages = (primary_files[repo.id].find_packages(
                        update.name))

                    mp = None
                    for pkg in meta_packages:

                        if (pkg.name == update.name
                                and pkg.version == update.version
                                and pkg.release == update.release
                                and pkg.arch == update.arch):

                            mp = pkg

                            #file_data = self._create_file_data(
                            #    mp,
                            #    deps,
                            #    repo,
                            #    primary_files,
                            #    rd
                            #)
                            file_data = self._create_file_data(mp, repo)

                            dependencies = self._get_dependencies(
                                mp.name, mp.version, mp.release, mp.arch)

                            application = CreateApplication.create(
                                mp.name,
                                mp.complete_version,
                                mp.description,  # description
                                file_data,  # file_data
                                dependencies,  # dependencies
                                mp.url,  # support_url
                                '',  # vendor_severity
                                mp.size,  # file_size
                                '',  # vendor_id,
                                mp.vendor,  # vendor_name
                                None,  # install_date
                                mp.release_date,  # release_date
                                False,  # installed
                                repo.name,  # repo
                                "no",  # reboot_required
                                "yes"  # TODO: Is app uninstallable?
                            )

                            break

                except Exception as e:

                    logger.error("Could not get available update. Skipping.")
                    logger.exception(e)

                if application:

                    updates.append(application)
                    logger.debug(application)

                logger.debug("{0} out of {1} finished.".format(i, total))
                i += 1

            # Append all dependencies' file_data to app's file_data.
            # Must be done after getting all apps.
            for update in updates:
                self._append_file_data(update, updates)

        except Exception as e:

            logger.error("Could not get available updates.")
            logger.exception(e)

        logger.info('Done.')
        return updates
예제 #2
0
    def get_available_updates(self):
        """Gets available updates, as Appliation instances, through yum.

        Returns:

            - A list of Applications.

        """

        logger.info('Getting available updates.')

        updates = []

        try:

            yum.renew_repo_cache()
            updates_available = yum.list_updates()
            rd = RepoData()
            primary_files = {}

            # For logging
            i = 1
            total = len(updates_available)

            for update in updates_available:

                application = None

                try:

                    #deps = yum.get_needed_dependencies(update)

                    repo = rd.get_repo(update.repo)

                    if not repo.id:

                        logger.info(
                            "No primary.xml data for {0}. Skipping."
                            .format(update.name)
                        )

                        continue

                    if repo.id not in primary_files:

                        primary_files[repo.id] = get_primary_file(repo.id, rd)

                    meta_packages = (
                        primary_files[repo.id].find_packages(update.name)
                    )

                    mp = None
                    for pkg in meta_packages:

                        if (
                            pkg.name == update.name
                            and pkg.version == update.version
                            and pkg.release == update.release
                            and pkg.arch == update.arch
                        ):

                            mp = pkg

                            #file_data = self._create_file_data(
                            #    mp,
                            #    deps,
                            #    repo,
                            #    primary_files,
                            #    rd
                            #)
                            file_data = self._create_file_data(mp, repo)

                            dependencies = self._get_dependencies(
                                mp.name,
                                mp.version,
                                mp.release,
                                mp.arch
                            )

                            application = CreateApplication.create(
                                mp.name,
                                mp.complete_version,
                                mp.description,  # description
                                file_data,  # file_data
                                dependencies,  # dependencies
                                mp.url,  # support_url
                                '',  # vendor_severity
                                mp.size,  # file_size
                                '',  # vendor_id,
                                mp.vendor,  # vendor_name
                                None,  # install_date
                                mp.release_date,  # release_date
                                False,  # installed
                                repo.name,  # repo
                                "no",  # reboot_required
                                "yes"  # TODO: Is app uninstallable?
                            )

                            break

                except Exception as e:

                    logger.error("Could not get available update. Skipping.")
                    logger.exception(e)

                if application:

                    updates.append(application)
                    logger.debug(application)

                logger.debug("{0} out of {1} finished.".format(i, total))
                i += 1

            # Append all dependencies' file_data to app's file_data.
            # Must be done after getting all apps.
            for update in updates:
                self._append_file_data(update, updates)

        except Exception as e:

            logger.error("Could not get available updates.")
            logger.exception(e)

        logger.info('Done.')
        return updates
예제 #3
0
    def get_available_updates(self):
        logger.debug('Getting available updates.')

        try:
            logger.debug("Renewing repo cache.")
            yum.renew_repo_cache()
            logger.debug("Done renewing repo cache.")

            logger.debug("Getting list of available updates.")
            cmd = [yum.yum_cmd, 'info', 'updates', '-v']
            output, err = self.utilcmds.run_command(cmd)
            if err:
                raise Exception(err)

            avail_updates = self.yum_parse.parse_info_updates(output)
            logger.debug("Done getting list of available updates.")

            logger.debug("Getting severity of packages.")
            cmd = [yum.yum_cmd, 'list-security']
            output, err = self.utilcmds.run_command(cmd)
            if err:
                logger.error("Failed to get package severities.")
                logger.exception(err)
                severity_of_pkgs = {}
            else:
                severity_of_pkgs = self.yum_parse.parse_pkg_severity(output)
                logger.debug("Done getting severity of packages.")

            # For logging
            i = 1
            total = len(avail_updates)

            applications = []
            for pkg in avail_updates:
                try:
                    app_name = pkg.get(PkgKeys.name, '')

                    dependencies = self._get_dependencies(
                        app_name,
                        pkg[PkgKeys.version],
                        pkg[PkgKeys.release],
                        pkg[PkgKeys.arch]
                    )

                    lookup_name = pkg.get(PkgKeys.lookup_name, '')
                    vendor_severity = \
                        severity_of_pkgs.get(lookup_name, '')

                    app = CreateApplication.create(
                        app_name,
                        pkg[PkgKeys.full_version],
                        pkg[PkgKeys.description],  # description
                        [],  # file_data
                        dependencies,  # dependencies
                        '',  # support_url
                        vendor_severity,  # vendor_severity
                        '',  # file_size
                        '',  # vendor_id,
                        '',  # vendor_name
                        None,  # install_date
                        pkg[PkgKeys.release_date],  # release_date
                        False,  # installed
                        "",  # repo
                        "no",  # reboot_required
                        "yes"  # TODO: check if app is uninstallable
                    )

                    if app:
                        logger.debug(app)
                        applications.append(app)

                    logger.debug("{0} out of {1} finished.".format(i, total))
                    i += 1

                except Exception as e:
                    logger.error(
                        "Failed to create app for: {0}".format(app_name)
                    )
                    logger.exception(e)

                    continue

            logger.debug("Done getting available updates.")

            return applications

        except Exception as e:
            logger.error("Failed to retrieve available updates.")
            logger.exception(e)

            return []
예제 #4
0
    def get_available_updates(self):
        logger.debug('Getting available updates.')

        try:
            logger.debug("Renewing repo cache.")
            yum.renew_repo_cache()
            logger.debug("Done renewing repo cache.")

            logger.debug("Getting list of available updates.")
            cmd = [yum.yum_cmd, 'info', 'updates', '-v']
            output, err = self.utilcmds.run_command(cmd)
            if err:
                raise Exception(err)

            avail_updates = self.yum_parse.parse_info_updates(output)
            logger.debug("Done getting list of available updates.")

            logger.debug("Getting severity of packages.")
            cmd = [yum.yum_cmd, 'list-security']
            output, err = self.utilcmds.run_command(cmd)
            if err:
                logger.error("Failed to get package severities.")
                logger.exception(err)
                severity_of_pkgs = {}
            else:
                severity_of_pkgs = self.yum_parse.parse_pkg_severity(output)
                logger.debug("Done getting severity of packages.")

            # For logging
            i = 1
            total = len(avail_updates)

            applications = []
            for pkg in avail_updates:
                try:
                    app_name = pkg.get(PkgKeys.name, '')

                    dependencies = self._get_dependencies(
                        app_name,
                        pkg[PkgKeys.version],
                        pkg[PkgKeys.release],
                        pkg[PkgKeys.arch]
                    )

                    lookup_name = pkg.get(PkgKeys.lookup_name, '')
                    vendor_severity = \
                        severity_of_pkgs.get(lookup_name, '')

                    app = CreateApplication.create(
                        app_name,
                        pkg[PkgKeys.full_version],
                        pkg[PkgKeys.description],  # description
                        [],  # file_data
                        dependencies,  # dependencies
                        '',  # support_url
                        vendor_severity,  # vendor_severity
                        '',  # file_size
                        '',  # vendor_id,
                        '',  # vendor_name
                        None,  # install_date
                        pkg[PkgKeys.release_date],  # release_date
                        False,  # installed
                        "",  # repo
                        "no",  # reboot_required
                        "yes"  # TODO: check if app is uninstallable
                    )

                    if app:
                        logger.debug(app)
                        applications.append(app)

                    logger.debug("{0} out of {1} finished.".format(i, total))
                    i += 1

                except Exception as e:
                    logger.error(
                        "Failed to create app for: {0}".format(app_name)
                    )
                    logger.exception(e)

                    continue

            logger.debug("Done getting available updates.")

            return applications

        except Exception as e:
            logger.error("Failed to retrieve available updates.")
            logger.exception(e)

            return []