def createChangeSet(self, origTroveList, recurse = True,
                        withFiles = True, withFileContents = True,
                        excludeAutoSource = False,
                        mirrorMode = False, roleIds = None):
        """
        @param origTroveList: a list of
        C{(troveName, flavor, oldVersion, newVersion, absolute)} tuples.

        If C{oldVersion == None} and C{absolute == 0}, then the trove is
        assumed to be new for the purposes of the change set.

        If C{newVersion == None} then the trove is being removed.

        If recurse is set, this yields one result for the entire troveList.

        If recurse is not set, it yields one result per troveList entry.
        """
        cs = changeset.ChangeSet()
        externalTroveList = []
        externalFileList = []
        removedTroveList = []

        dupFilter = set()

        # make a copy to remove things from
        troveList = origTroveList[:]

        # def createChangeSet begins here

        troveWrapper = _TroveListWrapper(troveList, self.troveStore, withFiles,
                                         roleIds = roleIds)

        for (job, old, new, streams) in troveWrapper:
            (troveName, (oldVersion, oldFlavor),
                         (newVersion, newFlavor), absolute) = job

            # make sure we haven't already generated this changeset; since
            # troves can be included from other troves we could try
            # to generate quite a few duplicates
            if dupFilter in job:
                continue
            else:
                dupFilter.add(job)

            done = False
            if not newVersion:
                if oldVersion.getHost() not in self.serverNameList:
                    externalTroveList.append((troveName,
                                         (oldVersion, oldFlavor),
                                         (None, None), absolute))
                else:
                    # remove this trove and any trove contained in it
                    cs.oldTrove(troveName, oldVersion, oldFlavor)
                    for (name, version, flavor) in \
                                            old.iterTroveList(strongRefs=True):
                        troveWrapper.append((name, (version, flavor),
                                                   (None, None), absolute),
                                            False)
                done = True
            elif (newVersion.getHost() not in self.serverNameList
                or (oldVersion and
                    oldVersion.getHost() not in self.serverNameList)):
                # don't try to make changesets between repositories; the
                # client can do that itself

                # we don't generate chagnesets between removed and
                # present troves; that's up to the client
                externalTroveList.append((troveName, (oldVersion, oldFlavor),
                                     (newVersion, newFlavor), absolute))
                done = True
            elif (oldVersion and old.type() == trove.TROVE_TYPE_REMOVED):
                removedTroveList.append((troveName, (oldVersion, oldFlavor),
                                        (newVersion, newFlavor), absolute))
                done = True

            if done:
                if not recurse:
                    yield (cs, externalTroveList, externalFileList,
                           removedTroveList)

                    cs = changeset.ChangeSet()
                    externalTroveList = []
                    externalFileList = []
                    removedTroveList = []

                continue

            (troveChgSet, filesNeeded, pkgsNeeded) = \
                                new.diff(old, absolute = absolute)

            if recurse:
                for refJob in pkgsNeeded:
                    refOldVersion = refJob[1][0]
                    refNewVersion = refJob[2][0]
                    if (refNewVersion and
                           (refNewVersion.getHost() not in self.serverNameList)
                        or (refOldVersion and
                            refOldVersion.getHost() not in self.serverNameList)
                       ):
                        # don't try to make changesets between repositories; the
                        # client can do that itself
                        externalTroveList.append(refJob)
                    else:
                        troveWrapper.append(refJob, True)

            cs.newTrove(troveChgSet)

            if job in origTroveList and job[2][0] is not None:
                # add the primary w/ timestamps on the version
                try:
                    primary = troveChgSet.getNewNameVersionFlavor()
                    cs.addPrimaryTrove(*primary)
                except KeyError:
                    # primary troves could be in the externalTroveList, in
                    # which case they aren't primries
                    pass

            # sort the set of files we need into bins based on the server
            # name
            getList = []
            localFilesNeeded = []

            for (pathId, oldFileId, oldFileVersion, newFileId, newFileVersion) in filesNeeded:
                # if either the old or new file version is on a different
                # repository, creating this diff is someone else's problem
                if (newFileVersion.getHost() not in self.serverNameList
                    or (oldFileVersion and
                        oldFileVersion.getHost() not in self.serverNameList)):
                    externalFileList.append((pathId, troveName,
                         (oldVersion, oldFlavor, oldFileId, oldFileVersion),
                         (newVersion, newFlavor, newFileId, newFileVersion)))
                else:
                    localFilesNeeded.append((pathId, oldFileId, oldFileVersion,
                                             newFileId, newFileVersion))
                    if oldFileVersion:
                        getList.append((pathId, oldFileId, oldFileVersion))
                    getList.append((pathId, newFileId, newFileVersion))

            # Walk this in reverse order. This may seem odd, but the
            # order in the final changeset is set by sorting that happens
            # in the change set object itself. The only reason we sort
            # here at all is to make sure PTR file types come before the
            # file they refer to. Reverse shorting makes this a bit easier.
            localFilesNeeded.sort()
            localFilesNeeded.reverse()

            ptrTable = {}
            for (pathId, oldFileId, oldFileVersion, newFileId, \
                 newFileVersion) in localFilesNeeded:
                oldFile = None
                if oldFileVersion:
                    oldFile = files.ThawFile(streams[oldFileId], pathId)

                oldCont = None
                newCont = None

                newFile = files.ThawFile(streams[newFileId], pathId)

                # Skip identical fileids when mirroring, but always use
                # absolute file changes if there is any difference. See note
                # below.
                forceAbsolute = (mirrorMode and oldFileId
                        and oldFileId != newFileId)
                if forceAbsolute:
                    (filecs, contentsHash) = changeset.fileChangeSet(pathId,
                                                                     None,
                                                                     newFile)
                else:
                    (filecs, contentsHash) = changeset.fileChangeSet(pathId,
                                                                     oldFile,
                                                                     newFile)

                cs.addFile(oldFileId, newFileId, filecs)

                if (not withFileContents
                    or (excludeAutoSource and newFile.flags.isAutoSource())
                    or (newFile.flags.isEncapsulatedContent()
                        and not newFile.flags.isCapsuleOverride())):
                    continue

                # this test catches files which have changed from not
                # config files to config files; these need to be included
                # unconditionally so we always have the pristine contents
                # to include in the local database
                # Also include contents of config files when mirroring if the
                # fileid changed, even if the SHA-1 did not.
                # cf CNY-1570, CNY-1699, CNY-2210
                if (contentsHash
                        or (oldFile and newFile.flags.isConfig()
                            and not oldFile.flags.isConfig())
                        or (forceAbsolute and newFile.hasContents)
                        ):
                    if oldFileVersion and oldFile.hasContents:
                        oldCont = self.getFileContents(
                            [ (oldFileId, oldFileVersion, oldFile) ])[0]

                    newCont = self.getFileContents(
                            [ (newFileId, newFileVersion, newFile) ])[0]

                    (contType, cont) = changeset.fileContentsDiff(oldFile,
                                                oldCont, newFile, newCont,
                                                mirrorMode = mirrorMode)

                    # we don't let config files be ptr types; if they were
                    # they could be ptrs to things which aren't config files,
                    # which would completely hose the sort order we use. this
                    # could be relaxed someday to let them be ptr's to other
                    # config files
                    if not newFile.flags.isConfig() and \
                                contType == changeset.ChangedFileTypes.file:
                        contentsHash = newFile.contents.sha1()
                        ptr = ptrTable.get(contentsHash, None)
                        if ptr is not None:
                            contType = changeset.ChangedFileTypes.ptr
                            cont = filecontents.FromString(ptr)
                        else:
                            ptrTable[contentsHash] = pathId + newFileId

                    if not newFile.flags.isConfig() and \
                                contType == changeset.ChangedFileTypes.file:
                        cont = filecontents.CompressedFromDataStore(
                                              self.contentsStore,
                                              newFile.contents.sha1())
                        compressed = True
                    else:
                        compressed = False

                    # ptr entries are not compressed, whether or not they
                    # are config files. override the compressed rule from
                    # above
                    if contType == changeset.ChangedFileTypes.ptr:
                        compressed = False

                    cs.addFileContents(pathId, newFileId, contType, cont,
                                       newFile.flags.isConfig(),
                                       compressed = compressed)

            if not recurse:
                yield cs, externalTroveList, externalFileList, removedTroveList

                cs = changeset.ChangeSet()
                externalTroveList = []
                externalFileList = []
                removedTroveList = []

        if recurse:
            yield cs, externalTroveList, externalFileList, removedTroveList
dataset/ETHPy150Open sassoftware/conary/conary/repository/netrepos/fsrepos.py/FilesystemRepository.createChangeSet/swapped operands of `in`