Пример #1
0
    def _on_exit(self, trans, enum):
        """Callback for the exit state of the transaction"""
        # Make sure to dettach the terminal
        self._detach()
        if self._show_progress:
            sys.stderr.write("[+] 100% " + ANSI_BOLD +
                             "%-*.*s" % (self._terminal_width - 9,
                                         self._terminal_width - 9,
                                         enums.get_exit_string_from_enum(enum))+
                             ANSI_RESET + "\n")

        if enum == enums.EXIT_FAILED:
            msg = "%s: %s\n%s\n\n%s" % (
                   _("ERROR"),
                   enums.get_error_string_from_enum(trans.error_code),
                   enums.get_error_description_from_enum(trans.error_code),
                   trans.error_details)
            print msg
        self._loop.quit()
Пример #2
0
    def _show_changes(self):
        def show_packages(pkgs):
            """Format the pkgs in a nice way."""
            line = " "
            pkgs.sort()
            for pkg in pkgs:
                try:
                    name, version = pkg.split("=", 1)[0:2]
                except ValueError:
                    name = pkg
                    version = None
                if self._details and version:
                    output = "%s=%s" % (name, version)
                else:
                    output = name
                if len(line) + 1 + len(output) > self._terminal_width and \
                   line != " ":
                    print line
                    line = " "
                line += " %s" % output
            if line != " ":
                print line
        self._stop_custom_progress()
        self._clear_progress()
        installs, reinstalls, removals, purges, upgrades, downgrades  = \
                self._transaction.packages
        dep_installs, dep_reinstalls, dep_removals, dep_purges, dep_upgrades, \
                dep_downgrades, dep_kepts = self._transaction.dependencies
        installs.extend(dep_installs)
        upgrades.extend(dep_upgrades)
        removals.extend(purges)
        removals.extend(dep_removals)
        removals.extend(dep_purges)
        reinstalls.extend(dep_reinstalls)
        downgrades.extend(dep_downgrades)
        kepts = dep_kepts
        if installs:
            #TRANSLATORS: %s is the number of packages
            print ngettext("The following NEW package will be installed "
                           "(%(count)s):",
                           "The following NEW packages will be installed "
                           "(%(count)s):",
                           len(installs)) % {"count": len(installs)}
            show_packages(installs)
        if upgrades:
            #TRANSLATORS: %s is the number of packages
            print ngettext("The following package will be upgraded "
                           "(%(count)s):",
                           "The following packages will be upgraded "
                           "(%(count)s):",
                           len(upgrades)) % {"count": len(upgrades)}
            show_packages(upgrades)
        if removals:
            #TRANSLATORS: %s is the number of packages
            print ngettext("The following package will be REMOVED "
                           "(%(count)s):",
                           "The following packages will be REMOVED "
                           "(%(count)s):",
                           len(removals)) % {"count": len(removals)}
            #FIXME: mark purges
            show_packages(removals)
        if downgrades:
            #TRANSLATORS: %s is the number of packages
            print ngettext("The following package will be DOWNGRADED "
                           "(%(count)s):",
                           "The following packages will be DOWNGRADED "
                           "(%(count)s):",
                           len(downgrades)) % {"count": len(downgrades)}
            show_packages(downgrades)
        if reinstalls:
            #TRANSLATORS: %s is the number of packages
            print ngettext("The following package will be reinstalled "
                           "(%(count)s):",
                           "The following packages will be reinstalled "
                           "(%(count)s):",
                           len(reinstalls)) % {"count": len(reinstalls)}
            show_packages(reinstalls)
        if kepts:
            print ngettext("The following package has been kept back "
                           "(%(count)s):",
                           "The following packages have been kept back "
                           "(%(count)s):",
                           len(kepts)) % {"count": len(kepts)}
            show_packages(kepts)

        if self._transaction.download:
            print _("Need to get %sB of archives.") % \
                    apt_pkg.size_to_str(self._transaction.download)
        if self._transaction.space > 0:
            print _("After this operation, %sB of additional disk space "
                    "will be used.") % \
                            apt_pkg.size_to_str(self._transaction.space)
        elif self._transaction.space < 0:
            print _("After this operation, %sB of additional disk space "
                    "will be freed.") % \
                            apt_pkg.size_to_str(self._transaction.space)
        if (not apt_pkg.config.find_b("APT::Get::Assume-Yes") and
            (self._transaction.space or self._transaction.download or
             installs or upgrades or downgrades or removals or kepts or
             reinstalls)):
            try:
                cont = raw_input(_("Do you want to continue [Y/n]?"))
            except EOFError:
                cont = "n"
            #FIXME: Listen to changed dependencies!
            if not re.match(locale.nl_langinfo(locale.YESEXPR), cont) and \
               cont != "":
                msg = enums.get_exit_string_from_enum(enums.EXIT_CANCELLED)
                self._update_custom_progress(msg, None, False)
                self._loop.quit()
                sys.exit(1)
        #TRANSLATORS: status message
        self._progress_id = gobject.timeout_add(250,
                                                self._update_custom_progress,
                                                _("Queuing"))
        self._transaction.run(error_handler=self._on_exception,
                           reply_handler=lambda: self._stop_custom_progress())