Пример #1
0
 def __init__(self, ctrl):
     Interface.__init__(self, ctrl)
     self._progress = TextProgress()
     self._activestatus = False
Пример #2
0
class TextInterface(Interface):

    def __init__(self, ctrl):
        Interface.__init__(self, ctrl)
        self._progress = TextProgress()
        self._activestatus = False

    def getProgress(self, obj, hassub=False):
        self._progress.setHasSub(hassub)
        self._progress.setFetcherMode(isinstance(obj, Fetcher))
        return self._progress

    def getSubProgress(self, obj):
        return self._progress

    def showStatus(self, msg):
        if self._activestatus:
            print
        else:
            self._activestatus = True
        sys.stdout.write(msg)
        sys.stdout.flush()

    def hideStatus(self):
        if self._activestatus:
            self._activestatus = False
            print

    def askYesNo(self, question, default=False):
        self.hideStatus()
        mask = default and _("%s (Y/n): ") or _("%s (y/N): ")
        try:
            res = raw_input(mask % question).strip().lower()
        except (KeyboardInterrupt, EOFError):
            print
            return False
        print
        if res:
            return (_("yes").startswith(res) and not
                    _("no").startswith(res))
        return default

    def askContCancel(self, question, default=False):
        self.hideStatus()
        if default:
            mask = _("%s (Continue/cancel): ")
        else:
            mask = _("%s (continue/Cancel): ")
        try:
            res = raw_input(mask % question).strip().lower()
        except (KeyboardInterrupt, EOFError):
            print
            return False
        print
        if res:
            return (_("continue").startswith(res) and not
                    _("cancel").startswith(res))
        return default

    def askOkCancel(self, question, default=False):
        self.hideStatus()
        mask = default and _("%s (Ok/cancel): ") or _("%s (ok/Cancel): ")
        try:
            res = raw_input(mask % question).strip().lower()
        except (KeyboardInterrupt, EOFError):
            print
            return False
        print
        if res:
            return (_("ok").startswith(res) and not
                    _("cancel").startswith(res))
        return default

    def confirmChangeSet(self, changeset):
        return self.showChangeSet(changeset, confirm=True)

    def askInput(self, prompt, message=None, widthchars=None, echo=True):
        print
        if message:
            print message
        prompt += ": "
        try:
            if echo:
                res = raw_input(prompt)
            else:
                res = getpass.getpass(prompt)
        except (KeyboardInterrupt, EOFError):
            res = ""
        print
        return res

    def askPassword(self, location, caching=OPTIONAL):
        self._progress.lock()
        passwd = Interface.askPassword(self, location, caching)
        self._progress.unlock()
        return passwd

    def insertRemovableChannels(self, channels):
        self.hideStatus()
        print
        print _("Insert one or more of the following removable channels:")
        print
        for channel in channels:
            print "   ", str(channel)
        print
        return self.askOkCancel(_("Continue?"), True)

    # Non-standard interface methods:
        
    def showChangeSet(self, changeset, keep=None, confirm=False):
        self.hideStatus()
        report = Report(changeset)
        report.compute()


        if not sysconf.get("explain-changesets", False):
            screenwidth = getScreenWidth()
            hideversion = sysconf.get("text-hide-version", len(changeset) > 40)
            def showPackages(pkgs, showrelations=None):
                if hideversion:
                    pkgs = [x.name for x in pkgs]
                pkgs.sort()
                printColumns(pkgs, indent=2, width=screenwidth)
        else:
            def being(pkg):
                if (pkg in report.installing or
                    pkg in report.upgrading or
                    pkg in report.downgrading):
                    return _("(installed)")
                elif pkg in report.upgraded:
                    return _("(upgraded)")
                elif pkg in report.removed:
                    return _("(removed)")
                elif pkg in report.downgraded:
                    return _("(downgraded)")
                else:
                    return "" # Shouldn't happen
            def showPackages(pkgs, showrelations=True):
                pkgs.sort()
                for pkg in pkgs:
                    channels = []
                    for loader in pkg.loaders:
                        channels.append(loader.getChannel().getAlias())
                        channels.sort()
                    print " ", pkg, ("[%s]" % ", ".join(channels))
                    if showrelations:
                        if pkg in report.upgrading:
                            print "   ", _("Upgrades:")
                            for upgpkg in report.upgrading[pkg]:
                                print "     ", upgpkg, being(upgpkg)
                        if pkg in report.downgrading:
                            print "   ", _("Downgrades:")
                            for dwnpkg in report.downgrading[pkg]:
                                print "     ", dwnpkg, being(dwnpkg)
                        if pkg in report.requires:
                            print "   ", _("Requires:")
                            for reqpkg in report.requires[pkg]:
                                print "     ", reqpkg, being(reqpkg)
                        if pkg in report.requiredby:
                            print "   ", _("Required By:")
                            for reqpkg in report.requiredby[pkg]:
                                print "     ", reqpkg, being(reqpkg)
                        if pkg in report.conflicts:
                            print "   ", _("Conflicts:")
                            for cnfpkg in report.conflicts[pkg]:
                                print "     ", cnfpkg, being(cnfpkg)

        print
        if keep:
            print _("Kept packages (%d):") % len(keep)
            showPackages(keep, False)
            print
        pkgs = report.upgrading.keys()
        if pkgs:
            print _("Upgrading packages (%d):") % len(pkgs)
            showPackages(pkgs)
            print
        pkgs = report.downgrading.keys()
        if pkgs:
            print _("Downgrading packages (%d):") % len(pkgs)
            showPackages(pkgs)
            print
        pkgs = report.installing.keys()
        if pkgs:
            print _("Installing packages (%d):") % len(pkgs)
            showPackages(pkgs)
            print
        pkgs = report.removed.keys()
        if pkgs:
            print _("Removing packages (%d):") % len(pkgs)
            showPackages(pkgs)
            print

        dsize = report.getDownloadSize() - report.getCachedSize()
        size = report.getInstallSize() - report.getRemoveSize()
        if dsize:
            sys.stdout.write(_("%s of package files are needed. ") %
                             sizeToStr(dsize))
        if size > 0:
            sys.stdout.write(_("%s will be used.") % sizeToStr(size))
        elif size < 0:
            size *= -1
            sys.stdout.write(_("%s will be freed.") % sizeToStr(size))
        if dsize or size:
            sys.stdout.write("\n\n")
        if confirm:
            return self.askYesNo(_("Confirm changes?"), True)
        return True
Пример #3
0
class TextInterface(Interface):

    def __init__(self, ctrl):
        Interface.__init__(self, ctrl)
        self._progress = TextProgress()
        self._activestatus = False

    def getProgress(self, obj, hassub=False):
        self._progress.setHasSub(hassub)
        self._progress.setFetcherMode(isinstance(obj, Fetcher))
        return self._progress

    def getSubProgress(self, obj):
        return self._progress

    def showStatus(self, msg):
        if self._activestatus:
            print
        else:
            self._activestatus = True
        sys.stdout.write(msg)
        sys.stdout.flush()

    def hideStatus(self):
        if self._activestatus:
            self._activestatus = False
            print

    def askYesNo(self, question, default=False):
        self.hideStatus()
        mask = default and _("%s (Y/n): ") or _("%s (y/N): ")
        res = raw_input(mask % question).strip().lower()
        print
        if res:
            return (_("yes").startswith(res) and not
                    _("no").startswith(res))
        return default

    def askContCancel(self, question, default=False):
        self.hideStatus()
        if default:
            mask = _("%s (Continue/cancel): ")
        else:
            mask = _("%s (continue/Cancel): ")
        res = raw_input(mask % question).strip().lower()
        print
        if res:
            return (_("continue").startswith(res) and not
                    _("cancel").startswith(res))
        return default

    def askOkCancel(self, question, default=False):
        self.hideStatus()
        mask = default and _("%s (Ok/cancel): ") or _("%s (ok/Cancel): ")
        res = raw_input(mask % question).strip().lower()
        print
        if res:
            return (_("ok").startswith(res) and not
                    _("cancel").startswith(res))
        return default

    def confirmChangeSet(self, changeset):
        return self.showChangeSet(changeset, confirm=True)

    def askInput(self, prompt, message=None, widthchars=None, echo=True):
        print
        if message:
            print message
        prompt += ": "
        try:
            if echo:
                res = raw_input(prompt)
            else:
                res = getpass.getpass(prompt)
        except KeyboardInterrupt:
            res = ""
        print
        return res

    def askPassword(self, location, caching=OPTIONAL):
        self._progress.lock()
        passwd = Interface.askPassword(self, location, caching)
        self._progress.unlock()
        return passwd

    def insertRemovableChannels(self, channels):
        self.hideStatus()
        print
        print _("Insert one or more of the following removable channels:")
        print
        for channel in channels:
            print "   ", str(channel)
        print
        return self.askOkCancel(_("Continue?"), True)

    # Non-standard interface methods:

    def showChangeSet(self, changeset, keep=None, confirm=False):
        self.hideStatus()
        report = Report(changeset)
        report.compute()

        screenwidth = getScreenWidth()

        hideversion = sysconf.get("text-hide-version", len(changeset) > 40)
        if hideversion:
            def cvt(lst):
                return [x.name for x in lst]
        else:
            def cvt(lst):
                return lst

        print
        if keep:
            keep = cvt(keep)
            keep.sort()
            print _("Kept packages (%d):") % len(keep)
            printColumns(keep, indent=2, width=screenwidth)
            print
        pkgs = report.upgrading.keys()
        if pkgs:
            pkgs = cvt(pkgs)
            pkgs.sort()
            print _("Upgrading packages (%d):") % len(pkgs)
            printColumns(pkgs, indent=2, width=screenwidth)
            print
        pkgs = report.downgrading.keys()
        if pkgs:
            pkgs = cvt(pkgs)
            pkgs.sort()
            print _("Downgrading packages (%d):") % len(pkgs)
            printColumns(pkgs, indent=2, width=screenwidth)
            print
        pkgs = report.installing.keys()
        if pkgs:
            pkgs = cvt(pkgs)
            pkgs.sort()
            print _("Installed packages (%d):") % len(pkgs)
            printColumns(pkgs, indent=2, width=screenwidth)
            print
        pkgs = report.removed.keys()
        if pkgs:
            pkgs = cvt(pkgs)
            pkgs.sort()
            print _("Removed packages (%d):") % len(pkgs)
            printColumns(pkgs, indent=2, width=screenwidth)
            print
        dsize = report.getDownloadSize()
        size = report.getInstallSize() - report.getRemoveSize()
        if dsize:
            sys.stdout.write(_("%s of package files are needed. ") %
                             sizeToStr(dsize))
        if size > 0:
            sys.stdout.write(_("%s will be used.") % sizeToStr(size))
        elif size < 0:
            size *= -1
            sys.stdout.write(_("%s will be freed.") % sizeToStr(size))
        if dsize or size:
            sys.stdout.write("\n\n")
        if confirm:
            return self.askYesNo(_("Confirm changes?"), True)
        return True
Пример #4
0
 def __init__(self, ctrl):
     Interface.__init__(self, ctrl)
     self._progress = TextProgress()
     self._activestatus = False
Пример #5
0
class TextInterface(Interface):
    def __init__(self, ctrl):
        Interface.__init__(self, ctrl)
        self._progress = TextProgress()
        self._activestatus = False

    def getProgress(self, obj, hassub=False):
        self._progress.setHasSub(hassub)
        self._progress.setFetcherMode(isinstance(obj, Fetcher))
        return self._progress

    def getSubProgress(self, obj):
        return self._progress

    def showStatus(self, msg):
        if self._activestatus:
            print
        else:
            self._activestatus = True
        sys.stdout.write(msg)
        sys.stdout.flush()

    def hideStatus(self):
        if self._activestatus:
            self._activestatus = False
            print

    def askYesNo(self, question, default=False):
        self.hideStatus()
        mask = default and _("%s (Y/n): ") or _("%s (y/N): ")
        res = raw_input(mask % question).strip().lower()
        print
        if res:
            return (_("yes").startswith(res) and not _("no").startswith(res))
        return default

    def askContCancel(self, question, default=False):
        self.hideStatus()
        if default:
            mask = _("%s (Continue/cancel): ")
        else:
            mask = _("%s (continue/Cancel): ")
        res = raw_input(mask % question).strip().lower()
        print
        if res:
            return (_("continue").startswith(res)
                    and not _("cancel").startswith(res))
        return default

    def askOkCancel(self, question, default=False):
        self.hideStatus()
        mask = default and _("%s (Ok/cancel): ") or _("%s (ok/Cancel): ")
        res = raw_input(mask % question).strip().lower()
        print
        if res:
            return (_("ok").startswith(res)
                    and not _("cancel").startswith(res))
        return default

    def confirmChangeSet(self, changeset):
        return self.showChangeSet(changeset, confirm=True)

    def askInput(self, prompt, message=None, widthchars=None, echo=True):
        print
        if message:
            print message
        prompt += ": "
        try:
            if echo:
                res = raw_input(prompt)
            else:
                res = getpass.getpass(prompt)
        except KeyboardInterrupt:
            res = ""
        print
        return res

    def askPassword(self, location, caching=OPTIONAL):
        self._progress.lock()
        passwd = Interface.askPassword(self, location, caching)
        self._progress.unlock()
        return passwd

    def insertRemovableChannels(self, channels):
        self.hideStatus()
        print
        print _("Insert one or more of the following removable channels:")
        print
        for channel in channels:
            print "   ", str(channel)
        print
        return self.askOkCancel(_("Continue?"), True)

    # Non-standard interface methods:

    def showChangeSet(self, changeset, keep=None, confirm=False):
        self.hideStatus()
        report = Report(changeset)
        report.compute()

        screenwidth = getScreenWidth()

        hideversion = sysconf.get("text-hide-version", len(changeset) > 40)
        if hideversion:

            def cvt(lst):
                return [x.name for x in lst]
        else:

            def cvt(lst):
                return lst

        print
        if keep:
            keep = cvt(keep)
            keep.sort()
            print _("Kept packages (%d):") % len(keep)
            printColumns(keep, indent=2, width=screenwidth)
            print
        pkgs = report.upgrading.keys()
        if pkgs:
            pkgs = cvt(pkgs)
            pkgs.sort()
            print _("Upgrading packages (%d):") % len(pkgs)
            printColumns(pkgs, indent=2, width=screenwidth)
            print
        pkgs = report.downgrading.keys()
        if pkgs:
            pkgs = cvt(pkgs)
            pkgs.sort()
            print _("Downgrading packages (%d):") % len(pkgs)
            printColumns(pkgs, indent=2, width=screenwidth)
            print
        pkgs = report.installing.keys()
        if pkgs:
            pkgs = cvt(pkgs)
            pkgs.sort()
            print _("Installed packages (%d):") % len(pkgs)
            printColumns(pkgs, indent=2, width=screenwidth)
            print
        pkgs = report.removed.keys()
        if pkgs:
            pkgs = cvt(pkgs)
            pkgs.sort()
            print _("Removed packages (%d):") % len(pkgs)
            printColumns(pkgs, indent=2, width=screenwidth)
            print
        dsize = report.getDownloadSize()
        size = report.getInstallSize() - report.getRemoveSize()
        if dsize:
            sys.stdout.write(
                _("%s of package files are needed. ") % sizeToStr(dsize))
        if size > 0:
            sys.stdout.write(_("%s will be used.") % sizeToStr(size))
        elif size < 0:
            size *= -1
            sys.stdout.write(_("%s will be freed.") % sizeToStr(size))
        if dsize or size:
            sys.stdout.write("\n\n")
        if confirm:
            return self.askYesNo(_("Confirm changes?"), True)
        return True
Пример #6
0
class TextInterface(Interface):
    def __init__(self, ctrl):
        Interface.__init__(self, ctrl)
        self._progress = TextProgress()
        self._activestatus = False

    def getProgress(self, obj, hassub=False):
        self._progress.setHasSub(hassub)
        self._progress.setFetcherMode(isinstance(obj, Fetcher))
        return self._progress

    def getSubProgress(self, obj):
        return self._progress

    def showStatus(self, msg):
        if self._activestatus:
            print
        else:
            self._activestatus = True
        sys.stdout.write(msg)
        sys.stdout.flush()

    def hideStatus(self):
        if self._activestatus:
            self._activestatus = False
            print

    def askYesNo(self, question, default=False):
        self.hideStatus()
        mask = default and _("%s (Y/n): ") or _("%s (y/N): ")
        try:
            res = raw_input(mask % question).strip().lower()
        except (KeyboardInterrupt, EOFError):
            print
            return False
        print
        if res:
            return (_("yes").startswith(res) and not _("no").startswith(res))
        return default

    def askContCancel(self, question, default=False):
        self.hideStatus()
        if default:
            mask = _("%s (Continue/cancel): ")
        else:
            mask = _("%s (continue/Cancel): ")
        try:
            res = raw_input(mask % question).strip().lower()
        except (KeyboardInterrupt, EOFError):
            print
            return False
        print
        if res:
            return (_("continue").startswith(res)
                    and not _("cancel").startswith(res))
        return default

    def askOkCancel(self, question, default=False):
        self.hideStatus()
        mask = default and _("%s (Ok/cancel): ") or _("%s (ok/Cancel): ")
        try:
            res = raw_input(mask % question).strip().lower()
        except (KeyboardInterrupt, EOFError):
            print
            return False
        print
        if res:
            return (_("ok").startswith(res)
                    and not _("cancel").startswith(res))
        return default

    def confirmChangeSet(self, changeset):
        return self.showChangeSet(changeset, confirm=True)

    def askInput(self, prompt, message=None, widthchars=None, echo=True):
        print
        if message:
            print message
        prompt += ": "
        try:
            if echo:
                res = raw_input(prompt)
            else:
                res = getpass.getpass(prompt)
        except (KeyboardInterrupt, EOFError):
            res = ""
        print
        return res

    def askPassword(self, location, caching=OPTIONAL):
        self._progress.lock()
        passwd = Interface.askPassword(self, location, caching)
        self._progress.unlock()
        return passwd

    def insertRemovableChannels(self, channels):
        self.hideStatus()
        print
        print _("Insert one or more of the following removable channels:")
        print
        for channel in channels:
            print "   ", str(channel)
        print
        return self.askOkCancel(_("Continue?"), True)

    # Non-standard interface methods:

    def showChangeSet(self, changeset, keep=None, confirm=False):
        self.hideStatus()
        report = Report(changeset)
        report.compute()

        if not sysconf.get("explain-changesets", False):
            screenwidth = getScreenWidth()
            hideversion = sysconf.get("text-hide-version", len(changeset) > 40)

            def showPackages(pkgs, showrelations=None):
                if hideversion:
                    pkgs = [x.name for x in pkgs]
                pkgs.sort()
                printColumns(pkgs, indent=2, width=screenwidth)
        else:

            def being(pkg):
                if (pkg in report.installing or pkg in report.upgrading
                        or pkg in report.downgrading):
                    return _("(installed)")
                elif pkg in report.upgraded:
                    return _("(upgraded)")
                elif pkg in report.removed:
                    return _("(removed)")
                elif pkg in report.downgraded:
                    return _("(downgraded)")
                else:
                    return ""  # Shouldn't happen

            def showPackages(pkgs, showrelations=True):
                pkgs.sort()
                for pkg in pkgs:
                    channels = []
                    for loader in pkg.loaders:
                        channels.append(loader.getChannel().getAlias())
                        channels.sort()
                    print " ", pkg, ("[%s]" % ", ".join(channels))
                    if showrelations:
                        if pkg in report.upgrading:
                            print "   ", _("Upgrades:")
                            for upgpkg in report.upgrading[pkg]:
                                print "     ", upgpkg, being(upgpkg)
                        if pkg in report.downgrading:
                            print "   ", _("Downgrades:")
                            for dwnpkg in report.downgrading[pkg]:
                                print "     ", dwnpkg, being(dwnpkg)
                        if pkg in report.requires:
                            print "   ", _("Requires:")
                            for reqpkg in report.requires[pkg]:
                                print "     ", reqpkg, being(reqpkg)
                        if pkg in report.requiredby:
                            print "   ", _("Required By:")
                            for reqpkg in report.requiredby[pkg]:
                                print "     ", reqpkg, being(reqpkg)
                        if pkg in report.conflicts:
                            print "   ", _("Conflicts:")
                            for cnfpkg in report.conflicts[pkg]:
                                print "     ", cnfpkg, being(cnfpkg)

        print
        if keep:
            print _("Kept packages (%d):") % len(keep)
            showPackages(keep, False)
            print
        pkgs = report.upgrading.keys()
        if pkgs:
            print _("Upgrading packages (%d):") % len(pkgs)
            showPackages(pkgs)
            print
        pkgs = report.downgrading.keys()
        if pkgs:
            print _("Downgrading packages (%d):") % len(pkgs)
            showPackages(pkgs)
            print
        pkgs = report.installing.keys()
        if pkgs:
            print _("Installing packages (%d):") % len(pkgs)
            showPackages(pkgs)
            print
        pkgs = report.removed.keys()
        if pkgs:
            print _("Removing packages (%d):") % len(pkgs)
            showPackages(pkgs)
            print

        dsize = report.getDownloadSize() - report.getCachedSize()
        size = report.getInstallSize() - report.getRemoveSize()
        if dsize:
            sys.stdout.write(
                _("%s of package files are needed. ") % sizeToStr(dsize))
        if size > 0:
            sys.stdout.write(_("%s will be used.") % sizeToStr(size))
        elif size < 0:
            size *= -1
            sys.stdout.write(_("%s will be freed.") % sizeToStr(size))
        if dsize or size:
            sys.stdout.write("\n\n")
        if confirm:
            return self.askYesNo(_("Confirm changes?"), True)
        return True