예제 #1
0
파일: rpmdb.py 프로젝트: kholia/pyrpm
    def _removePkg(self, pkg):
        pkgid = pkg.key

        signals = functions.blockSignals()
        try:
            if self.__openDB4() != self.OK:
                functions.unblockSignals(signals)
                return 0

            self.__removeId(self.basenames_db, "basenames", pkgid, pkg)
            self.__removeId(self.conflictname_db, "conflictname", pkgid, pkg)
            self.__removeId(self.dirnames_db, "dirnames", pkgid, pkg)
            self.__removeId(self.filemd5s_db, "filemd5s", pkgid, pkg, True,
                            a2b_hex)
            self.__removeId(self.group_db, "group", pkgid, pkg)
            self.__removeId(self.installtid_db, "installtid", pkgid, pkg, True,
                            lambda x:pack("i", x))
            self.__removeId(self.name_db, "name", pkgid, pkg, False)
            self.__removeId(self.providename_db, "providename", pkgid, pkg)
            self.__removeId(self.provideversion_db, "provideversion", pkgid,
                            pkg)
            self.__removeId(self.requirename_db, "requirename", pkgid, pkg)
            self.__removeId(self.requireversion_db, "requireversion", pkgid,
                            pkg)
            self.__removeId(self.sha1header_db, "install_sha1header", pkgid,
                            pkg, False)
            self.__removeId(self.sigmd5_db, "install_md5", pkgid, pkg, False)
            self.__removeId(self.triggername_db, "triggername", pkgid, pkg)
            del self.packages_db[pkgid]
            self._sync()
        except bsddb.error:
            functions.unblockSignals(signals)
            return 0 # FIXME: keep trying?
        functions.unblockSignals(signals)
        return 1
예제 #2
0
파일: rpmdb.py 프로젝트: kholia/pyrpm
    def _addPkg(self, pkg):
        signals = functions.blockSignals()
        try:
            if self.__openDB4() != self.OK:
                functions.unblockSignals(signals)
                return 0

            try:
                maxid = unpack("I", self.packages_db[self.zero])[0]
            except (struct.error, KeyError):
                maxid = 0

            pkgid = pack("I", maxid + 1)

            rpmio = io.RpmFileIO("dummy")
            if pkg["signature"].has_key("size_in_sig"):
                pkg["install_size_in_sig"] = pkg["signature"]["size_in_sig"]
            if pkg["signature"].has_key("gpg"):
                pkg["install_gpg"] = pkg["signature"]["gpg"]
            if pkg["signature"].has_key("md5"):
                pkg["install_md5"] = pkg["signature"]["md5"]
            if pkg["signature"].has_key("sha1header"):
                pkg["install_sha1header"] = pkg["signature"]["sha1header"]
            if pkg["signature"].has_key("badsha1_1"):
                pkg["install_badsha1_1"] = pkg["signature"]["badsha1_1"]
            if pkg["signature"].has_key("badsha1_2"):
                pkg["install_badsha1_2"] = pkg["signature"]["badsha1_2"]
            if pkg["signature"].has_key("dsaheader"):
                pkg["install_dsaheader"] = pkg["signature"]["dsaheader"]
            if pkg["signature"].has_key("payloadsize"):
                pkg["archivesize"] = pkg["signature"]["payloadsize"]
            pkg["installtime"] = int(time.time())
            if pkg.has_key("basenames"):
                pkg["filestates"] = self.__getFileStates(pkg)
            pkg["installcolor"] = [self.config.tscolor,]
            pkg["installtid"] = [self.config.tid,]

            self.packages_db[self.zero] = pkgid

            (headerindex, headerdata) = rpmio._generateHeader(pkg, 4)
            self.packages_db[pkgid] = headerindex[8:]+headerdata

            self.__writeDB4(self.basenames_db, "basenames", pkgid, pkg)
            self.__writeDB4(self.conflictname_db, "conflictname", pkgid, pkg)
            self.__writeDB4(self.dirnames_db, "dirnames", pkgid, pkg)
            self.__writeDB4(self.filemd5s_db, "filemd5s", pkgid, pkg, True,
                            a2b_hex)
            self.__writeDB4(self.group_db, "group", pkgid, pkg)
            self.__writeDB4(self.installtid_db, "installtid", pkgid, pkg, True,
                            lambda x:pack("i", x))
            self.__writeDB4(self.name_db, "name", pkgid, pkg, False)
            self.__writeDB4(self.providename_db, "providename", pkgid, pkg)
            self.__writeDB4(self.provideversion_db, "provideversion", pkgid,
                            pkg)
            self.__writeDB4(self.requirename_db, "requirename", pkgid, pkg)
            self.__writeDB4(self.requireversion_db, "requireversion", pkgid,
                            pkg)
            self.__writeDB4(self.sha1header_db, "install_sha1header", pkgid,
                            pkg, False)
            self.__writeDB4(self.sigmd5_db, "install_md5", pkgid, pkg, False)
            self.__writeDB4(self.triggername_db, "triggername", pkgid, pkg)

            self._sync()
        except bsddb.error:
            functions.unblockSignals(signals)
            return 0 # Due to the blocking, this is now virtually atomic
        functions.unblockSignals(signals)
        return pkgid