コード例 #1
0
    def getTagAssignments(self, productName, glob=True, user=True):
        """
        return a list of tuples of the form (tag, version, flavor) listing
        all of the tags assigned to the product.
        @param productName     the name of the product
        @param glob            if true (default), include the global tags
        @param user            if true (default), include the user tags
        """
        out = []
        loc = [None, None]
        if glob: loc[0] = self._productDir(productName)
        if user and self._getUserTagDb():
            loc[1] = self._productDir(productName, self._getUserTagDb())

        tgroup = ""
        for i in xrange(len(loc)):
            if not loc[i]: continue
            if i > 0:
                tgroup = "user:"
                if not os.path.exists(loc[i]):
                    continue

            for file in os.listdir(loc[i]):
                mat = tagFileRe.match(file)
                if mat:
                    tag = mat.group(1)
                    file = ChainFile(os.path.join(loc[i], file), productName,
                                     tag)
                    for flavor in file.getFlavors():
                        vers = file.getVersion(flavor)
                        out.append((tgroup + tag, vers, flavor))

        return out
コード例 #2
0
ファイル: Database.py プロジェクト: jhoblitt/eups
    def getTagAssignments(self, productName, glob=True, user=True):
        """
        return a list of tuples of the form (tag, version, flavor) listing
        all of the tags assigned to the product.
        @param productName     the name of the product
        @param glob            if true (default), include the global tags
        @param user            if true (default), include the user tags
        """
        out = []
        loc = [None, None]
        if glob:  loc[0] = self._productDir(productName) 
        if user and self._getUserTagDb():
            loc[1] = self._productDir(productName, self._getUserTagDb())

        tgroup = ""
        for i in xrange(len(loc)):
            if not loc[i]: continue
            if i > 0:  
                tgroup = "user:"
                if not os.path.exists(loc[i]):
                    continue

            for file in os.listdir(loc[i]):
                mat = tagFileRe.match(file)
                if mat: 
                    tag = mat.group(1)
                    file = ChainFile(os.path.join(loc[i],file), productName,tag)
                    for flavor in file.getFlavors():
                        vers = file.getVersion(flavor)
                        out.append( (tgroup+tag, vers, flavor) )

        return out
コード例 #3
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()
コード例 #4
0
ファイル: Database.py プロジェクト: jhoblitt/eups
    def unassignTag(self, tag, productNames, flavors=None):
        """
        unassign a tag from a product

        @param tag :          the tag to unassign
        @param productNames : the names of the products to deassign the 
                                 tag for.  This can be given as a single 
                                 string (for a single product) or as a list
                                 of product names.  If None, the tag will 
                                 be deassigned from all products.  
        @param flavors :      the flavors of the product to deassign tag for.  
                                 If None, deassign the tag for all available 
                                 flavors.
        @return bool : False if tag was not assigned to any of the products.
        """
        dbroot = self.dbpath
        if tag.startswith("user:"******"user:"******"No products names given: " + str(productNames))
        if not isinstance(productNames, list):
            productNames = [productNames]
        if flavors is not None and not isinstance(flavors, list):
            flavors = [flavors]

        unassigned = False
        for prod in productNames:
            tfile = self._tagFileInDir(self._productDir(prod,dbroot), tag)
            if not os.path.exists(tfile):
                continue

            if flavors is None:
                # remove all flavors
                os.remove(tfile)
                unassigned = True
                continue

            tf = ChainFile(tfile)
            changed = False
            for flavor in flavors:
                if tf.removeVersion(flavor):
                    changed = True

            if changed:
                tf.write()
                unassigned = True

        return unassigned
コード例 #5
0
    def unassignTag(self, tag, productNames, flavors=None):
        """
        unassign a tag from a product

        @param tag :          the tag to unassign
        @param productNames : the names of the products to deassign the 
                                 tag for.  This can be given as a single 
                                 string (for a single product) or as a list
                                 of product names.  If None, the tag will 
                                 be deassigned from all products.  
        @param flavors :      the flavors of the product to deassign tag for.  
                                 If None, deassign the tag for all available 
                                 flavors.
        @return bool : False if tag was not assigned to any of the products.
        """
        dbroot = self.dbpath
        if tag.startswith("user:"******"user:"******"No products names given: " + str(productNames))
        if not isinstance(productNames, list):
            productNames = [productNames]
        if flavors is not None and not isinstance(flavors, list):
            flavors = [flavors]

        unassigned = False
        for prod in productNames:
            tfile = self._tagFileInDir(self._productDir(prod, dbroot), tag)
            if not os.path.exists(tfile):
                continue

            if flavors is None:
                # remove all flavors
                os.remove(tfile)
                unassigned = True
                continue

            tf = ChainFile(tfile)
            changed = False
            for flavor in flavors:
                if tf.removeVersion(flavor):
                    changed = True

            if changed:
                tf.write()
                unassigned = True

        return unassigned
コード例 #6
0
    def getChainFile(self, tag, productName, searchUserDB=False):
        """
        return the ChainFile for the version name of the product that has the given tag assigned
        to it.  None is return if the tag is not assigned to any version.
        ProductNotFound is raised if no version of the product is declared.
        @param tag          the string name for the tag.  A user tag must be
                              prepended by a "user:"******"""
        pdir = self._productDir(productName)
        if not os.path.exists(pdir):
            raise ProductNotFound(productName, stack=self.dbpath)

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

        pdirs = []
        if searchUserDB and tag.isUser():
            for d in self._getUserTagDb(values=True):
                if d:
                    pdirs.append(self._productDir(productName, d))
        else:
            pdirs.append(pdir)

        for pdir in pdirs:
            tfile = self._tagFileInDir(pdir, tag.name)
            if os.path.exists(tfile):
                return ChainFile(tfile)

        return None
コード例 #7
0
ファイル: Database.py プロジェクト: jhoblitt/eups
    def _findTagsInDir(self, dir, productName, version, flavor):
        # look tag assignments via chain files in a given directory

        tagFiles = filter(lambda x: not x.startswith('.'), os.listdir(dir))
        
        tags = []
        for file in tagFiles:
            mat = tagFileRe.match(file)
            if not mat:
                continue

            tag = mat.group(1)
            cf = ChainFile(os.path.join(dir,file), productName, tag)
            if cf.getVersion(flavor) == version:
                tags.append(tag)

        return tags
コード例 #8
0
    def _findTagsInDir(self, dir, productName, version, flavor):
        # look tag assignments via chain files in a given directory

        tagFiles = filter(lambda x: not x.startswith('.'), os.listdir(dir))

        tags = []
        for file in tagFiles:
            mat = tagFileRe.match(file)
            if not mat:
                continue

            tag = mat.group(1)
            cf = ChainFile(os.path.join(dir, file), productName, tag)
            if cf.getVersion(flavor) == version:
                tags.append(tag)

        return tags
コード例 #9
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()