Ejemplo n.º 1
0
Archivo: pm.py Proyecto: rprstop/rootfs
class RPMPackageManager(PackageManager):
    def commit(self, changeset, pkgpaths):

        prog = iface.getProgress(self, True)
        prog.start()
        prog.setTopic(_("Committing transaction..."))
        prog.set(0, len(changeset))
        prog.show()

        # Compute upgrading/upgraded packages
        upgrading = {}
        upgraded = {}
        for pkg in changeset.keys():
            if changeset.get(pkg) is INSTALL:
                upgpkgs = [
                    upgpkg for prv in pkg.provides for upg in prv.upgradedby
                    for upgpkg in upg.packages if upgpkg.installed
                ]
                upgpkgs.extend([
                    prvpkg for upg in pkg.upgrades for prv in upg.providedby
                    for prvpkg in prv.packages if prvpkg.installed
                ])
                if upgpkgs:
                    for upgpkg in upgpkgs:
                        # If any upgraded package will stay in the system,
                        # this is not really an upgrade for rpm.
                        if changeset.get(upgpkg) is not REMOVE:
                            break
                    else:
                        upgrading[pkg] = True
                        for upgpkg in upgpkgs:
                            upgraded[upgpkg] = True
                            if upgpkg in changeset:
                                del changeset[upgpkg]

        ts = getTS(True)

        flags = ts.setFlags(0)
        if sysconf.get("rpm-allfiles", False):
            flags |= rpm.RPMTRANS_FLAG_ALLFILES
        if sysconf.get("rpm-justdb", False):
            flags |= rpm.RPMTRANS_FLAG_JUSTDB
        if sysconf.get("rpm-noconfigs", False):
            flags |= rpm.RPMTRANS_FLAG_NOCONFIGS
        if (sysconf.get("rpm-nodocs", False)
                or sysconf.get("rpm-excludedocs", False)):
            flags |= rpm.RPMTRANS_FLAG_NODOCS
        if sysconf.get("rpm-nomd5", False):
            flags |= rpm.RPMTRANS_FLAG_NOMD5
        if sysconf.get("rpm-noscripts", False):
            flags |= rpm.RPMTRANS_FLAG_NOSCRIPTS
        if sysconf.get("rpm-notriggers", False):
            flags |= rpm.RPMTRANS_FLAG_NOTRIGGERS
        if sysconf.get("rpm-repackage", False):
            flags |= rpm.RPMTRANS_FLAG_REPACKAGE
        if sysconf.get("rpm-test", False):
            flags |= rpm.RPMTRANS_FLAG_TEST
        ts.setFlags(flags)

        dflags = ts.setDFlags(0)
        if sysconf.get("rpm-noupgrade", False):
            dflags |= rpm.RPMDEPS_FLAG_NOUPGRADE
        if sysconf.get("rpm-norequires", False):
            dflags |= rpm.RPMDEPS_FLAG_NOREQUIRES
        if sysconf.get("rpm-noconflicts", False):
            dflags |= rpm.RPMDEPS_FLAG_NOCONFLICTS
        if sysconf.get("rpm-noobsoletes", False):
            dflags |= rpm.RPMDEPS_FLAG_NOOBSOLETES
        if sysconf.get("rpm-noparentdirs", False):
            dflags |= rpm.RPMDEPS_FLAG_NOPARENTDIRS
        if sysconf.get("rpm-nolinktos", False):
            dflags |= rpm.RPMDEPS_FLAG_NOLINKTOS
        if sysconf.get("rpm-nosuggest", False):
            dflags |= rpm.RPMDEPS_FLAG_NOSUGGEST
        ts.setDFlags(dflags)

        # Set rpm verbosity level.
        levelname = sysconf.get('rpm-log-level')
        level = {
            'emerg': rpm.RPMLOG_EMERG,
            'alert': rpm.RPMLOG_ALERT,
            'crit': rpm.RPMLOG_CRIT,
            'err': rpm.RPMLOG_ERR,
            'warning': rpm.RPMLOG_WARNING,
            'notice': rpm.RPMLOG_NOTICE,
            'info': rpm.RPMLOG_INFO,
            'debug': rpm.RPMLOG_DEBUG
        }.get(levelname)
        if level is not None:
            rpm.setVerbosity(level)

        # Set rpm output log file
        rpmlogfile = sysconf.get('rpm-log-file')
        if rpmlogfile is not None:
            try:
                rpmlog = open(rpmlogfile, 'w')
                rpm.setLogFile(rpmlog)
            except (IOError, OSError), e:
                raise Error, "%s: %s" % (rpmlogfile, unicode(e))

        # Let's help RPM, since it doesn't do a good
        # ordering job on erasures.
        try:
            sorter = ChangeSetSorter(changeset)
            sorted = sorter.getSorted()
            forcerpmorder = False
        except LoopError:
            lines = [_("Found unbreakable loops:")]
            for path in sorter.getLoopPaths(sorter.getLoops()):
                path = [
                    "%s [%s]" % (pkg, op is INSTALL and "I" or "R")
                    for pkg, op in path
                ]
                lines.append("    " + " -> ".join(path))
            lines.append(_("Will ask RPM to order it."))
            iface.error("\n".join(lines))
            sorted = [(pkg, changeset[pkg]) for pkg in changeset]
            forcerpmorder = True
        del sorter

        packages = 0
        reinstall = False
        for pkg, op in sorted:
            if op is INSTALL:
                if pkg.installed:
                    reinstall = True
                loader = [x for x in pkg.loaders if not x.getInstalled()][0]
                info = loader.getInfo(pkg)
                mode = pkg in upgrading and "u" or "i"
                path = pkgpaths[pkg][0]
                fd = os.open(path, os.O_RDONLY)
                try:
                    h = ts.hdrFromFdno(fd)
                    if sysconf.get("rpm-check-signatures", False):
                        if get_public_key(h) == '(none)':
                            raise rpm.error('package is not signed')
                except rpm.error, e:
                    os.close(fd)
                    raise Error, "%s: %s" % (os.path.basename(path), e)
                os.close(fd)
                ts.addInstall(h, (info, path), mode)
                packages += 1
            else:
                loader = [x for x in pkg.loaders if x.getInstalled()][0]
                offset = pkg.loaders[loader]
                try:
                    ts.addErase(offset)
                except rpm.error, e:
                    raise Error, "%s-%s: %s" % \
                                 (pkg.name, pkg.version, unicode(e))
Ejemplo n.º 2
0
        # Let's help RPM, since it doesn't do a good
        # ordering job on erasures.
        try:
            sorter = ChangeSetSorter(changeset)
            sorted = sorter.getSorted()
            forcerpmorder = False
        except LoopError:
            lines = [_("Found unbreakable loops:")]
            for path in sorter.getLoopPaths(sorter.getLoops()):
                path = [
                    "%s [%s]" % (pkg, op is INSTALL and "I" or "R")
                    for pkg, op in path
                ]
                lines.append("    " + " -> ".join(path))
            lines.append(_("Will ask RPM to order it."))
            iface.error("\n".join(lines))
            sorted = [(pkg, changeset[pkg]) for pkg in changeset]
            forcerpmorder = True
        del sorter

        packages = 0
        reinstall = False
        for pkg, op in sorted:
            if op is INSTALL:
                if pkg.installed:
                    reinstall = True
                loader = [x for x in pkg.loaders if not x.getInstalled()][0]
                info = loader.getInfo(pkg)
                mode = pkg in upgrading and "u" or "i"
                path = pkgpaths[pkg][0]
                fd = os.open(path, os.O_RDONLY)
Ejemplo n.º 3
0
    def commit(self, changeset, pkgpaths):

        prog = iface.getProgress(self, True)
        prog.start()
        prog.setTopic(_("Committing transaction..."))
        prog.show()

        # Compute upgraded packages
        upgraded = {}
        for pkg in changeset.keys():
            if changeset[pkg] is INSTALL:
                upgpkgs = [
                    upgpkg
                    for prv in pkg.provides
                    for upg in prv.upgradedby
                    for upgpkg in upg.packages
                    if upgpkg.installed
                ]
                upgpkgs.extend(
                    [
                        prvpkg
                        for upg in pkg.upgrades
                        for prv in upg.providedby
                        for prvpkg in prv.packages
                        if prvpkg.installed
                    ]
                )
                if upgpkgs:
                    for upgpkg in upgpkgs:
                        assert changeset.get(upgpkg) is REMOVE, "Installing %s while %s is kept?" % (pkg, upgpkg)
                        assert upgpkg not in upgraded, (
                            "Two packages (%s and %s) upgrading the "
                            "same installed package (%s)!?" % (pkg, upgraded[upgpkg], upgpkg)
                        )
                        upgraded[upgpkg] = pkg

        sorter = DebSorter(changeset)

        sorted = sorter.getSorted()

        prog.set(0, len(sorted))

        baseargs = shlex.split(sysconf.get("dpkg", "dpkg"))

        opt = sysconf.get("deb-root")
        if opt:
            baseargs.append("--root=%s" % opt)
        opt = sysconf.get("deb-admindir")
        if opt:
            baseargs.append("--admindir=%s" % opt)
        opt = sysconf.get("deb-instdir")
        if opt:
            baseargs.append("--instdir=%s" % opt)
        opt = sysconf.get("deb-simulate")
        if opt:
            baseargs.append("--simulate")

        if sysconf.get("deb-purge"):
            for i in range(len(sorted)):
                pkg, op = sorted[i]
                if op is REMOVE and not upgraded.get(pkg):
                    sorted[i] = pkg, PURGE

        if sysconf.get("deb-non-interactive"):
            old_debian_frontend = os.environ.get(DEBIAN_FRONTEND)
            old_apt_lc_frontend = os.environ.get(APT_LISTCHANGES_FRONTEND)
            os.environ[DEBIAN_FRONTEND] = "noninteractive"
            os.environ[APT_LISTCHANGES_FRONTEND] = "none"
            baseargs.append("--force-confold")

        if sysconf.get("pm-iface-output"):
            output = tempfile.TemporaryFile()
        else:
            output = sys.stdout

        print >> output

        done = {}
        error = None
        while sorted:

            pkgs = []
            op = sorted[0][1]
            while sorted and sorted[0][1] is op and len(pkgs) < self.MAXPKGSPEROP:
                pkg, op = sorted.pop(0)
                if op is REMOVE and upgraded.get(pkg) in done:
                    continue
                done[pkg] = True
                opname = {REMOVE: "remove", PURGE: "purge", CONFIG: "config", UNPACK: "unpack", INSTALL: "install"}
                print >> output, "[%s] %s" % (opname[op], pkg)
                pkgs.append(pkg)

            if not pkgs:
                continue

            args = baseargs[:]

            if op is REMOVE:
                args.append("--force-depends")
                args.append("--force-remove-essential")
                args.append("--remove")
            elif op is PURGE:
                args.append("--force-remove-essential")
                args.append("--purge")
            elif op is UNPACK:
                args.append("--unpack")
            elif op is CONFIG:
                args.append("--force-depends")
                args.append("--force-remove-essential")
                args.append("--configure")

            if op is UNPACK:
                for pkg in pkgs:
                    args.append(pkgpaths[pkg][0])
            else:
                for pkg in pkgs:
                    args.append(pkg.name)

            thread_name = threading.currentThread().getName()
            if thread_name == "MainThread":
                quithandler = signal.signal(signal.SIGQUIT, signal.SIG_IGN)
                inthandler = signal.signal(signal.SIGINT, signal.SIG_IGN)

            output.flush()

            cb = DebCallback(prog, op, pkgs)

            status = self.dpkg(args, output, cb)

            if thread_name == "MainThread":
                signal.signal(signal.SIGQUIT, quithandler)
                signal.signal(signal.SIGINT, inthandler)

            if not os.WIFEXITED(status) or os.WEXITSTATUS(status) != 0:
                if os.WIFSIGNALED(status) and os.WTERMSIG(status):
                    error = _("Sub-process %s has received a " "segmentation fault") % args[0]
                elif os.WIFEXITED(status):
                    error = _("Sub-process %s returned an error code " "(%d)") % (args[0], os.WEXITSTATUS(status))
                else:
                    error = _("Sub-process %s exited unexpectedly") % args[0]
                break

        if output != sys.stdout:
            output.flush()
            output.seek(0)
            data = output.read(8192)
            while data:
                iface.showOutput(data)
                data = output.read(8192)
            output.close()

        if sysconf.get("deb-non-interactive"):
            if old_debian_frontend is None:
                del os.environ[DEBIAN_FRONTEND]
            else:
                os.environ[DEBIAN_FRONTEND] = old_debian_frontend
            if old_apt_lc_frontend is None:
                del os.environ[APT_LISTCHANGES_FRONTEND]
            else:
                os.environ[APT_LISTCHANGES_FRONTEND] = old_apt_lc_frontend

        if error:
            iface.error(error)

        prog.setDone()
        prog.stop()
Ejemplo n.º 4
0
Archivo: pm.py Proyecto: pombreda/smart
    def commit(self, changeset, pkgpaths):

        prog = iface.getProgress(self, True)
        prog.start()
        prog.setTopic(_("Committing transaction..."))
        prog.show()

        # Compute upgraded packages
        upgraded = {}
        for pkg in changeset.keys():
            if changeset[pkg] is INSTALL:
                upgpkgs = [
                    upgpkg for prv in pkg.provides for upg in prv.upgradedby
                    for upgpkg in upg.packages if upgpkg.installed
                ]
                upgpkgs.extend([
                    prvpkg for upg in pkg.upgrades for prv in upg.providedby
                    for prvpkg in prv.packages if prvpkg.installed
                ])
                if upgpkgs:
                    for upgpkg in upgpkgs:
                        assert changeset.get(upgpkg) is REMOVE, \
                               "Installing %s while %s is kept?" % \
                               (pkg, upgpkg)
                        assert upgpkg not in upgraded, \
                               "Two packages (%s and %s) upgrading the " \
                               "same installed package (%s)!?" % \
                               (pkg, upgraded[upgpkg], upgpkg)
                        upgraded[upgpkg] = pkg

        sorter = DebSorter(changeset)

        sorted = sorter.getSorted()

        prog.set(0, len(sorted))

        baseargs = shlex.split(sysconf.get("dpkg", "dpkg"))

        opt = sysconf.get("deb-root")
        if opt:
            baseargs.append("--root=%s" % opt)
        opt = sysconf.get("deb-admindir")
        if opt:
            baseargs.append("--admindir=%s" % opt)
        opt = sysconf.get("deb-instdir")
        if opt:
            baseargs.append("--instdir=%s" % opt)
        opt = sysconf.get("deb-simulate")
        if opt:
            baseargs.append("--simulate")

        if sysconf.get("deb-purge"):
            for i in range(len(sorted)):
                pkg, op = sorted[i]
                if op is REMOVE and not upgraded.get(pkg):
                    sorted[i] = pkg, PURGE

        if sysconf.get("deb-non-interactive"):
            old_debian_frontend = os.environ.get(DEBIAN_FRONTEND)
            old_apt_lc_frontend = os.environ.get(APT_LISTCHANGES_FRONTEND)
            os.environ[DEBIAN_FRONTEND] = "noninteractive"
            os.environ[APT_LISTCHANGES_FRONTEND] = "none"
            baseargs.append("--force-confold")

        if sysconf.get("pm-iface-output"):
            output = tempfile.TemporaryFile()
        else:
            output = sys.stdout

        print >> output

        done = {}
        error = None
        while sorted:

            pkgs = []
            op = sorted[0][1]
            while (sorted and sorted[0][1] is op
                   and len(pkgs) < self.MAXPKGSPEROP):
                pkg, op = sorted.pop(0)
                if op is REMOVE and upgraded.get(pkg) in done:
                    continue
                done[pkg] = True
                opname = {
                    REMOVE: "remove",
                    PURGE: "purge",
                    CONFIG: "config",
                    UNPACK: "unpack",
                    INSTALL: "install"
                }
                print >> output, "[%s] %s" % (opname[op], pkg)
                pkgs.append(pkg)

            if not pkgs:
                continue

            args = baseargs[:]

            if op is REMOVE:
                args.append("--force-depends")
                args.append("--force-remove-essential")
                args.append("--remove")
            elif op is PURGE:
                args.append("--force-remove-essential")
                args.append("--purge")
            elif op is UNPACK:
                args.append("--unpack")
            elif op is CONFIG:
                args.append("--force-depends")
                args.append("--force-remove-essential")
                args.append("--configure")

            if op is UNPACK:
                for pkg in pkgs:
                    args.append(pkgpaths[pkg][0])
            else:
                for pkg in pkgs:
                    args.append(pkg.name)

            thread_name = threading.currentThread().getName()
            if thread_name == "MainThread":
                quithandler = signal.signal(signal.SIGQUIT, signal.SIG_IGN)
                inthandler = signal.signal(signal.SIGINT, signal.SIG_IGN)

            output.flush()

            cb = DebCallback(prog, op, pkgs)

            status = self.dpkg(args, output, cb)

            if thread_name == "MainThread":
                signal.signal(signal.SIGQUIT, quithandler)
                signal.signal(signal.SIGINT, inthandler)

            if not os.WIFEXITED(status) or os.WEXITSTATUS(status) != 0:
                if os.WIFSIGNALED(status) and os.WTERMSIG(status):
                    error = _("Sub-process %s has received a "
                              "segmentation fault") % args[0]
                elif os.WIFEXITED(status):
                    error = _("Sub-process %s returned an error code "
                              "(%d)") % (args[0], os.WEXITSTATUS(status))
                else:
                    error = _("Sub-process %s exited unexpectedly") % args[0]
                break

        if output != sys.stdout:
            output.flush()
            output.seek(0)
            data = output.read(8192)
            while data:
                iface.showOutput(data)
                data = output.read(8192)
            output.close()

        if sysconf.get("deb-non-interactive"):
            if old_debian_frontend is None:
                del os.environ[DEBIAN_FRONTEND]
            else:
                os.environ[DEBIAN_FRONTEND] = old_debian_frontend
            if old_apt_lc_frontend is None:
                del os.environ[APT_LISTCHANGES_FRONTEND]
            else:
                os.environ[APT_LISTCHANGES_FRONTEND] = old_apt_lc_frontend

        if error:
            iface.error(error)

        prog.setDone()
        prog.stop()
Ejemplo n.º 5
0
Archivo: pm.py Proyecto: KortanZ/linux
                raise Error, "%s: %s" % (rpmlogfile, unicode(e))

        # Let's help RPM, since it doesn't do a good
        # ordering job on erasures.
        try:
            sorter = ChangeSetSorter(changeset)
            sorted = sorter.getSorted()
            forcerpmorder = False
        except LoopError:
            lines = [_("Found unbreakable loops:")]
            for path in sorter.getLoopPaths(sorter.getLoops()):
                path = ["%s [%s]" % (pkg, op is INSTALL and "I" or "R")
                        for pkg, op in path]
                lines.append("    "+" -> ".join(path))
            lines.append(_("Will ask RPM to order it."))
            iface.error("\n".join(lines))
            sorted = [(pkg, changeset[pkg]) for pkg in changeset]
            forcerpmorder = True
        del sorter

        packages = 0
        reinstall = False
        for pkg, op in sorted:
            if op is INSTALL:
                if pkg.installed:
                    reinstall = True
                loader = [x for x in pkg.loaders if not x.getInstalled()][0]
                info = loader.getInfo(pkg)
                mode = pkg in upgrading and "u" or "i"
                path = pkgpaths[pkg][0]
                fd = os.open(path, os.O_RDONLY)