def addCollection(self, name, version=None, strongList=None,
                      weakRefList=None, calcSize=False, repos=None,
                      defaultFlavor=None, createComps=False,
                      existsOkay=False, redirect=None,
                      changeSetFile = None, buildReqs=None,
                      labelPath=None, sourceName=None,
                      preUpdateScript = None, postInstallScript = None,
                      postUpdateScript = None,
                      preRollbackScript = None, postRollbackScript = None,
                      preInstallScript = None, preEraseScript = None,
                      postEraseScript = None,
                      compatClass = None, flavor = None,
                      loadedReqs=None, metadata=None, imageGroup = None,
                      pathConflicts=None):
        if not repos:
            repos = self.openRepository()

        if isinstance(version, (list, tuple)):
            strongList = version
            version = None
        assert(strongList or redirect)

        if version is None and defaultFlavor is None:
            name, version, defaultFlavor = cmdline.parseTroveSpec(name)
            if not version:
                version = '1.0'

        version = self._cvtVersion(version)
        assert(':' not in name and not name.startswith('fileset'))

        if defaultFlavor is None:
            defaultFlavor = deps.Flavor()
        elif isinstance(defaultFlavor, str):
            defaultFlavor = deps.parseFlavor(defaultFlavor)

        fullList = {}

        if weakRefList is None:
            hasWeakRefs = False
            weakRefList = []
        else:
            hasWeakRefs = True

        idx = 0
        for weakRef, troveList in zip((False, True), (strongList, weakRefList)):
            for info in troveList:
                idx += 1
                trvFlavor = None
                trvVersion = None
                byDefault = True
                if isinstance(info, str):
                    trvName = info
                    if '=' in trvName or trvName in '[':
                        (trvName, trvVersion, trvFlavor) \
                                        = cmdline.parseTroveSpec(trvName)
                elif isinstance(info, trove.Trove):
                    (trvName, trvVersion, trvFlavor) \
                                        = info.getNameVersionFlavor()
                elif len(info) == 1:
                    (trvName,) = info
                elif len(info) == 2:
                    (trvName, item) = info
                    if isinstance(item, bool):
                        byDefault = item
                    else:
                        trvVersion = item
                elif len(info) == 3:
                    (trvName, trvVersion, trvFlavor) = info
                elif len(info) == 4:
                    (trvName, trvVersion, trvFlavor, byDefault) = info
                else:
                    assert(False)

                if trvVersion is None and trvFlavor is None:
                    (trvName, trvVersion, trvFlavor) = \
                                cmdline.parseTroveSpec(trvName)

                if not trvVersion:
                    trvVersion = version
                else:
                    trvVersion = self._cvtVersion(trvVersion)

                if trvFlavor is None:
                    trvFlavor = defaultFlavor
                elif type(trvFlavor) == str:
                    trvFlavor = deps.parseFlavor(trvFlavor)

                if trvName[0] == ':':
                    trvName = name + trvName

                if createComps and ':' in trvName:
                    self.addComponent(trvName, trvVersion.freeze(),
                                      str(trvFlavor), filePrimer=idx, sourceName=sourceName)

                fullList[(trvName, trvVersion, trvFlavor)] = (byDefault,
                                                              weakRef)
        if flavor:
            flavor = deps.parseFlavor(flavor, raiseError=True)
        else:
            flavor = deps.mergeFlavorList([x[2] for x in fullList],
                                          deps.DEP_MERGE_TYPE_DROP_CONFLICTS)

        if not hasWeakRefs:
            collList = [ x for x in fullList.iteritems() if trove.troveIsCollection(x[0][0])]
            troves = repos.getTroves([x[0] for x in collList], withFiles=False)

            for (troveTup, (byDefault, _)), trv in itertools.izip(collList,
                                                                  troves):
                for childInfo in trv.iterTroveList(strongRefs=True,
                                                   weakRefs=True):
                    childByDefault = (trv.includeTroveByDefault(*childInfo)
                                      and byDefault)
                    currInfo = fullList.get(childInfo, None)
                    if currInfo:
                        childByDefult = currInfo[0] or childByDefault
                        fullList[childInfo] = (childByDefault, currInfo[1])
                    else:
                        fullList[childInfo] = (childByDefault, True)

        if redirect is not None:
            redirectList = []
            for info in redirect:
                if info is None:
                    redirectList.append((None, None, None))
                    continue
                if not isinstance(info, (list, tuple)):
                    info = [info]
                if len(info) == 1:
                    redirName = info[0]
                    redirBranch = version.branch()
                    redirFlavor = flavor
                elif len(info) == 2:
                    redirName, redirBranch = info
                    redirBranch = versions.VersionFromString(redirBranch)
                    redirFlavor = deps.parseFlavor('')
                else:
                    redirName, redirBranch, redirFlavor = info
                    redirBranch = versions.VersionFromString(redirBranch)
                    redirFlavor = deps.parseFlavor(redirFlavor)
                redirectList.append((redirName, redirBranch, redirFlavor))

        # add a pkg diff
        if redirect is not None:
            troveType = trove.TROVE_TYPE_REDIRECT
        else:
            troveType = trove.TROVE_TYPE_NORMAL

        coll = trove.Trove(name, version, flavor, None, type=troveType)
        if existsOkay and repos.hasTrove(name, version, flavor):
            return repos.getTrove(name, version, flavor)

        coll.setIsCollection(True)
        coll.setSize(0)         # None is widely used as a shortcut
        for info, (byDefault, weakRef) in fullList.iteritems():
            coll.addTrove(*info, **dict(byDefault=byDefault, weakRef=weakRef))
        if not sourceName:
            sourceName = name + ':source'
        coll.setSourceName(sourceName)
        coll.setBuildTime(1238075164.694746)

        if redirect:
            for toName, toBranch, toFlavor in redirectList:
                coll.addRedirect(toName, toBranch, toFlavor)
        else:
            coll.setProvides(deps.parseDep('trove: %s' % name))

        if buildReqs is not None:
            buildReqs = self.makeTroveTupleList(buildReqs)
            coll.setBuildRequirements(buildReqs)
        if loadedReqs:
            loadedReqs = self.makeTroveTupleList(loadedReqs)
            coll.setLoadedTroves(loadedReqs)

        if pathConflicts is not None:
            for path in pathConflicts:
                coll.troveInfo.pathConflicts.append(path)

        if labelPath:
            coll.setLabelPath(labelPath)

        if compatClass:
            coll.setCompatibilityClass(compatClass)

        for spec, script in \
            [ (preUpdateScript,    coll.troveInfo.scripts.preUpdate),
              (postInstallScript,  coll.troveInfo.scripts.postInstall),
              (postUpdateScript,   coll.troveInfo.scripts.postUpdate),
              (preRollbackScript,  coll.troveInfo.scripts.preRollback),
              (postRollbackScript, coll.troveInfo.scripts.postRollback),
              (preInstallScript,   coll.troveInfo.scripts.preInstall),
              (preEraseScript,     coll.troveInfo.scripts.preErase),
              (postEraseScript,    coll.troveInfo.scripts.postErase), ]:
            if spec is None: continue
            if type(spec) == str:
                spec = TroveScript(script = spec)

            script.script.set(spec.script)

            if spec.conversions:
                assert(compatClass)
                assert(isinstance(spec, RollbackScript))
                script.conversions.addList(
                        (compatClass, x) for x in spec.conversions)

        if calcSize:
            compList = [x for x in fullList \
                                    if not trove.troveIsCollection(x[0])]
            size = (x.getSize() \
                    for x in repos.getTroves(compList, withFiles=False))
            coll.setSize(sum(x for x in size if x is not None))

        if metadata:
            if not isinstance(metadata, (list, tuple)):
                metadata = [metadata]
            for item in metadata:
                coll.troveInfo.metadata.addItem(item)

        if imageGroup is not None:
            coll.troveInfo.imageGroup.set(imageGroup)

        coll.computeDigests()
        assert(redirect or list(coll.iterTroveList(strongRefs=True)))

        # create an absolute changeset
        cs = changeset.ChangeSet()
        diff = coll.diff(None, absolute = True)[0]
        cs.newTrove(diff)

        if changeSetFile:
            cs.addPrimaryTrove(coll.getName(), coll.getVersion(),
                               coll.getFlavor())
            cs.writeToFile(changeSetFile)
        else:
            repos.commitChangeSet(cs)

        return coll
dataset/ETHPy150Open sassoftware/conary/conary_test/rephelp.py/RepositoryHelper.addCollection/swapped operands of `in`