Exemple #1
0
    def _list(self, entropy_client, inst_repo):
        """
        Solo PreservedLibs List command.
        """
        quiet = self._nsargs.quiet
        verbose = self._nsargs.verbose

        preserved_mgr = preservedlibs.PreservedLibraries(
            inst_repo, None, frozenset(),
            root=etpConst['systemroot'])

        preserved = preserved_mgr.list()

        if not preserved:
            if not quiet:
                entropy_client.output(
                    darkgreen(_("No preserved libraries found")),
                    header=darkred(" @@ "))

            return 0

        for library, elfclass, path, atom in preserved:

            if quiet:
                entropy_client.output(path, level="generic")
                continue

            needed_by_str = const_convert_to_unicode("")
            if verbose:
                needed_by_str += ", %s:" % (
                    darkgreen(_("needed by")),
                )

            entropy_client.output(
                "%s [%s:%s -> %s]%s" % (
                    darkred(path),
                    purple(library),
                    teal(const_convert_to_unicode(elfclass)),
                    enlightenatom(atom),
                    needed_by_str,
                ))

            if verbose:
                package_ids = inst_repo.searchNeeded(
                    library, elfclass=elfclass)
                for package_id in package_ids:
                    atom = inst_repo.retrieveAtom(package_id)
                    if atom is None:
                        continue

                    entropy_client.output(
                        "%s" % (enlightenatom(atom),),
                        header=brown(" -> "),
                        importance=0)

        return 0
Exemple #2
0
    def _list(self, entropy_client, inst_repo):
        """
        Solo PreservedLibs List command.
        """
        quiet = self._nsargs.quiet
        verbose = self._nsargs.verbose

        preserved_mgr = preservedlibs.PreservedLibraries(
            inst_repo, None, frozenset(), root=etpConst['systemroot'])

        preserved = preserved_mgr.list()

        if not preserved:
            if not quiet:
                entropy_client.output(darkgreen(
                    _("No preserved libraries found")),
                                      header=darkred(" @@ "))

            return 0

        for library, elfclass, path, atom in preserved:

            if quiet:
                entropy_client.output(path, level="generic")
                continue

            needed_by_str = const_convert_to_unicode("")
            if verbose:
                needed_by_str += ", %s:" % (darkgreen(_("needed by")), )

            entropy_client.output("%s [%s:%s -> %s]%s" % (
                darkred(path),
                purple(library),
                teal(const_convert_to_unicode(elfclass)),
                enlightenatom(atom),
                needed_by_str,
            ))

            if verbose:
                package_ids = inst_repo.searchNeeded(library,
                                                     elfclass=elfclass)
                for package_id in package_ids:
                    atom = inst_repo.retrieveAtom(package_id)
                    if atom is None:
                        continue

                    entropy_client.output("%s" % (enlightenatom(atom), ),
                                          header=brown(" -> "),
                                          importance=0)

        return 0
Exemple #3
0
    def _show_preserved_libraries(self, entropy_client):
        """
        Inform User about preserved libraries living on the filesystem.
        This method is process and thread safe.
        """
        inst_repo = entropy_client.installed_repository()
        with inst_repo.shared():
            preserved_mgr = PreservedLibraries(
                inst_repo, None, frozenset(), root=etpConst['systemroot'])

            preserved = preserved_mgr.list()

        if preserved:
            mytxt = ngettext(
                "There is %s preserved library on the system",
                "There are %s preserved libraries on the system",
                len(preserved)) % (len(preserved),)
            entropy_client.output(
                darkgreen(mytxt),
                level="warning")

        for library, elfclass, path, atom in preserved:
            entropy_client.output(
                "%s [%s:%s -> %s]" % (
                    darkred(path),
                    purple(library),
                    teal(const_convert_to_unicode(elfclass)),
                    enlightenatom(atom),
                ))
Exemple #4
0
    def _show_preserved_libraries(self, entropy_client):
        """
        Inform User about preserved libraries living on the filesystem.
        This method is process and thread safe.
        """
        inst_repo = entropy_client.installed_repository()
        with inst_repo.shared():
            preserved_mgr = PreservedLibraries(inst_repo,
                                               None,
                                               frozenset(),
                                               root=etpConst['systemroot'])

            preserved = preserved_mgr.list()

        if preserved:
            mytxt = ngettext("There is %s preserved library on the system",
                             "There are %s preserved libraries on the system",
                             len(preserved)) % (len(preserved), )
            entropy_client.output(darkgreen(mytxt), level="warning")

        for library, elfclass, path, atom in preserved:
            entropy_client.output("%s [%s:%s -> %s]" % (
                darkred(path),
                purple(library),
                teal(const_convert_to_unicode(elfclass)),
                enlightenatom(atom),
            ))
Exemple #5
0
    def _show_did_you_mean(self, entropy_client, package, from_installed):
        """
        Show "Did you mean?" results for the given package name.
        """
        items = entropy_client.get_meant_packages(
            package, from_installed=from_installed)
        if not items:
            return

        mytxt = "%s %s %s %s %s" % (
            bold(const_convert_to_unicode("   ?")),
            teal(_("When you wrote")),
            bold(const_convert_to_unicode(package)),
            darkgreen(_("You Meant(tm)")),
            teal(_("one of these below?")),
        )
        entropy_client.output(mytxt)

        _cache = set()
        for pkg_id, repo_id in items:
            if from_installed:
                repo = entropy_client.installed_repository()
            else:
                repo = entropy_client.open_repository(repo_id)

            key_slot = repo.retrieveKeySlotAggregated(pkg_id)
            if key_slot not in _cache:
                entropy_client.output(
                    enlightenatom(key_slot),
                    header=brown("    # "))
                _cache.add(key_slot)
Exemple #6
0
    def _show_did_you_mean(self, entropy_client, package, from_installed):
        """
        Show "Did you mean?" results for the given package name.
        """
        items = entropy_client.get_meant_packages(
            package, from_installed=from_installed)
        if not items:
            return

        mytxt = "%s %s %s %s %s" % (
            bold(const_convert_to_unicode("   ?")),
            teal(_("When you wrote")),
            bold(const_convert_to_unicode(package)),
            darkgreen(_("You Meant(tm)")),
            teal(_("one of these below?")),
        )
        entropy_client.output(mytxt)

        _cache = set()
        for pkg_id, repo_id in items:
            if from_installed:
                repo = entropy_client.installed_repository()
            else:
                repo = entropy_client.open_repository(repo_id)

            key_slot = repo.retrieveKeySlotAggregated(pkg_id)
            if key_slot not in _cache:
                entropy_client.output(
                    enlightenatom(key_slot),
                    header=brown("    # "))
                _cache.add(key_slot)
Exemple #7
0
    def _show_removal_info(self, entropy_client, package_ids,
                           manual=False):
        """
        Show packages removal information.
        """
        if manual:
            entropy_client.output(
                "%s:" % (
                    blue(_("These are the packages that "
                      "should be MANUALLY removed")),),
                header=darkred(" @@ "))
        else:
            entropy_client.output(
                "%s:" % (
                    blue(_("These are the packages that "
                      "would be removed")),),
                header=darkred(" @@ "))

        total = len(package_ids)
        inst_repo = entropy_client.installed_repository()

        for count, package_id in enumerate(package_ids, 1):

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

            on_disk_size = inst_repo.retrieveOnDiskSize(package_id)
            pkg_size = inst_repo.retrieveSize(package_id)
            extra_downloads = inst_repo.retrieveExtraDownload(package_id)
            for extra_download in extra_downloads:
                pkg_size += extra_download['size']
                on_disk_size += extra_download['disksize']

            disksize = entropy.tools.bytes_into_human(on_disk_size)
            disksize_info = "%s%s%s" % (
                bold("["),
                brown("%s" % (disksize,)),
                bold("]"))
            repo_info = bold("[") + brown(installedfrom) + bold("]")

            mytxt = "%s %s %s" % (
                repo_info,
                enlightenatom(atom),
                disksize_info)

            entropy_client.output(mytxt, header=darkred(" ## "))
Exemple #8
0
    def _show_removal_info(self, entropy_client, package_ids, manual=False):
        """
        Show packages removal information.
        """
        if manual:
            entropy_client.output("%s:" % (blue(
                _("These are the packages that "
                  "should be MANUALLY removed")), ),
                                  header=darkred(" @@ "))
        else:
            entropy_client.output(
                "%s:" %
                (blue(_("These are the packages that "
                        "would be removed")), ),
                header=darkred(" @@ "))

        inst_repo = entropy_client.installed_repository()

        for package_id in package_ids:

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

            on_disk_size = inst_repo.retrieveOnDiskSize(package_id)
            extra_downloads = inst_repo.retrieveExtraDownload(package_id)
            for extra_download in extra_downloads:
                on_disk_size += extra_download['disksize']

            disksize = entropy.tools.bytes_into_human(on_disk_size)
            disksize_info = "%s%s%s" % (bold("["), brown(
                "%s" % (disksize, )), bold("]"))
            repo_info = bold("[") + brown(installedfrom) + bold("]")

            mytxt = "%s %s %s" % (repo_info, enlightenatom(atom),
                                  disksize_info)

            entropy_client.output(mytxt, header=darkred(" ## "))
Exemple #9
0
    def _run(self, entropy_client):
        """
        Mask/Unmask code logic.
        """
        found_pkg_atoms = []
        for package in self._packages:
            package_id, repoid = entropy_client.atom_match(
                package, mask_filter = False)

            if package_id == -1:
                mytxt = "!!! %s: %s %s." % (
                    purple(_("Warning")),
                    teal(const_convert_to_unicode(package)),
                    purple(_("is not available")),
                )
                entropy_client.output("!!!", level="warning", importance=1)
                entropy_client.output(mytxt, level="warning", importance=1)
                entropy_client.output("!!!", level="warning", importance=1)
                if len(package) > 3:
                    self._show_did_you_mean(
                        entropy_client, package,
                        from_installed=False)
                    entropy_client.output("!!!", level="warning", importance=1)
                continue

            found_pkg_atoms.append(package)

        if not found_pkg_atoms:
            entropy_client.output(
                "%s." % (
                    darkred(_("No packages found")),
                    ),
                level="error", importance=1)
            return 1

        if self._ask or self._pretend:
            mytxt = "%s:" % (
                blue(_("These are the packages that would be handled")),
                )
            entropy_client.output(
                mytxt,
                header=red(" @@ "))

        match_data = {}
        for package in found_pkg_atoms:
            matches, rc = entropy_client.atom_match(
                package, multi_match = True, multi_repo = True,
                    mask_filter = False)
            match_data[package] = matches

            flags = darkgreen(" [")
            if self._action == "mask":
                flags += brown("M")
            else:
                flags += red("U")
            flags += darkgreen("] ")
            entropy_client.output(
                darkred(" ##") + flags + purple(package))

            if rc == 0:
                # also show found pkgs
                for package_id, repository_id in matches:
                    repo = entropy_client.open_repository(repository_id)
                    atom = repo.retrieveAtom(package_id)
                    entropy_client.output(
                        "    -> " + enlightenatom(atom))

        if self._pretend:
            return 0

        if self._ask:
            answer = entropy_client.ask_question(
                _("Would you like to continue?"))
            if answer == _("No"):
                return 0

        for package, matches in match_data.items():
            for match in matches:
                if self._action == "mask":
                    done = entropy_client.mask_package_generic(match, package)
                else:
                    done = entropy_client.unmask_package_generic(match, package)
                if not done:
                    mytxt = "!!! %s: %s %s." % (
                        purple(_("Warning")),
                        teal(const_convert_to_unicode(package)),
                        purple(_("action not executed")),
                    )
                    entropy_client.output("!!!", level="warning", importance=1)
                    entropy_client.output(mytxt, level="warning", importance=1)
                    entropy_client.output("!!!", level="warning", importance=1)

        entropy_client.output("Have a nice day.")
        return 0
Exemple #10
0
    def _prompt_removal(self, entropy_client, inst_repo, package_ids,
                        system_packages_check):
        """
        Show list of packages that would be removed and ask User
        about dependencies calculation, if --ask has been provided.
        """
        ask = self._nsargs.ask
        verbose = self._nsargs.verbose
        pretend = self._nsargs.pretend
        plain_removal_queue = []
        deep_removal = True

        entropy_client.output(
            "%s:" % (
                teal(_("These are the chosen packages")),),
            header=darkgreen(" @@ "))

        total = len(package_ids)
        for count, package_id in enumerate(package_ids, 1):

            atom = inst_repo.retrieveAtom(package_id)
            if system_packages_check:
                valid = entropy_client.validate_package_removal(
                    package_id)
                if not valid:
                    mytxt = "%s: %s. %s." % (
                        enlightenatom(atom),
                        darkred(_("vital package")),
                        darkred(_("Removal forbidden")),
                    )
                    entropy_client.output(
                        mytxt,
                        level="warning",
                        count=(count, total),
                        header=bold("   !!! "))
                    continue

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

            on_disk_size = inst_repo.retrieveOnDiskSize(package_id)
            extra_downloads = inst_repo.retrieveExtraDownload(package_id)

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

            disksize = entropy.tools.bytes_into_human(on_disk_size)
            disksizeinfo = " [%s]" % (
                bold(const_convert_to_unicode(disksize)),)

            entropy_client.output(
                "[%s] %s %s" % (
                    brown(installedfrom),
                    enlightenatom(atom),
                    disksizeinfo),
                count=(count, total),
                header=darkgreen("   # "))

        if verbose or ask or pretend:
            entropy_client.output(
                "%s: %d" % (
                    blue(_("Packages involved")),
                    total,),
                header=purple(" @@ "))

        return plain_removal_queue, deep_removal
Exemple #11
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(" !!! "))
Exemple #12
0
    def _config_action(self, entropy_client):
        """
        Solo Config command action.
        """
        ask = self._nsargs.ask
        pretend = self._nsargs.pretend
        verbose = self._nsargs.verbose

        packages = entropy_client.packages_expand(
            self._nsargs.packages)
        inst_repo = entropy_client.installed_repository()
        package_ids = self._scan_installed_packages(
            entropy_client, inst_repo, packages)

        if not packages:
            entropy_client.output(
                "%s." % (
                    darkred(_("No packages found")),),
                level="error", importance=1)
            return 1, False

        for count, package_id in enumerate(package_ids, 1):

            atom = inst_repo.retrieveAtom(package_id)
            installed_from = inst_repo.getInstalledPackageRepository(
                package_id)
            if installed_from is None:
                installed_from = _("Not available")

            mytxt = "%s | %s: %s" % (
                enlightenatom(atom),
                brown(_("installed from")),
                darkred(installed_from),
                )
            entropy_client.output(
                mytxt,
                count=(count, len(package_ids)),
                header=darkgreen("   # "))

        if verbose or ask or pretend:
            entropy_client.output(
                "%s: %s" % (
                    blue(_("Packages involved")),
                    len(package_ids),),
                header=darkred(" @@ "))

        if ask:
            exit_st = entropy_client.ask_question(
                question = "     %s" % (
                    _("Would you like to continue ?"),))
            if exit_st == _("No"):
                return 1, False

        if pretend:
            return 0, False

        for count, package_id in enumerate(package_ids, 1):

            atom = inst_repo.retrieveAtom(package_id)
            pkg = None

            try:
                pkg = entropy_client.Package()
                pkg.prepare((package_id,), "config")

                xterm_header = "equo (%s) :: %d of %d ::" % (
                    _("configure"), count, len(package_ids))

                entropy_client.output(
                    darkgreen(atom),
                    count=(count, len(package_ids)),
                    header=darkred(" ::: ") + ">>> ")

                exit_st = pkg.run(xterm_header=xterm_header)
                if exit_st not in (0, 3):
                    return 1, True

            finally:
                if pkg is not None:
                    pkg.kill()

        return 0, True
Exemple #13
0
    def _config_action(self, entropy_client):
        """
        Solo Config command action.
        """
        ask = self._nsargs.ask
        pretend = self._nsargs.pretend
        verbose = self._nsargs.verbose

        inst_repo = entropy_client.installed_repository()
        with inst_repo.shared():

            packages = entropy_client.packages_expand(
                self._nsargs.packages)
            package_ids = self._scan_installed_packages(
                entropy_client, inst_repo, packages)

            if not package_ids:
                entropy_client.output(
                    "%s." % (
                        darkred(_("No packages found")),),
                    level="error", importance=1)
                return 1, False

            for count, package_id in enumerate(package_ids, 1):

                atom = inst_repo.retrieveAtom(package_id)
                installed_from = inst_repo.getInstalledPackageRepository(
                    package_id)
                if installed_from is None:
                    installed_from = _("Not available")

                mytxt = "%s | %s: %s" % (
                    enlightenatom(atom),
                    brown(_("installed from")),
                    darkred(installed_from),
                    )
                entropy_client.output(
                    mytxt,
                    count=(count, len(package_ids)),
                    header=darkgreen("   # "))

        if verbose or ask or pretend:
            entropy_client.output(
                "%s: %s" % (
                    blue(_("Packages involved")),
                    len(package_ids),),
                header=darkred(" @@ "))

        if ask:
            exit_st = entropy_client.ask_question(
                question = "     %s" % (
                    _("Would you like to continue ?"),))
            if exit_st == _("No"):
                return 1, False

        if pretend:
            return 0, False

        action_factory = entropy_client.PackageActionFactory()

        for count, package_id in enumerate(package_ids, 1):

            atom = inst_repo.retrieveAtom(package_id)
            pkg = None

            try:
                pkg = action_factory.get(
                    action_factory.CONFIG_ACTION,
                    (package_id, inst_repo.repository_id()))

                xterm_header = "equo (%s) :: %d of %d ::" % (
                    _("configure"), count, len(package_ids))
                pkg.set_xterm_header(xterm_header)

                entropy_client.output(
                    darkgreen(atom),
                    count=(count, len(package_ids)),
                    header=darkred(" ::: ") + ">>> ")

                exit_st = pkg.start()
                if exit_st not in (0, 3):
                    return 1, True

            finally:
                if pkg is not None:
                    pkg.finalize()

        return 0, True
Exemple #14
0
    def _run(self, entropy_client):
        """
        Mask/Unmask code logic.
        """
        found_pkg_atoms = []
        for package in self._packages:
            package_id, repoid = entropy_client.atom_match(package,
                                                           mask_filter=False)

            if package_id == -1:
                mytxt = "!!! %s: %s %s." % (
                    purple(_("Warning")),
                    teal(const_convert_to_unicode(package)),
                    purple(_("is not available")),
                )
                entropy_client.output("!!!", level="warning", importance=1)
                entropy_client.output(mytxt, level="warning", importance=1)
                entropy_client.output("!!!", level="warning", importance=1)
                if len(package) > 3:
                    self._show_did_you_mean(entropy_client,
                                            package,
                                            from_installed=False)
                    entropy_client.output("!!!", level="warning", importance=1)
                continue

            found_pkg_atoms.append(package)

        if not found_pkg_atoms:
            entropy_client.output("%s." % (darkred(_("No packages found")), ),
                                  level="error",
                                  importance=1)
            return 1

        if self._ask or self._pretend:
            mytxt = "%s:" % (blue(
                _("These are the packages that would be handled")), )
            entropy_client.output(mytxt, header=red(" @@ "))

        match_data = {}
        for package in found_pkg_atoms:
            matches, rc = entropy_client.atom_match(package,
                                                    multi_match=True,
                                                    multi_repo=True,
                                                    mask_filter=False)
            match_data[package] = matches

            flags = darkgreen(" [")
            if self._action == "mask":
                flags += brown("M")
            else:
                flags += red("U")
            flags += darkgreen("] ")
            entropy_client.output(darkred(" ##") + flags + purple(package))

            if rc == 0:
                # also show found pkgs
                for package_id, repository_id in matches:
                    repo = entropy_client.open_repository(repository_id)
                    atom = repo.retrieveAtom(package_id)
                    entropy_client.output("    -> " + enlightenatom(atom))

        if self._pretend:
            return 0

        if self._ask:
            answer = entropy_client.ask_question(
                _("Would you like to continue?"))
            if answer == _("No"):
                return 0

        for package, matches in match_data.items():
            for match in matches:
                if self._action == "mask":
                    done = entropy_client.mask_package_generic(match, package)
                else:
                    done = entropy_client.unmask_package_generic(
                        match, package)
                if not done:
                    mytxt = "!!! %s: %s %s." % (
                        purple(_("Warning")),
                        teal(const_convert_to_unicode(package)),
                        purple(_("action not executed")),
                    )
                    entropy_client.output("!!!", level="warning", importance=1)
                    entropy_client.output(mytxt, level="warning", importance=1)
                    entropy_client.output("!!!", level="warning", importance=1)

        entropy_client.output("Have a nice day.")
        return 0