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
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
def assignTag(self, tag, productName, version, flavors=None, writeableDB=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 is_string(tag): 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 not writeableDB and tag.isUser(): if not self._getUserTagDb(): raise RuntimeError("Unable to assign user tags (user db not available)") writeableDB = self._getUserTagDb() if writeableDB: pdir = self._productDir(productName, writeableDB) 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()
def assignTag(self, tag, productName, version, flavors=None, writeableDB=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 is_string(tag): 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 not writeableDB and tag.isUser(): if not self._getUserTagDb(): raise RuntimeError( "Unable to assign user tags (user db not available)") writeableDB = self._getUserTagDb() if writeableDB: pdir = self._productDir(productName, writeableDB) 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()