コード例 #1
0
ファイル: fix.py プロジェクト: nikhilgv9/winlibrepacman
def main(ctrl, opts):

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

    ctrl.reloadChannels()
    cache = ctrl.getCache()
    trans = Transaction(cache, PolicyInstall)
    if opts.args:
        pkgs = {}
        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):
                            dct[obj] = True
                        else:
                            dct.update(dict.fromkeys(obj.packages, True))
                    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

            dct = {}
            for obj in results:
                if isinstance(obj, Package):
                    dct[obj] = True
                else:
                    dct.update(dict.fromkeys(obj.packages, True))
            pkgs.update(dct)
        pkgs = pkgs.keys()
    else:
        pkgs = cache.getPackages()
    for pkg in pkgs:
        trans.enqueue(pkg, FIX)
    iface.showStatus(_("Computing transaction..."))
    trans.run()
    if not trans:
        iface.showStatus(_("No problems to resolve!"))
    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)
コード例 #2
0
ファイル: interactive.py プロジェクト: NehaRawat/spacewalk
 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!"))
コード例 #3
0
 def applyChanges(self, confirm=True):
     transaction = Transaction(self._ctrl.getCache(),
                               changeset=self._changeset)
     if self._ctrl.commitTransaction(transaction, confirm=confirm):
         del self._undo[:]
         del self._redo[:]
         self._redomenuitem.set_property("sensitive", False)
         self._undomenuitem.set_property("sensitive", False)
         self._changeset.clear()
         self._ctrl.reloadChannels()
         self.refreshPackages()
         self.changedMarks()
     self._progress.hide()
コード例 #4
0
 def applyChanges(self, confirm=True):
     transaction = Transaction(self._ctrl.getCache(),
                               changeset=self._changeset)
     if self._ctrl.commitTransaction(transaction, confirm=confirm):
         del self._undo[:]
         del self._redo[:]
         self._actions["redo"].setEnabled(False)
         self._actions["undo"].setEnabled(False)
         self._changeset.clear()
         self._ctrl.reloadChannels()
         self.refreshPackages()
         self.changedMarks()
     self._progress.hide()
コード例 #5
0
ファイル: fix.py プロジェクト: pombredanne/spacewalk
def main(ctrl, opts):

    ctrl.reloadChannels()
    cache = ctrl.getCache()
    trans = Transaction(cache, PolicyInstall)
    if opts.args:
        pkgs = {}
        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):
                            dct[obj] = True
                        else:
                            dct.update(dict.fromkeys(obj.packages, True))
                    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

            dct = {}
            for obj in results:
                if isinstance(obj, Package):
                    dct[obj] = True
                else:
                    dct.update(dict.fromkeys(obj.packages, True))
            pkgs.update(dct)
        pkgs = pkgs.keys()
    else:
        pkgs = cache.getPackages()
    for pkg in pkgs:
        trans.enqueue(pkg, FIX)
    iface.showStatus(_("Computing transaction..."))
    trans.run()
    if not trans:
        iface.showStatus(_("No problems to resolve!"))
    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)
コード例 #6
0
ファイル: install.py プロジェクト: lufengwei2010/AG35
def main(ctrl, opts):

    # Argument check
    if not opts.args:
        raise Error, _("no package(s) given")

    if opts.attempt:
        sysconf.set("attempt-install", True, soft=True)

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

    urls = []
    for arg in opts.args[:]:
        if (os.path.isfile(arg) and '/' in arg or ctrl.checkPackageFile(arg)):
            ctrl.addFileChannel(arg)
            opts.args.remove(arg)
        elif ":/" in arg:
            urls.append(arg)
    if urls:
        succ, fail = ctrl.downloadURLs(urls,
                                       _("packages"),
                                       targetdir=os.getcwd())
        if fail:
            raise Error, _("Failed to download packages:\n") + \
                         "\n".join(["    %s: %s" % (url, fail[url])
                                    for url in fail])
        for url, file in succ.items():
            ctrl.addFileChannel(file)
            opts.args.remove(url)
    if 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, PolicyInstall)
    for channel in ctrl.getFileChannels():
        for loader in channel.getLoaders():
            for pkg in loader.getPackages():
                if pkg.installed:
                    raise Error, _("%s is already installed") % pkg
                trans.enqueue(pkg, INSTALL)

    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):
                        dct[obj] = True
                    else:
                        dct.update(dict.fromkeys(obj.packages, True))
                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

        pkgs = []

        for obj in results:
            if isinstance(obj, Package):
                pkgs.append(obj)

        if not pkgs:
            installed = False
            names = {}
            for obj in results:
                for pkg in obj.packages:
                    if pkg.installed:
                        iface.info(
                            _("%s (for %s) is already installed") % (pkg, arg))
                        installed = True
                        break
                    else:
                        pkgs.append(pkg)
                        names[pkg.name] = True
                else:
                    continue
                break
            if installed:
                continue
            if len(names) == 2 and sysconf.get("rpm-strict-multilib"):
                from smart.backends.rpm.rpmver import splitarch
                # two packages with the same version but different arch, pick best
                if splitarch(pkgs[0].version)[0] == splitarch(
                        pkgs[1].version)[0]:
                    pkg = max(pkgs[0], pkgs[1])
                    names.pop(pkg.name)
                    pkgs.remove(pkg)
            if len(names) > 1:
                raise Error, _("There are multiple matches for '%s':\n%s") % \
                              (arg, "\n".join(["    "+str(x) for x in pkgs]))

        if len(pkgs) > 1:
            sortUpgrades(pkgs)

        names = {}
        for pkg in pkgs:
            names.setdefault(pkg.name, []).append(pkg)
        for name in names:
            pkg = names[name][0]
            if pkg.installed:
                iface.info(_("%s is already installed") % pkg)
            else:
                trans.enqueue(pkg, INSTALL)

    iface.showStatus(_("Computing transaction..."))
    trans.run()
    iface.hideStatus()
    if trans:
        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)
コード例 #7
0
ファイル: upgrade.py プロジェクト: nikhilgv9/winlibrepacman
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)
コード例 #8
0
def main(ctrl, opts):

    ctrl.reloadChannels()
    cache = ctrl.getCache()
    trans = Transaction(cache, PolicyRemove)
    policy = trans.getPolicy()
    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

        pkgs = []

        for obj in results:
            if isinstance(obj, Package):
                pkgs.append(obj)

        if not pkgs:
            for obj in results:
                for pkg in obj.packages:
                    pkgs.append(pkg)

        found = False
        for pkg in pkgs:
            if pkg.installed:
                found = True
                trans.enqueue(pkg, REMOVE)
            else:
                policy.setLocked(pkg, True)
        if not found:
            iface.warning(_("'%s' matches no installed packages") % arg)

    iface.showStatus(_("Computing transaction..."))
    trans.run()
    iface.hideStatus()
    if trans:
        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)
コード例 #9
0
ファイル: newer.py プロジェクト: lufengwei2010/AG35
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)
コード例 #10
0
ファイル: interactive.py プロジェクト: diegocrzt/smart
 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)
         self.changedMarks(pkgs)
コード例 #11
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)
コード例 #12
0
def main(ctrl, opts):

    # Argument check
    if not opts.args:
        raise Error, _("no package(s) given")

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

    if 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, PolicyInstall)
    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

        pkgs = []

        for obj in results:
            if isinstance(obj, Package):
                pkgs.append(obj)

        if not pkgs:
            for obj in results:
                for pkg in obj.packages:
                    pkgs.append(pkg)

        found = False
        for pkg in pkgs:
            if pkg.installed:
                found = True
                trans.enqueue(pkg, REINSTALL)
                for loader in pkg.loaders:
                    if not loader.getInstalled():
                        break
                else:
                    raise Error, _("'%s' is not available for "
                                   "reinstallation") % pkg
        if not found:
            iface.warning(_("'%s' matches no installed packages") % arg)

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

    if trans:
        confirm = not opts.yes
        if opts.urls:
            ctrl.dumpTransactionURLs(trans)
        elif opts.metalink:
            ctrl.dumpTransactionMetalink(trans)
        elif opts.download:
            ctrl.downloadTransaction(trans, confirm=confirm)
        elif opts.stepped:
            ctrl.commitTransactionStepped(trans, confirm=confirm)
        else:
            ctrl.commitTransaction(trans, confirm=confirm)
コード例 #13
0
ファイル: upgrade.py プロジェクト: pombredanne/spacewalk
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)
コード例 #14
0
ファイル: reinstall.py プロジェクト: nikhilgv9/winlibrepacman
def main(ctrl, opts):
    
    if opts.explain:
        sysconf.set("explain-changesets", True, soft=True)

    ctrl.reloadChannels()
    cache = ctrl.getCache()
    trans = Transaction(cache, PolicyInstall)
    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

        pkgs = []

        for obj in results:
            if isinstance(obj, Package):
                pkgs.append(obj)

        if not pkgs:
            for obj in results:
                for pkg in obj.packages:
                    pkgs.append(pkg)

        found = False
        for pkg in pkgs:
            if pkg.installed:
                found = True
                trans.enqueue(pkg, REINSTALL)
                for loader in pkg.loaders:
                    if not loader.getInstalled():
                        break
                else:
                    raise Error, _("'%s' is not available for "
                                   "reinstallation") % pkg
        if not found:
            iface.warning(_("'%s' matches no installed packages") % arg)

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

    if trans:
        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)
コード例 #15
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()
             emptychangeset = not self._changeset
             self._changeset.setState(changeset)
             self.changedMarks()
             if self.askYesNo(_("Apply marked changes now?"), True):
                 self.applyChanges(confirm=not emptychangeset)
     else:
         self.showStatus(_("No interesting upgrades available!"))
コード例 #16
0
ファイル: install.py プロジェクト: pombredanne/spacewalk
def main(ctrl, opts, policy=None):

    if not policy:
        policy = PolicyInstall

    urls = []
    for arg in opts.args[:]:
        if (os.path.isfile(arg) and '/' in arg
                or filter(None, hooks.call("check-package-file", arg))):
            ctrl.addFileChannel(arg)
            opts.args.remove(arg)
        elif ":/" in arg:
            urls.append(arg)
    if urls:
        succ, fail = ctrl.downloadURLs(urls,
                                       _("packages"),
                                       targetdir=os.getcwd())
        if fail:
            raise Error, _("Failed to download packages:\n") + \
                         "\n".join(["    %s: %s" % (url, fail[url])
                                    for url in fail])
        for url, file in succ.items():
            ctrl.addFileChannel(file)
            opts.args.remove(url)
    ctrl.reloadChannels()
    cache = ctrl.getCache()
    trans = Transaction(cache, policy)
    for channel in ctrl.getFileChannels():
        for loader in channel.getLoaders():
            for pkg in loader.getPackages():
                if pkg.installed:
                    raise Error, _("%s is already installed") % pkg
                trans.enqueue(pkg, INSTALL)

    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):
                        dct[obj] = True
                    else:
                        dct.update(dict.fromkeys(obj.packages, True))
                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

        pkgs = []

        for obj in results:
            if isinstance(obj, Package):
                pkgs.append(obj)

        if not pkgs:
            installed = False
            names = {}
            for obj in results:
                for pkg in obj.packages:
                    if pkg.installed:
                        iface.warning(
                            _("%s (for %s) is already installed") % (pkg, arg))
                        installed = True
                        break
                    else:
                        pkgs.append(pkg)
                        names[pkg.name] = True
                else:
                    continue
                break
            if installed:
                continue
            if len(names) > 1:
                raise Error, _("There are multiple matches for '%s':\n%s") % \
                              (arg, "\n".join(["    "+str(x) for x in pkgs]))

        if len(pkgs) > 1:
            if pkgs[0].isPatch():
                pkgs.sort()
                pkgs.reverse()
            else:
                sortUpgrades(pkgs)

        names = {}
        for pkg in pkgs:
            names.setdefault(pkg.name, []).append(pkg)
        for name in names:
            pkg = names[name][0]
            if pkg.installed:
                iface.warning(_("%s is already installed") % pkg)
            else:
                trans.enqueue(pkg, INSTALL)

    iface.showStatus(_("Computing transaction..."))
    trans.run()
    iface.hideStatus()
    if trans:
        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)
コード例 #17
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)
         self.changedMarks()
コード例 #18
0
ファイル: remove.py プロジェクト: Kampi/Zybo-Linux
def main(ctrl, opts):

    # Argument check
    if not opts.args:
        raise Error, _("no package(s) given")

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

    if 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, PolicyRemove)
    policy = trans.getPolicy()

    if opts.auto:
        rmcs = ctrl.markAndSweep()
        confirm = not opts.yes
        ctrl.commitChangeSet(rmcs, confirm=confirm)
    
    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

        pkgs = []

        for obj in results:
            if isinstance(obj, Package):
                pkgs.append(obj)

        if not pkgs:
            for obj in results:
                for pkg in obj.packages:
                    pkgs.append(pkg)

        found = False
        for pkg in pkgs:
            if pkg.installed:
                found = True
                trans.enqueue(pkg, REMOVE)
            else:
                policy.setLocked(pkg, True)
        if not found:
            iface.warning(_("'%s' matches no installed packages") % arg)

    iface.showStatus(_("Computing transaction..."))
    trans.run()
    iface.hideStatus()
    if trans:
        confirm = not opts.yes
        if opts.urls:
            ctrl.dumpTransactionURLs(trans)
        elif opts.metalink:
            ctrl.dumpTransactionMetalink(trans)
        elif opts.dump:
            ctrl.dumpTransactionPackages(trans, remove=True)
        elif opts.download:
            ctrl.downloadTransaction(trans, confirm=confirm)
        elif opts.stepped:
            ctrl.commitTransactionStepped(trans, confirm=confirm)
        else:
            ctrl.commitTransaction(trans, confirm=confirm)
コード例 #19
0
ファイル: install.py プロジェクト: Kampi/Zybo-Linux
def main(ctrl, opts):
 
    # Argument check
    if not opts.args:
        raise Error, _("no package(s) given")

    if opts.attempt:
	sysconf.set("attempt-install", True, soft=True)

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

    urls = []
    for arg in opts.args[:]:
        if (os.path.isfile(arg) and
            '/' in arg or ctrl.checkPackageFile(arg)):
            ctrl.addFileChannel(arg)
            opts.args.remove(arg)
        elif ":/" in arg:
            urls.append(arg)
    if urls:
        succ, fail = ctrl.downloadURLs(urls, _("packages"),
                                       targetdir=os.getcwd())
        if fail:
            raise Error, _("Failed to download packages:\n") + \
                         "\n".join(["    %s: %s" % (url, fail[url])
                                    for url in fail])
        for url, file in succ.items():
            ctrl.addFileChannel(file)
            opts.args.remove(url)
    if 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, PolicyInstall)
    for channel in ctrl.getFileChannels():
        for loader in channel.getLoaders():
            for pkg in loader.getPackages():
                if pkg.installed:
                    raise Error, _("%s is already installed") % pkg
                trans.enqueue(pkg, INSTALL)


    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):
                        dct[obj] = True
                    else:
                        dct.update(dict.fromkeys(obj.packages, True))
                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

        pkgs = []

        for obj in results:
            if isinstance(obj, Package):
                pkgs.append(obj)

        if not pkgs:
            installed = False
            names = {}
            for obj in results:
                for pkg in obj.packages:
                    if pkg.installed:
                        iface.info(_("%s (for %s) is already installed")
                                      % (pkg, arg))
                        installed = True
                        break
                    else:
                        pkgs.append(pkg)
                        names[pkg.name] = True
                else:
                    continue
                break
            if installed:
                continue
            if len(names) == 2 and sysconf.get("rpm-strict-multilib"):
                from smart.backends.rpm.rpmver import splitarch
                # two packages with the same version but different arch, pick best
                if splitarch(pkgs[0].version)[0] == splitarch(pkgs[1].version)[0]:
                    pkg = max(pkgs[0], pkgs[1])
                    names.pop(pkg.name)
                    pkgs.remove(pkg)
            if len(names) > 1:
                raise Error, _("There are multiple matches for '%s':\n%s") % \
                              (arg, "\n".join(["    "+str(x) for x in pkgs]))

        if len(pkgs) > 1:
            sortUpgrades(pkgs)

        names = {}
        for pkg in pkgs:
            names.setdefault(pkg.name, []).append(pkg)
        for name in names:
            pkg = names[name][0]
            if pkg.installed:
                iface.info(_("%s is already installed") % pkg)
            else:
                trans.enqueue(pkg, INSTALL)

    iface.showStatus(_("Computing transaction..."))
    trans.run()
    iface.hideStatus()
    if trans:
        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)
コード例 #20
0
ファイル: install.py プロジェクト: pombredanne/winlibre_pm
def main(ctrl, opts):
 
    if opts.explain:
        sysconf.set("explain-changesets", True, soft=True)

    urls = []
    for arg in opts.args[:]:
        if (os.path.isfile(arg) and
            '/' in arg or filter(None, hooks.call("check-package-file", arg))):
            ctrl.addFileChannel(arg)
            opts.args.remove(arg)
        elif ":/" in arg:
            urls.append(arg)
    if urls:
        succ, fail = ctrl.downloadURLs(urls, _("packages"),
                                       targetdir=os.getcwd())
        if fail:
            raise Error, _("Failed to download packages:\n") + \
                         "\n".join(["    %s: %s" % (url, fail[url])
                                    for url in fail])
        for url, file in succ.items():
            ctrl.addFileChannel(file)
            opts.args.remove(url)
    ctrl.reloadChannels()
    cache = ctrl.getCache()
    trans = Transaction(cache, PolicyInstall)
    for channel in ctrl.getFileChannels():
        for loader in channel.getLoaders():
            for pkg in loader.getPackages():
                if pkg.installed:
                    raise Error, _("%s is already installed") % pkg
                trans.enqueue(pkg, INSTALL)


    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):
                        dct[obj] = True
                    else:
                        dct.update(dict.fromkeys(obj.packages, True))
                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

        pkgs = []

        for obj in results:
            if isinstance(obj, Package):
                pkgs.append(obj)

        if not pkgs:
            installed = False
            names = {}
            for obj in results:
                for pkg in obj.packages:
                    if pkg.installed:
                        iface.warning(_("%s (for %s) is already installed")
                                      % (pkg, arg))
                        installed = True
                        break
                    else:
                        pkgs.append(pkg)
                        names[pkg.name] = True
                else:
                    continue
                break
            if installed:
                continue
            if len(names) > 1:
                raise Error, _("There are multiple matches for '%s':\n%s") % \
                              (arg, "\n".join(["    "+str(x) for x in pkgs]))

        if len(pkgs) > 1:
            sortUpgrades(pkgs)

        names = {}
        for pkg in pkgs:
            names.setdefault(pkg.name, []).append(pkg)
        for name in names:
            pkg = names[name][0]
            if pkg.installed:
                iface.warning(_("%s is already installed") % pkg)
            else:
                trans.enqueue(pkg, INSTALL)

    iface.showStatus(_("Computing transaction..."))
    trans.run()
    iface.hideStatus()
    if trans:
        confirm = not opts.yes
        print opts.urls, opts.dump, opts.download, opts.stepped, confirm
        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)
コード例 #21
0
ファイル: remove.py プロジェクト: NehaRawat/spacewalk
def main(ctrl, opts):

    ctrl.reloadChannels()
    cache = ctrl.getCache()
    trans = Transaction(cache, PolicyRemove)
    policy = trans.getPolicy()
    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

        pkgs = []

        for obj in results:
            if isinstance(obj, Package):
                pkgs.append(obj)

        if not pkgs:
            for obj in results:
                for pkg in obj.packages:
                    pkgs.append(pkg)

        found = False
        for pkg in pkgs:
            if pkg.installed:
                found = True
                trans.enqueue(pkg, REMOVE)
            else:
                policy.setLocked(pkg, True)
        if not found:
            iface.warning(_("'%s' matches no installed packages") % arg)

    iface.showStatus(_("Computing transaction..."))
    trans.run()
    iface.hideStatus()
    if trans:
        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)
コード例 #22
0
def main(ctrl, opts):

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

    if 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, PolicyRemove)
    policy = trans.getPolicy()

    if opts.auto:
        rmcs = ctrl.markAndSweep()
        confirm = not opts.yes
        ctrl.commitChangeSet(rmcs, confirm=confirm)

    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

        pkgs = []

        for obj in results:
            if isinstance(obj, Package):
                pkgs.append(obj)

        if not pkgs:
            for obj in results:
                for pkg in obj.packages:
                    pkgs.append(pkg)

        found = False
        for pkg in pkgs:
            if pkg.installed:
                found = True
                trans.enqueue(pkg, REMOVE)
            else:
                policy.setLocked(pkg, True)
        if not found:
            iface.warning(_("'%s' matches no installed packages") % arg)

    iface.showStatus(_("Computing transaction..."))
    trans.run()
    iface.hideStatus()
    if trans:
        confirm = not opts.yes
        if opts.urls:
            ctrl.dumpTransactionURLs(trans)
        elif opts.metalink:
            ctrl.dumpTransactionMetalink(trans)
        elif opts.dump:
            ctrl.dumpTransactionPackages(trans, remove=True)
        elif opts.download:
            ctrl.downloadTransaction(trans, confirm=confirm)
        elif opts.stepped:
            ctrl.commitTransactionStepped(trans, confirm=confirm)
        else:
            ctrl.commitTransaction(trans, confirm=confirm)