예제 #1
0
파일: Database.py 프로젝트: jhoblitt/eups
    def findFlavors(self, productName, versions=None):
        """
        return a list of flavors supported for the given product.  An 
        empty list is returned if the product is not declared or the 
        given version is not declared.

        @param productName : the name of the product to fine
        @param versions :    the versions to search for.  If None, all 
                                  versions will be considered.
        @return string[] :
        """
        if versions is None:
            versions = self.findVersions(productName)

        if not isinstance(versions, list):
            versions = [versions]

        out = []
        for version in versions:
            vfile = self._versionFile(productName, version)
            vfile = VersionFile(vfile, productName, version)
            flavors = vfile.getFlavors()
            for f in flavors:
                if f not in out:  out.append(f)

        return out
예제 #2
0
    def findFlavors(self, productName, versions=None):
        """
        return a list of flavors supported for the given product.  An 
        empty list is returned if the product is not declared or the 
        given version is not declared.

        @param productName : the name of the product to fine
        @param versions :    the versions to search for.  If None, all 
                                  versions will be considered.
        @return string[] :
        """
        if versions is None:
            versions = self.findVersions(productName)

        if not isinstance(versions, list):
            versions = [versions]

        out = []
        for version in versions:
            vfile = self._versionFile(productName, version)
            vfile = VersionFile(vfile, productName, version)
            flavors = vfile.getFlavors()
            for f in flavors:
                if f not in out: out.append(f)

        return out
예제 #3
0
    def assignTag(self, tag, productName, version, flavors=None):
        """
        assign a tag to a given product.

        @param tag :         the name of the tag to assign.  If the name is 
                               prepended with the "user:"******"""

        if isinstance(tag, str):
            tag = eups.tags.Tag(tag)

        vf = VersionFile(self._versionFile(productName, version))
        declaredFlavors = vf.getFlavors()
        if len(declaredFlavors) == 0:
            raise ProductNotFound(productName, version)

        if flavors is None:
            flavors = list(declaredFlavors)
        elif not isinstance(flavors, list):
            flavors = [flavors]
        else:
            flavors = list(flavors)  # make a copy; we're gonna mess with it
        if len(flavors) == 0:
            flavors = list(declaredFlavors)

        # reduce the list of flavors to ones actually declared
        for i in xrange(len(flavors)):
            flavor = flavors.pop(0)
            if flavor in declaredFlavors and flavor not in flavors:
                flavors.append(flavor)
        if len(flavors) == 0:
            raise ProductNotFound(
                productName,
                version,
                msg="Requested flavors not declared for %s %s" %
                (productName, version))

        if tag.isUser():
            if not self._getUserTagDb():
                raise RuntimeError(
                    "Unable to assign user tags (user db not available)")

            pdir = self._productDir(productName, self._getUserTagDb())
            if not os.path.exists(pdir):
                os.makedirs(pdir)
        else:
            pdir = self._productDir(productName)

        tfile = self._tagFileInDir(pdir, tag.name)
        tagFile = ChainFile(tfile, productName, tag.name)

        tagFile.setVersion(version, flavors)
        tagFile.write()
예제 #4
0
파일: Database.py 프로젝트: jhoblitt/eups
    def assignTag(self, tag, productName, version, flavors=None):
        """
        assign a tag to a given product.

        @param tag :         the name of the tag to assign.  If the name is 
                               prepended with the "user:"******"""

        if isinstance(tag, str):
            tag = eups.tags.Tag(tag)

        vf = VersionFile(self._versionFile(productName, version))
        declaredFlavors = vf.getFlavors()
        if len(declaredFlavors) == 0:
            raise ProductNotFound(productName, version)

        if flavors is None:
            flavors = list(declaredFlavors)
        elif not isinstance(flavors, list):
            flavors = [flavors]
        else:
            flavors = list(flavors)  # make a copy; we're gonna mess with it
        if len(flavors) == 0:
            flavors = list(declaredFlavors)

        # reduce the list of flavors to ones actually declared
        for i in xrange(len(flavors)):
            flavor = flavors.pop(0)
            if flavor in declaredFlavors and flavor not in flavors:
                flavors.append(flavor)
        if len(flavors) == 0:
            raise ProductNotFound(productName, version, 
                               msg="Requested flavors not declared for %s %s"
                                   % (productName, version))

        if tag.isUser():
            if not self._getUserTagDb():
                raise RuntimeError("Unable to assign user tags (user db not available)")

            pdir = self._productDir(productName, self._getUserTagDb())
            if not os.path.exists(pdir):
                os.makedirs(pdir)
        else:
            pdir = self._productDir(productName)
        
        tfile = self._tagFileInDir(pdir, tag.name)
        tagFile = ChainFile(tfile, productName, tag.name)

        tagFile.setVersion(version, flavors)
        tagFile.write()
예제 #5
0
파일: Database.py 프로젝트: jhoblitt/eups
    def findProducts(self, name, versions=None, flavors=None):
        """
        return a list of Products matching the given inputs

        @param name :     the name of the desired product
        @param versions : the desired versions.  If versions is None, 
                            return all declared versions of the product.
        @param flavors :  the desired flavors.  If None, return matching 
                            products of all declared flavors.
        @return Product[] : a list of the matching products
        """
        if versions is None:
            versions = self.findVersions(name)

        if not isinstance(versions, list):
            versions = [versions]

        if flavors is not None and not isinstance(flavors, list):
            flavors = [flavors]

        out = {}
        for vers in versions:
            vfile = self._versionFile(name, vers)
            if not os.path.exists(vfile):
                continue
            vfile = VersionFile(vfile, name, vers)
                                
            flavs = flavors
            declared = vfile.getFlavors()
            if flavs is None:  flavs = declared
            out[vers] = {}
            for f in flavs:
                if f in declared:
                    out[vers][f] = vfile.makeProduct(f, self.defStackRoot, 
                                                     self.dbpath)

        if len(out.keys()) == 0:
            return []

        pdir = self._productDir(name)
        if not os.path.exists(pdir):
          raise RuntimeError("programmer error: product directory disappeared")

        # add in the tags 
        for tag, vers, flavor in self.getTagAssignments(name):
            try: 
                out[vers][flavor].tags.append(tag)
            except KeyError:
                pass

#  not sure why this doesn't work:
#        out = reduce(lambda x,y: x.extend(y), 
#                     map(lambda z:  z.values(), out.values()))
#        out.sort(_cmp_by_verflav)
#
#  replaced with moral equivalent:
#                          
        v = map(lambda z:  z.values(), out.values())
        x = v[0]
        for y in v[1:]:  x.extend(y)
        x.sort(_cmp_by_verflav)
        return x
예제 #6
0
    def findProducts(self, name, versions=None, flavors=None):
        """
        return a list of Products matching the given inputs

        @param name :     the name of the desired product
        @param versions : the desired versions.  If versions is None, 
                            return all declared versions of the product.
        @param flavors :  the desired flavors.  If None, return matching 
                            products of all declared flavors.
        @return Product[] : a list of the matching products
        """
        if versions is None:
            versions = self.findVersions(name)

        if not isinstance(versions, list):
            versions = [versions]

        if flavors is not None and not isinstance(flavors, list):
            flavors = [flavors]

        out = {}
        for vers in versions:
            vfile = self._versionFile(name, vers)
            if not os.path.exists(vfile):
                continue
            vfile = VersionFile(vfile, name, vers)

            flavs = flavors
            declared = vfile.getFlavors()
            if flavs is None: flavs = declared
            out[vers] = {}
            for f in flavs:
                if f in declared:
                    out[vers][f] = vfile.makeProduct(f, self.defStackRoot,
                                                     self.dbpath)

        if len(out.keys()) == 0:
            return []

        pdir = self._productDir(name)
        if not os.path.exists(pdir):
            raise RuntimeError(
                "programmer error: product directory disappeared")

        # add in the tags
        for tag, vers, flavor in self.getTagAssignments(name):
            try:
                out[vers][flavor].tags.append(tag)
            except KeyError:
                pass


#  not sure why this doesn't work:
#        out = reduce(lambda x,y: x.extend(y),
#                     map(lambda z:  z.values(), out.values()))
#        out.sort(_cmp_by_verflav)
#
#  replaced with moral equivalent:
#
        v = map(lambda z: z.values(), out.values())
        x = v[0]
        for y in v[1:]:
            x.extend(y)
        x.sort(_cmp_by_verflav)
        return x