Ejemplo n.º 1
0
 def upgradeAll(self):
     transaction = Transaction(self._ctrl.getCache())
     transaction.setState(self._changeset)
     for pkg in self._ctrl.getCache().getPackages():
         if pkg.installed:
             transaction.enqueue(pkg, UPGRADE)
     transaction.setPolicy(PolicyUpgrade)
     transaction.run()
     changeset = transaction.getChangeSet()
     if changeset != self._changeset:
         if self.confirmChange(self._changeset, changeset):
             self.saveUndo()
             self._changeset.setState(changeset)
             self.changedMarks()
             if self.askYesNo(_("Apply marked changes now?"), True):
                 self.applyChanges()
     else:
         self.showStatus(_("No interesting upgrades available!"))
Ejemplo n.º 2
0
 def actOnPackages(self, pkgs, op=None):
     cache = self._ctrl.getCache()
     transaction = Transaction(cache, policy=PolicyInstall)
     transaction.setState(self._changeset)
     changeset = transaction.getChangeSet()
     if op is None:
         if not [pkg for pkg in pkgs if pkg not in changeset]:
             op = KEEP
         else:
             for pkg in pkgs:
                 if not pkg.installed:
                     op = INSTALL
                     break
             else:
                 op = REMOVE
     if op is REMOVE:
         transaction.setPolicy(PolicyRemove)
     policy = transaction.getPolicy()
     for pkg in pkgs:
         if op is KEEP:
             transaction.enqueue(pkg, op)
         elif op in (REMOVE, REINSTALL, FIX):
             if pkg.installed:
                 transaction.enqueue(pkg, op)
                 if op is REMOVE:
                     for _pkg in cache.getPackages(pkg.name):
                         if not _pkg.installed:
                             policy.setLocked(_pkg, True)
         elif op is INSTALL:
             if not pkg.installed:
                 transaction.enqueue(pkg, op)
     transaction.run()
     if op is FIX:
         expected = 0
     else:
         expected = 1
     if self.confirmChange(self._changeset, changeset, expected):
         self.saveUndo()
         self._changeset.setState(changeset)
         pkgs.extend(changeset)
         self.changedMarks(pkgs)
Ejemplo n.º 3
0
def main(ctrl, opts, reloadchannels=True):

    if reloadchannels:
        ctrl.reloadChannels()

    cache = ctrl.getCache()
    trans = Transaction(cache, PolicyUpgrade)
    checkstate = None

    for pkg in cache.getPackages():
        if pkg.installed:
            trans.enqueue(pkg, UPGRADE)
            pass
        pass

    trans.run()
    changeset = trans.getChangeSet()
    state = changeset.getPersistentState()
    if not state:
        iface.showStatus(_("No interesting upgrades available."))
        return 2
    elif checkstate:
        for entry in state:
            if checkstate.get(entry) != state[entry]:
                break
            pass
        else:
            iface.showStatus(_("There are pending upgrades!"))
            return 1
        iface.showStatus(_("There are new upgrades available!"))
    elif not trans:
        iface.showStatus(_("No interesting upgrades available."))
        pass
    else:
        iface.hideStatus()
        upgrades = [pkg for (pkg, op) in changeset.items() if op == INSTALL]
        upgrades.sort()
        report = []
        for pkg in upgrades:
            upgraded = []
            for upg in pkg.upgrades:
                for prv in upg.providedby:
                    for prvpkg in prv.packages:
                        if prvpkg.installed:
                            upgraded.append(prvpkg)
                            pass
                        pass
                    pass
                pass

            for loader in pkg.loaders:
                if not loader.getInstalled():
                    break
                else:
                    continue
            info = loader.getInfo(pkg)
            for url in info.getURLs():
                size = info.getSize(url)
            ch = loader.getChannel()

            if len(upgraded) > 0:
                if str.find(upgraded[0].version, '@') != -1 :
                    (uversion, uarch) = upgraded[0].version.split('@')
                else:
                    (uversion, uarch) = (upgraded[0].version, "")
            else:
                uversion = _('(not installed)')
                uarch = ''
                pass
            if str.find(pkg.version, '@') != -1 :
                (iversion, iarch) = pkg.version.split('@')
            else:
                (iversion, iarch) = (pkg.version, "")
            entry = [pkg.name, uversion, uarch, iversion, iarch, ch.getAlias(), size]
            report.append(entry)
            pass

        # TODO: make this use an interface method
        
        report.insert(0, [_('Package Name'), _('Installed'), '', _('Upgrade'), '', _('Channel'), _('Size')])

        maxwidth = [0, 0, 0, 0, 0, 0, 0]
        for entry in report:
            for i in range(len(entry)):
                if entry[i] != None and len(str(entry[i])) > maxwidth[i]:
                    maxwidth[i] = len(str(entry[i]))
                    pass
                pass
            pass

        line = []
        mask = []
        mask.append('%-'+str(maxwidth[0])+'s')
        mask.append('%-'+str(maxwidth[1])+'s %'+str(maxwidth[2])+'s')
        mask.append('%-'+str(maxwidth[3])+'s %'+str(maxwidth[4])+'s')
        mask.append('%-'+str(maxwidth[5])+'s')
        mask.append('%-'+str(maxwidth[6])+'s')
        
        for mw in maxwidth:
            line.append(''.join(['-' for x in range(mw)]))
            pass

        maskline = ' | '.join(mask)

        print maskline % tuple(report[0])
        print '-+-'.join(mask) % tuple(line)
        for entry in report[1:]:
            print maskline % tuple(entry)
Ejemplo n.º 4
0
def main(ctrl, opts):

    if opts.explain:
        sysconf.set("explain-changesets", True, soft=True)

    if opts.update:
        from smart.commands import update
        updateopts = update.parse_options([])
        update.main(ctrl, updateopts)
    else:
        ctrl.reloadChannels()

    cache = ctrl.getCache()
    trans = Transaction(cache, PolicyUpgrade)

    if opts.args:

        for arg in opts.args:

            ratio, results, suggestions = ctrl.search(arg)

            if not results:
                if suggestions:
                    dct = {}
                    for r, obj in suggestions:
                        if isinstance(obj, Package):
                            if obj.installed:
                                dct[obj] = True
                        else:
                            for pkg in obj.packages:
                                if pkg.installed:
                                    dct[pkg] = True
                    if not dct:
                        del suggestions[:]
                if suggestions:
                    raise Error, _("'%s' matches no packages. "
                                   "Suggestions:\n%s") % \
                                 (arg, "\n".join(["    "+str(x) for x in dct]))
                else:
                    raise Error, _("'%s' matches no packages") % arg

            foundany = False
            foundinstalled = False
            for obj in results:
                if isinstance(obj, Package):
                    if obj.installed:
                        trans.enqueue(obj, UPGRADE)
                        foundinstalled = True
                    foundany = True
            if not foundany:
                for obj in results:
                    if not isinstance(obj, Package):
                        for pkg in obj.packages:
                            if pkg.installed:
                                foundinstalled = True
                                trans.enqueue(pkg, UPGRADE)
                            foundany = True
            if not foundinstalled:
                iface.warning(_("'%s' matches no installed packages") % arg)
    else:
        for pkg in cache.getPackages():
            if pkg.installed:
                trans.enqueue(pkg, UPGRADE)

    iface.showStatus(_("Computing transaction..."))
    trans.run()

    if trans and opts.check or opts.check_update:
        checkfile = os.path.expanduser("~/.smart/upgradecheck")
        if os.path.isfile(checkfile):
            file = open(checkfile)
            checkstate = cPickle.load(file)
            file.close()
        else:
            checkstate = None
        changeset = trans.getChangeSet()
        state = changeset.getPersistentState()
        if opts.check_update:
            dirname = os.path.dirname(checkfile)
            if not os.path.isdir(dirname):
                os.makedirs(dirname)
            file = open(checkfile, "w")
            cPickle.dump(state, file, 2)
            file.close()
        if not state:
            iface.showStatus(_("No interesting upgrades available."))
            return 2
        elif checkstate:
            for entry in state:
                if checkstate.get(entry) != state[entry]:
                    break
            else:
                iface.showStatus(_("There are pending upgrades!"))
                return 1
        iface.showStatus(_("There are new upgrades available!"))
    elif not trans:
        iface.showStatus(_("No interesting upgrades available."))
    else:
        iface.hideStatus()
        confirm = not opts.yes
        if opts.urls:
            ctrl.dumpTransactionURLs(trans)
        elif opts.dump:
            ctrl.dumpTransactionPackages(trans, install=True)
        elif opts.download:
            ctrl.downloadTransaction(trans, confirm=confirm)
        elif opts.stepped:
            ctrl.commitTransactionStepped(trans, confirm=confirm)
        else:
            ctrl.commitTransaction(trans, confirm=confirm)
Ejemplo n.º 5
0
def main(ctrl, opts):

    # Argument check
    opts.check_args_of_option("flag", 1)

    if opts.explain:
        sysconf.set("explain-changesets", True, soft=True)

    if opts.update or sysconf.get("auto-update"):
        from smart.commands import update
        updateopts = update.parse_options([])
        update.main(ctrl, updateopts)
    else:
        ctrl.reloadChannels()

    cache = ctrl.getCache()
    trans = Transaction(cache, PolicyUpgrade)

    if opts.args:

        for arg in opts.args:

            op = UPGRADE
            if arg.startswith('+'):
                arg = arg[1:]
                op = INSTALL
            if arg.startswith('-'):
                arg = arg[1:]
                op = REMOVE

            ratio, results, suggestions = ctrl.search(arg)

            if not results:
                if suggestions:
                    dct = {}
                    for r, obj in suggestions:
                        if isinstance(obj, Package):
                            if obj.installed or op == INSTALL:
                                dct[obj] = True
                        else:
                            for pkg in obj.packages:
                                if pkg.installed or op == INSTALL:
                                    dct[pkg] = True
                    if not dct:
                        del suggestions[:]
                if suggestions:
                    raise Error, _("'%s' matches no packages. "
                                   "Suggestions:\n%s") % \
                                 (arg, "\n".join(["    "+str(x) for x in dct]))
                else:
                    raise Error, _("'%s' matches no packages") % arg

            foundany = False
            foundinstalled = False
            for obj in results:
                if isinstance(obj, Package):
                    if (obj.installed or op == INSTALL) and (not opts.flag or pkgconf.testFlag(opts.flag, obj)):
                        trans.enqueue(obj, op)
                        foundinstalled = obj.installed
                    foundany = True
            if not foundany:
                for obj in results:
                    if not isinstance(obj, Package):
                        for pkg in obj.packages:
                            if (pkg.installed or op == INSTALL) and (not opts.flag or pkgconf.testFlag(opts.flag, pkg)):
                                foundinstalled = pkg.installed
                                trans.enqueue(pkg, op)
                            foundany = True
            if not foundinstalled and op != INSTALL:
                iface.warning(_("'%s' matches no installed packages") % arg)
    else:
        for pkg in cache.getPackages():
            if pkg.installed and (not opts.flag or pkgconf.testFlag(opts.flag, pkg)):
                trans.enqueue(pkg, UPGRADE)

    iface.showStatus(_("Computing transaction..."))
    trans.run()

    if trans and opts.check or opts.check_update:
        checkfile = os.path.expanduser("~/.smart/upgradecheck")
        if os.path.isfile(checkfile):
            file = open(checkfile)
            checkstate = cPickle.load(file)
            file.close()
        else:
            checkstate = None
        changeset = trans.getChangeSet()
        state = changeset.getPersistentState()
        if opts.check_update:
            dirname = os.path.dirname(checkfile)
            if not os.path.isdir(dirname):
                os.makedirs(dirname)
            file = open(checkfile, "w")
            cPickle.dump(state, file, 2)
            file.close()
        if not state:
            iface.showStatus(_("No interesting upgrades available."))
            return 2
        elif checkstate:
            for entry in state:
                if checkstate.get(entry) != state[entry]:
                    break
            else:
                iface.showStatus(_("There are pending upgrades!"))
                return 1
        iface.showStatus(_("There are new upgrades available!"))
    elif not trans:
        iface.showStatus(_("No interesting upgrades available."))
    else:
        iface.hideStatus()
        confirm = not opts.yes
        if opts.urls:
            ctrl.dumpTransactionURLs(trans)
        elif opts.metalink:
            ctrl.dumpTransactionMetalink(trans)
        elif opts.dump:
            ctrl.dumpTransactionPackages(trans, install=True)
        elif opts.download:
            ctrl.downloadTransaction(trans, confirm=confirm)
        elif opts.stepped:
            ctrl.commitTransactionStepped(trans, confirm=confirm)
        else:
            ctrl.commitTransaction(trans, confirm=confirm)
Ejemplo n.º 6
0
def main(ctrl, opts):

    ctrl.reloadChannels()
    cache = ctrl.getCache()
    trans = Transaction(cache, PolicyUpgrade)

    if opts.args:

        for arg in opts.args:

            ratio, results, suggestions = ctrl.search(arg)

            if not results:
                if suggestions:
                    dct = {}
                    for r, obj in suggestions:
                        if isinstance(obj, Package):
                            if obj.installed:
                                dct[obj] = True
                        else:
                            for pkg in obj.packages:
                                if pkg.installed:
                                    dct[pkg] = True
                    if not dct:
                        del suggestions[:]
                if suggestions:
                    raise Error, _("'%s' matches no packages. "
                                   "Suggestions:\n%s") % \
                                 (arg, "\n".join(["    "+str(x) for x in dct]))
                else:
                    raise Error, _("'%s' matches no packages") % arg

            foundany = False
            foundinstalled = False
            for obj in results:
                if isinstance(obj, Package):
                    if obj.installed:
                        trans.enqueue(obj, UPGRADE)
                        foundinstalled = True
                    foundany = True
            if not foundany:
                for obj in results:
                    if not isinstance(obj, Packages):
                        for pkg in obj.packages:
                            if pkg.installed:
                                foundinstalled = True
                                trans.enqueue(obj, UPGRADE)
                            foundany = True
            if not foundinstalled:
                iface.warning(_("'%s' matches no installed packages") % arg)
    else:
        for pkg in cache.getPackages():
            if pkg.installed:
                trans.enqueue(pkg, UPGRADE)

    iface.showStatus(_("Computing transaction..."))
    trans.run()

    if trans and opts.check or opts.check_update:
        checkfile = os.path.expanduser("~/.smart/upgradecheck")
        if os.path.isfile(checkfile):
            file = open(checkfile)
            checkstate = cPickle.load(file)
            file.close()
        else:
            checkstate = None
        changeset = trans.getChangeSet()
        state = changeset.getPersistentState()
        if opts.check_update:
            dirname = os.path.dirname(checkfile)
            if not os.path.isdir(dirname):
                os.makedirs(dirname)
            file = open(checkfile, "w")
            cPickle.dump(state, file, 2)
            file.close()
        if not state:
            iface.showStatus(_("No interesting upgrades available."))
            return 2
        elif checkstate:
            for entry in state:
                if checkstate.get(entry) != state[entry]:
                    break
            else:
                iface.showStatus(_("There are pending upgrades!"))
                return 1
        iface.showStatus(_("There are new upgrades available!"))
    elif not trans:
        iface.showStatus(_("No interesting upgrades available."))
    else:
        iface.hideStatus()
        confirm = not opts.yes
        if opts.urls:
            ctrl.dumpTransactionURLs(trans)
        elif opts.download:
            ctrl.downloadTransaction(trans, confirm=confirm)
        elif opts.stepped:
            ctrl.commitTransactionStepped(trans, confirm=confirm)
        else:
            ctrl.commitTransaction(trans, confirm=confirm)