Ejemplo n.º 1
0
 def __show_download_files_info(self):
     count = 0
     pl = self._url_path_list[:]
     TextInterface.output(
         "%s: %s %s" % (
             darkblue(_("Aggregated download")),
             darkred(str(len(pl))),
             darkblue(ngettext("item", "items", len(pl))),
         ),
         importance = 0,
         level = "info",
         header = purple("  ## ")
     )
     for url, save_path in pl:
         count += 1
         fname = os.path.basename(url)
         uri = spliturl(url)[1]
         TextInterface.output(
             "[%s] %s => %s" % (
                 darkblue(str(count)),
                 darkgreen(uri),
                 blue(fname),
             ),
             importance = 0,
             level = "info",
             header = brown("   # ")
         )
Ejemplo n.º 2
0
 def __show_download_files_info(self):
     count = 0
     pl = self._url_path_list[:]
     TextInterface.output(
         "%s: %s %s" % (
             darkblue(_("Aggregated download")),
             darkred(str(len(pl))),
             darkblue(ngettext("item", "items", len(pl))),
         ),
         importance = 0,
         level = "info",
         header = purple("  ## ")
     )
     for url, save_path in pl:
         count += 1
         fname = os.path.basename(url)
         uri = spliturl(url)[1]
         TextInterface.output(
             "[%s] %s => %s" % (
                 darkblue(str(count)),
                 darkgreen(uri),
                 blue(fname),
             ),
             importance = 0,
             level = "info",
             header = brown("   # ")
         )
Ejemplo n.º 3
0
        def show_successful_download(down_list, data_transfer):
            for _pkg_id, repository_id, fname, _cksum, _signatures in down_list:
                best_mirror = get_best_mirror(repository_id)
                mirrorcount = repo_uris[repository_id].index(best_mirror) + 1
                basef = os.path.basename(fname)

                txt = "( mirror #%s ) [%s] %s %s %s" % (
                    mirrorcount,
                    brown(basef),
                    darkred(_("success")),
                    blue("@"),
                    red(self._get_url_name(best_mirror)),
                )
                self._entropy.output(
                    txt,
                    importance = 1,
                    level = "info",
                    header = red("   ## ")
                )

            if data_transfer:
                txt = " %s: %s%s%s" % (
                    blue(_("Aggregated transfer rate")),
                    bold(entropy.tools.bytes_into_human(data_transfer)),
                    darkred("/"),
                    darkblue(_("second")),
                )
                self._entropy.output(
                    txt,
                    importance = 1,
                    level = "info",
                    header = red("   ## ")
                )
Ejemplo n.º 4
0
    def _print_advisory_information(self, entropy_client,
                                    advisory_data, key):
        """
        Print Security Advisory.
        """
        toc = []

        # print advisory code
        toc.append(
            blue(" @@ ") + \
                red("%s " % (_("Advisory Identifier"),)) + bold(key) + \
                red(" | ")+blue(advisory_data['url']))

        # title
        toc.append((darkgreen("    %s:" % (_("Title"),)),
            darkred(advisory_data['title'])))

        # description
        description = advisory_data['description'].split("\n")
        desc_text = darkgreen("    %s:" % (_("Description"),) )
        for x in description:
            toc.append((desc_text, x.strip()))
            desc_text = " "

        for item in advisory_data['description_items']:
            desc_text = " %s " % (darkred("(*)"),)
            count = 8
            mystr = []
            for word in item.split():
                count -= 1
                mystr.append(word)
                if count < 1:
                    toc.append((" ", desc_text+' '.join(mystr)))
                    desc_text = "   "
                    mystr = []
                    count = 8
            if count < 8:
                toc.append((" ", desc_text+' '.join(mystr)))

        # background
        if advisory_data['background']:
            background = advisory_data['background'].split("\n")
            bg_text = darkgreen("    %s:" % (_("Background"),))
            for x in background:
                toc.append((bg_text, purple(x.strip())))
                bg_text = " "

        # access
        if advisory_data['access']:
            toc.append((darkgreen("    %s:" % (_("Exploitable"),)),
                bold(advisory_data['access'])))

        # impact
        if advisory_data['impact']:
            impact = advisory_data['impact'].split("\n")
            imp_text = darkgreen("    %s:" % (_("Impact"),))
            for x in impact:
                toc.append((imp_text, brown(x.strip())))
                imp_text = " "

        # impact type
        if advisory_data['impacttype']:
            toc.append((darkgreen("    %s:" % (_("Impact type"),)),
                bold(advisory_data['impacttype'])))

        # revised
        if advisory_data['revised']:
            toc.append((darkgreen("    %s:" % (_("Revised"),)),
                brown(advisory_data['revised'])))

        # announced
        if advisory_data['announced']:
            toc.append((darkgreen("    %s:" % (_("Announced"),)),
                brown(advisory_data['announced'])))

        # synopsis
        synopsis = advisory_data['synopsis'].split("\n")
        syn_text = darkgreen("    %s:" % (_("Synopsis"),))
        for x in synopsis:
            toc.append((syn_text, x.strip()))
            syn_text = " "

        # references
        if advisory_data['references']:
            toc.append(darkgreen("    %s:" % (_("References"),)))
            for reference in advisory_data['references']:
                toc.append((" ", darkblue(reference)))

        # gentoo bugs
        if advisory_data['bugs']:
            toc.append(darkgreen("    %s:" % (_("Upstream bugs"),)))
            for bug in advisory_data['bugs']:
                toc.append((" ", darkblue(bug)))

        # affected
        if advisory_data['affected']:
            toc.append(darkgreen("    %s:" % (_("Affected"),)))
            for key in advisory_data['affected']:
                toc.append((" ", darkred(key)))
                affected_data = advisory_data['affected'][key][0]
                vul_vers = affected_data['vul_vers']
                unaff_vers = affected_data['unaff_vers']
                if vul_vers:
                    toc.append((" ", brown("%s: " % (
                        _("vulnerable versions"),))+", ".join(vul_vers)))
                if unaff_vers:
                    toc.append((" ", brown("%s: " % (
                        _("unaffected versions"),))+", ".join(unaff_vers)))

        # workaround
        workaround = advisory_data['workaround'].split("\n")
        if advisory_data['workaround']:
            work_text = darkgreen("    %s:" % (_("Workaround"),))
            for x in workaround:
                toc.append((work_text, darkred(x.strip())))
                work_text = " "

        # resolution
        if advisory_data['resolution']:
            res_text = darkgreen("    %s:" % (_("Resolution"),))
            resolutions = advisory_data['resolution']
            for resolution in resolutions:
                for x in resolution.split("\n"):
                    toc.append((res_text, x.strip()))
                    res_text = " "

        print_table(entropy_client, toc, cell_spacing=3)
Ejemplo n.º 5
0
    def _show_install_queue(cls, entropy_client, inst_repo,
                            run_queue, removal_queue, ask, pretend,
                            quiet, verbose):
        """
        Show expanded installation queue to user.
        """
        download_size = 0
        unpack_size = 0
        on_disk_used_size = 0
        on_disk_freed_size = 0
        pkgs_install = 0
        pkgs_update = 0
        pkgs_reinstall = 0
        pkgs_downgrade = 0
        pkgs_remove = len(removal_queue)
        client_settings = entropy_client.ClientSettings()
        splitdebug = client_settings['misc']['splitdebug']

        if run_queue and ((ask or pretend) and not quiet):
            inst_msg = _("These are the packages that would be installed")
            entropy_client.output(
                "%s:" % (blue(inst_msg),),
                header=darkred(" @@ "))

        for package_id, repository_id in run_queue:

            repo = entropy_client.open_repository(repository_id)
            atom = repo.retrieveAtom(package_id)

            pkgver = repo.retrieveVersion(package_id)
            pkgtag = repo.retrieveTag(package_id)
            pkgrev = repo.retrieveRevision(package_id)
            pkgfile = repo.retrieveDownloadURL(package_id)
            on_disk_used_size += repo.retrieveOnDiskSize(package_id)

            pkgsize = repo.retrieveSize(package_id)
            extra_downloads = repo.retrieveExtraDownload(package_id)
            for extra_download in extra_downloads:
                if not splitdebug and (extra_download['type'] == "debug"):
                    continue
                pkgsize += extra_download['size']
                on_disk_used_size += extra_download['disksize']

            unpack_size += int(pkgsize) * 2

            fetch_path = PackageAction.get_standard_fetch_disk_path(pkgfile)
            if not os.path.exists(fetch_path):
                download_size += int(pkgsize)
            else:
                try:
                    f_size = entropy.tools.get_file_size(fetch_path)
                except OSError:
                    f_size = 0
                download_size += pkgsize - f_size

            installed_ver = '-1'
            installed_tag = ''
            installed_rev = 0
            inst_repo_s = None

            inst_pkg_id, inst_pkg_rc = cls._match_pkg_in_installed_repo(
                repo, package_id, inst_repo)

            if inst_pkg_rc == 0:
                installed_ver = inst_repo.retrieveVersion(
                    inst_pkg_id)
                installed_tag = inst_repo.retrieveTag(
                    inst_pkg_id)
                installed_rev = inst_repo.retrieveRevision(
                    inst_pkg_id)
                inst_repo_s = \
                    inst_repo.getInstalledPackageRepository(
                        inst_pkg_id)
                if inst_repo_s is None:
                    inst_repo_s = _("Not available")
                on_disk_freed_size += inst_repo.retrieveOnDiskSize(
                    inst_pkg_id)
                extra_downloads = inst_repo.retrieveExtraDownload(
                    inst_pkg_id)
                for extra_download in extra_downloads:
                    on_disk_freed_size += extra_download['disksize']

            # statistics generation complete
            # if --quiet, we're done doing stuff
            if quiet:
                continue

            inst_meta = (installed_ver, installed_tag, installed_rev,)
            avail_meta = (pkgver, pkgtag, pkgrev,)
            action = 0
            repo_switch = False
            if (repository_id != inst_repo_s) and \
                    (inst_repo_s is not None):
                repo_switch = True

            if repo_switch:
                flags = darkred(" [")
            else:
                flags = " ["
            if inst_repo_s is None:
                inst_repo_s = _('Not available')

            pkgcmp = entropy_client.get_package_action(
                (package_id, repository_id))

            if pkgcmp == 0:
                pkgs_reinstall += 1
                flags += red("R")
                action = 1
            elif pkgcmp == 1:
                pkgs_install += 1
                flags += darkgreen("N")
            elif pkgcmp == 2:
                pkgs_update += 1
                if avail_meta == inst_meta:
                    flags += blue("U") + red("R")
                else:
                    flags += blue("U")
                action = 2
            else:
                pkgs_downgrade += 1
                flags += darkblue("D")
                action = -1

            if repo_switch:
                flags += darkred("] ")
            else:
                flags += "] "

            if repo_switch:
                repo_info = "[%s->%s] " % (
                    brown(inst_repo_s),
                    darkred(repository_id),)
            else:
                repo_info = "[%s] " % (
                    brown(repository_id),)

            old_info = ""
            if action != 0:
                old_info = "   [%s|%s" % (
                    blue(installed_ver),
                    darkred(const_convert_to_unicode(installed_rev)),)

                old_tag = "]"
                if installed_tag:
                    old_tag = "|%s%s" % (
                        darkred(installed_tag),
                        old_tag,)
                old_info += old_tag

            entropy_client.output(
                "%s%s%s|%s%s" % (
                    flags,
                    repo_info,
                    enlightenatom(atom),
                    darkred(const_convert_to_unicode(pkgrev)),
                    old_info,),
                header=darkred(" ##"))

        delta_size = on_disk_used_size - on_disk_freed_size
        needed_size = delta_size
        if unpack_size > 0:
            needed_size += unpack_size

        if (ask or pretend or verbose) and removal_queue:
            mytxt = "%s (%s):" % (
                blue(_("These are the packages that would be removed")),
                bold(_("conflicting/substituted")),
            )
            entropy_client.output(
                mytxt, header=darkred(" @@ "))

        for package_id in removal_queue:

            atom = inst_repo.retrieveAtom(package_id)
            on_disk_freed_size += inst_repo.retrieveOnDiskSize(
                package_id)
            extra_downloads = inst_repo.retrieveExtraDownload(
                package_id)

            for extra_download in extra_downloads:
                on_disk_freed_size += extra_download['disksize']

            installedfrom = inst_repo.getInstalledPackageRepository(
                package_id)
            if installedfrom is None:
                installedfrom = _("Not available")

            mytxt = "[%s] %s%s: %s%s %s" % (
                purple("W"),
                darkred("["),
                brown(_("from")),
                bold(installedfrom),
                darkred("]"),
                enlightenatom(atom))
            entropy_client.output(mytxt, header=darkred("   ## "))

        # if --quiet, there is nothing else to show
        if quiet:
            return

        mytxt = "%s: %s" % (
            blue(_("Packages needing to be installed/updated/downgraded")),
            darkred(const_convert_to_unicode(len(run_queue))),)
        entropy_client.output(mytxt, header=darkred(" @@ "))

        mytxt = "%s: %s" % (
            blue(_("Packages needing to be removed")),
            darkred(const_convert_to_unicode(pkgs_remove)),)
        entropy_client.output(mytxt, header=darkred(" @@ "))

        if ask or verbose or pretend:

            mytxt = "%s: %s" % (
                darkgreen(_("Packages needing to be installed")),
                darkgreen(const_convert_to_unicode(pkgs_install)),
            )
            entropy_client.output(
                mytxt, header=darkred(" @@ "))

            mytxt = "%s: %s" % (
                brown(_("Packages needing to be reinstalled")),
                brown(const_convert_to_unicode(pkgs_reinstall)),
            )
            entropy_client.output(
                mytxt, header=darkred(" @@ "))

            mytxt = "%s: %s" % (
                blue(_("Packages needing to be updated")),
                blue(const_convert_to_unicode(pkgs_update)),
            )
            entropy_client.output(
                mytxt, header=darkred(" @@ "))

            mytxt = "%s: %s" % (
                darkred(_("Packages needing to be downgraded")),
                darkred(const_convert_to_unicode(pkgs_downgrade)),
            )
            entropy_client.output(
                mytxt, header=darkred(" @@ "))

        if download_size > 0:
            mysize = const_convert_to_unicode(
                entropy.tools.bytes_into_human(download_size))
        else:
            mysize = const_convert_to_unicode("0b")

        mytxt = "%s: %s" % (
            blue(_("Download size")),
            bold(mysize),
        )
        entropy_client.output(
            mytxt, header=darkred(" @@ "))

        if delta_size > 0:
            mysizetxt = _("Used disk space")
        else:
            mysizetxt = _("Freed disk space")
            delta_size = -delta_size
        delta_human = entropy.tools.bytes_into_human(delta_size)

        mytxt = "%s: %s" % (
            blue(mysizetxt),
            bold(delta_human),
        )
        entropy_client.output(mytxt, header=darkred(" @@ "))

        if needed_size < 0:
            needed_size = -needed_size

        mytxt = "%s: %s %s" % (
            blue(_("You need at least")),
            bold(entropy.tools.bytes_into_human(needed_size)),
            blue(_("of free space")),
        )
        entropy_client.output(
            mytxt, header=darkred(" @@ "))

        # check for disk space and print a warning
        target_dir = etpConst['entropyunpackdir']
        while not os.path.isdir(target_dir):
            target_dir = os.path.dirname(target_dir)
        size_match = entropy.tools.check_required_space(target_dir,
            needed_size)

        if not size_match:
            mytxt = "%s: %s" % (
                blue(_("You don't have enough space for "
                  "the installation. Free some space into")),
                darkred(target_dir),)

            entropy_client.output(
                bold(_("Attention")),
                header=darkred(" !!! "))
            entropy_client.output(
                bold(_("Attention")),
                header=darkred(" !!! "))

            entropy_client.output(
                mytxt, header=darkred(" !!! "))

            entropy_client.output(
                bold(_("Attention")),
                header=darkred(" !!! "))
            entropy_client.output(
                bold(_("Attention")),
                header=darkred(" !!! "))