def declare(self, product): """ declare the given product. If a table file is not specified, a default one will be searched for (in the ups subdirectory of the install directory). @param product : the Product instance to register @throws UnderSpecifiedProduct if the name, version, and flavor are not all set """ if not isinstance(product, Product): raise RuntimeError("Database.declare(): argument not a Product:" + product) if not product.name or not product.version or not product.flavor: raise UnderSpecifiedProduct( msg="Product not fully specified: %s %s %s" % (str(product.name), str(product.version), str(product.flavor))) prod = product.clone().canonicalizePaths() tablefile = prod.tablefile if not tablefile: tablefile = prod.tableFileName() if not tablefile or not os.path.exists(tablefile): raise TableFileNotFound( prod.name, prod.version, prod.flavor, msg="Unable to located a table file in default location: " + tablefile) # set the basic product information pdir = self._productDir(prod.name) vfile = self._versionFileInDir(pdir, prod.version) versionFile = VersionFile(vfile, prod.name, prod.version) versionFile.addFlavor(prod.flavor, prod.dir, tablefile, prod.ups_dir) # seal the deal if not os.path.exists(pdir): os.mkdir(pdir) if prod.dir: trimDir = prod.stackRoot() if trimDir and not os.path.exists(trimDir): trimDir = None versionFile.write(trimDir) # now assign any tags for tag in prod.tags: self.assignTag(tag, prod.name, prod.version, prod.flavor)
def declare(self, product): """ declare the given product. If a table file is not specified, a default one will be searched for (in the ups subdirectory of the install directory). @param product : the Product instance to register @throws UnderSpecifiedProduct if the name, version, and flavor are not all set """ if not isinstance(product, Product): raise RuntimeError("Database.declare(): argument not a Product:" + product) if not product.name or not product.version or not product.flavor: raise UnderSpecifiedProduct( msg="Product not fully specified: %s %s %s" % (str(product.name), str(product.version), str(product.flavor)) ) prod = product.clone().canonicalizePaths() tablefile = prod.tablefile if not tablefile: tablefile = prod.tableFileName() if not tablefile or not os.path.exists(tablefile): raise TableFileNotFound(prod.name, prod.version, prod.flavor, msg="Unable to located a table file in default location: " + tablefile) # set the basic product information pdir = self._productDir(prod.name) vfile = self._versionFileInDir(pdir, prod.version) versionFile = VersionFile(vfile, prod.name, prod.version) versionFile.addFlavor(prod.flavor, prod.dir, tablefile, prod.ups_dir) # seal the deal if not os.path.exists(pdir): os.mkdir(pdir) if prod.dir: trimDir = prod.stackRoot() if trimDir and not os.path.exists(trimDir): trimDir = None versionFile.write(trimDir) # now assign any tags for tag in prod.tags: self.assignTag(tag, prod.name, prod.version, prod.flavor)
def undeclare(self, product): """ undeclare the given Product. Only the name, version, and flavor will be paid attention to. False is returned if the product was not found in the database. @param product : the Product instance to undeclare. @return bool : False if nothing was undeclared @throws UnderSpecifiedProduct if the name, version, and flavor are not all set """ if not isinstance(product, Product): raise RuntimeError("Database.declare(): argument not a Product: " + product) if not product.name or not product.version or not product.flavor: raise UnderSpecifiedProduct( msg="Product not fully specified: %s %s %s" % (str(product.name), str(product.version), str(product.flavor)) ) pdir = self._productDir(product.name) vfile = self._versionFileInDir(pdir, product.version) if not os.path.exists(vfile): return False versionFile = VersionFile(vfile) if versionFile.hasFlavor(product.flavor): # unassign tags associated with this product tags = self.findTags(product.name, product.version, product.flavor) for tag in tags: self.unassignTag(tag, product.name, product.flavor) changed = versionFile.removeFlavor(product.flavor) if changed: versionFile.write() # do a little clean up: if we got rid of the version file, try # deleting the directory if not os.path.exists(vfile): try: os.rmdir(pdir) except: pass return changed
def undeclare(self, product): """ undeclare the given Product. Only the name, version, and flavor will be paid attention to. False is returned if the product was not found in the database. @param product : the Product instance to undeclare. @return bool : False if nothing was undeclared @throws UnderSpecifiedProduct if the name, version, and flavor are not all set """ if not isinstance(product, Product): raise RuntimeError("Database.declare(): argument not a Product: " + product) if not product.name or not product.version or not product.flavor: raise UnderSpecifiedProduct( msg="Product not fully specified: %s %s %s" % (str(product.name), str(product.version), str(product.flavor))) pdir = self._productDir(product.name) vfile = self._versionFileInDir(pdir, product.version) if not os.path.exists(vfile): return False versionFile = VersionFile(vfile) if versionFile.hasFlavor(product.flavor): # unassign tags associated with this product tags = self.findTags(product.name, product.version, product.flavor) for tag in tags: self.unassignTag(tag, product.name, product.flavor) changed = versionFile.removeFlavor(product.flavor) if changed: versionFile.write() # do a little clean up: if we got rid of the version file, try # deleting the directory if not os.path.exists(vfile): try: os.rmdir(pdir) except: pass return changed