def Component(self, troveName, version=None, flavor=None,
                  fileContents=None,
                  provides=deps.DependencySet(),
                  requires=deps.DependencySet(),
                  filePrimer=0, setConfigFlags=True,
                  repos=None, existsOkay=False, pathIdSalt='',
                  redirect=None, sourceName=None, metadata=None,
                  factory=None, capsule=None,
                  versus=None, buildTime=1238075164.694746):

        if isinstance(flavor, list):
            fileContents = flavor
            flavor = None
        elif isinstance(version, list):
            fileContents = version
            version = None

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

        troveVersion = self._cvtVersion(version,
                                         source=troveName.endswith(':source'))
        isSource = troveName.endswith(':source')

        assert(':' in troveName or trove.troveIsFileSet(troveName))

        componentDir = self.workDir + "/component"
        if os.path.exists(componentDir):
            shutil.rmtree(componentDir)
        util.mkdirChain(componentDir)
        if isinstance(flavor, list):
            assert(fileContents is None)
            fileContents = flavor
            flavor = ''
        flavor = deps.parseFlavor(flavor)

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

        # we create the trove with the wrong flavor here and fix it later
        # (by unioning in the file flavors)
        t = trove.Trove(troveName, troveVersion, flavor, None, type=troveType)

        # set up a file with some contents
        fileList = []
        if redirect is not None:
            redirectList = []
            assert(fileContents is None)
            for info in redirect:
                if info is None:
                    continue

                if not isinstance(info, (list, tuple)):
                    info = [info]
                if len(info) == 1:
                    redirName = info[0]
                    redirBranch = troveVersion.branch()
                    redirFlavor = flavor
                elif len(info) == 2:
                    redirName, redirBranch = info
                    redirBranch = versions.VersionFromString(redirBranch)
                    redirFlavor = None
                else:
                    redirName, redirBranch, redirFlavor = info
                    redirBranch = versions.VersionFromString(redirBranch)
                    if redirFlavor is not None:
                        redirFlavor = deps.parseFlavor(redirFlavor)
                redirectList.append((redirName, redirBranch, redirFlavor))
        else:
            if capsule:
                assert(capsule.endswith('.rpm'))
                f = files.FileFromFilesystem(capsule,
                                             trove.CAPSULE_PATHID)
                hdr = rpmhelper.readHeader(open(capsule))
                t.addRpmCapsule(os.path.basename(capsule),
                                troveVersion,
                                f.fileId(), hdr)
                fileList.append((f, trove.CAPSULE_PATHID,
                                 filecontents.FromFilesystem(capsule)))
            elif fileContents is None:
                path = '/contents%s' % filePrimer
                contents = 'hello, world!\n'

                if not filePrimer:
                    filePrimer = '\0'
                filePrimer = str(filePrimer)
                # Pad it on the left with zeros, up to 16 chars long
                pathId = filePrimer.rjust(16, '\1')
                pathId = pathId[0:16]

                contents = RegularFile(contents = contents, pathId = pathId,
                        config = None)
                fileContents = [(path, contents)]

            index = 0
            for fileInfo in fileContents:
                fileReq = None
                fileProv = None
                fileFlavor = None

                if isinstance(fileInfo, str):
                    fileInfo = [fileInfo, 'foo']

                fileName, contents = fileInfo[0:2]
                if isinstance(contents, filetypes._File):
                    assert(len(fileInfo) == 2)
                else:
                    if len(fileInfo) > 3:
                        if isinstance(fileInfo[3], (list, tuple)):
                            fileReq = fileInfo[3][0]
                            fileProv = fileInfo[3][1]
                        else:
                            fileReq = fileInfo[3]

                    if len(fileInfo) > 2 and fileInfo[2] is not None:
                        fileVersion = self._cvtVersion(fileInfo[2])
                    else:
                        fileVersion = troveVersion

                    contents = RegularFile(requires = fileReq,
                                           provides = fileProv,
                                           contents = contents)
                    contents.version = fileVersion

                cont = componentDir + '/' + fileName
                dir = os.path.dirname(cont)
                if not os.path.exists(dir):
                    util.mkdirChain(dir)

                pathId = contents.pathId
                if pathId is None:
                    pathId = sha1helper.md5String(pathIdSalt + fileName)
                else:
                    pathId += '0' * (16 - len(pathId))
                f = contents.get(pathId)

                f.flags.isSource(isSource)

                if contents.config is not None:
                    f.flags.isConfig(contents.config)
                elif ((setConfigFlags and fileName.startswith('/etc'))
                        or troveName.endswith(':source')):
                    f.flags.isConfig(True)
                index += 1

                if capsule and not (f.flags.isConfig() or
                                getattr(contents, 'isGhost', None)):
                    # RBL-5684: we force ghost files to not be marked as
                    # payload
                    f.flags.isEncapsulatedContent(True)

                if contents.version:
                    fileVersion = self._cvtVersion(contents.version)
                elif (versus and versus.hasFile(pathId) and
                        versus.getFile(pathId)[1] == f.fileId()):
                    # reuse file version if it hasn't changed
                    fileVersion = versus.getFile(pathId)[2]
                else:
                    fileVersion = troveVersion

                if not troveName.endswith(':source'):
                    if fileName[0] != '/':
                        fileName = '/' + fileName

                assert(len(pathId) == 16)
                t.addFile(pathId, fileName, fileVersion, f.fileId())

                if hasattr(contents, 'contents'):
                    fileList.append((f, pathId, contents.contents))
                else:
                    fileList.append((f, pathId, None))

        # find the flavor for this trove; it depends on the flavors of the
        # files
        for f, pathId, contents in fileList:
            flavor.union(f.flavor())
        t.changeFlavor(flavor)

        # create an absolute changeset
        cs = changeset.ChangeSet()

        if existsOkay and repos.hasTrove(troveName, troveVersion, flavor):
            return repos.getTrove(troveName, troveVersion, flavor), None

        if factory is not None:
            t.setFactory(factory)

        if not redirect:
            if isinstance(requires, str):
                req = deps.parseDep(requires)
            else:
                req = requires.copy()

            if isinstance(provides, str):
                prov = deps.parseDep(provides)
            else:
                prov = provides.copy()

            prov.union(deps.parseDep('trove: %s' % t.getName()))

            for f, pathId, contents in fileList:
                req.union(f.requires())
                prov.union(f.provides())

            t.setRequires(req)
            t.setProvides(prov)

        if not troveName.endswith(':source'):
            if not sourceName:
                sourceName = troveName.split(":")[0] + ":source"
            t.setSourceName(sourceName)

        t.computePathHashes()

        t.setBuildTime(buildTime)

        if redirect:
            for toName, toBranch, toFlavor in redirectList:
                t.addRedirect(toName, toBranch, toFlavor)

        if redirect:
            for toName, toBranch, toFlavor in redirectList:
                t.addRedirect(toName, toBranch, toFlavor)

        size = 0
        # add the file and file contents
        for f, pathId, contents in fileList:
            cs.addFile(None, f.fileId(), f.freeze())
            if f.hasContents and not f.flags.isEncapsulatedContent():
                cs.addFileContents(pathId, f.fileId(),
                                   changeset.ChangedFileTypes.file, contents,
                                   f.flags.isConfig())
                size += f.contents.size()
        if metadata:
            if not isinstance(metadata, (tuple, list)):
                metadata = [metadata]
            for item in metadata:
                t.troveInfo.metadata.addItem(item)
        t.setSize(size)
        t.computeDigests()

        diff = t.diff(None, absolute = True)[0]
        cs.newTrove(diff)
        cs.setPrimaryTroveList([t.getNameVersionFlavor()])

        return t, cs
dataset/ETHPy150Open sassoftware/conary/conary_test/rephelp.py/RepositoryHelper.Component/original