def loadTableFor(self, version, table=None): """ cache the parsed contents of the table file. If table is not None, it will be taken as the Table instance representing the already parsed contents; otherwise, the table will be loaded from the table file path. @param version the version of the product to load @param table an instance of Table to accept as the loaded contents """ try: verdata = self.versions[version] if not table: if not utils.isRealFilename(verdata[1]): return if not os.path.exists(verdata[1]): raise TableFileNotFound(verdata[1], self.name, version) prod = self.getProduct(version) table = Table(verdata[1]).expandEupsVariables(prod) self.versions[version] = (verdata[0], verdata[1], table) except KeyError: raise ProductNotFound(self.name, version)
def _read(self, file=None, verbosity=0): """ load data from a file @param file : the file to read the data from. """ if not file: file = self.file fd = open(file) flavor = None lineNo = 0 # line number in input file, for diagnostics for line in fd.readlines(): lineNo += 1 line = line.strip() line = re.sub(r"#.*$", "", line) if not line: continue # # Ignore Group: and End:, but check for needed fields. # # N.b. End is sometimes omitted, so a Group opens a new group # if re.search(r"^(End|Group)\s*:", line): if flavor: if "productDir" not in self.info[flavor]: if verbosity >= 0: print("Warning: Version file has no PROD_DIR for product %s %s %s\n file=%s" % \ (self.name, self.version, flavor, file), file=eups.utils.stdwarn) self.info[flavor]["productDir"] = None if "table_file" not in self.info[flavor]: if verbosity >= 0: print("Warning: Version file has no TABLE_FILE for product %s %s %s\n file=%s" % \ (self.name, self.version, flavor, file), file=eups.utils.stdwarn) self.info[flavor]["table_file"] = "none" tablefile = self.info[flavor]["table_file"] if "ups_dir" not in self.info[flavor] and \ isRealFilename(tablefile): if verbosity >= 0 and \ tablefile != ("%s.table" % self.name) and \ not os.path.isabs(tablefile): print("Warning: Version file has no UPS_DIR for product %s %s %s with TABLE_FILE=%s\n file=%s" % \ (self.name, self.version, flavor, tablefile, file), file=eups.utils.stdwarn) self.info[flavor]["ups_dir"] = "none" continue # # Get key = value # mat = re.search(r"^(\w+)\s*=\s*(.*)", line, re.IGNORECASE) if mat: key = mat.group(1).lower() if key == "prod_dir": key = "productDir" value = re.sub(r"^\"|\"$", "", mat.group(2)) else: raise RuntimeError("Unexpected line \"%s\" at %s:%d" % (line, self.file, lineNo)) # # Check for information about product # if key == "file": if value.lower() != "version": raise RuntimeError('Expected "File = Version"; saw "%s" at %s:%d' % (line, self.file, lineNo)) elif key == "product": if not self.name: self.name = value elif self.name != value: if verbosity >= 0: print("Warning: Unexpected product name, %s, in version file; expected %s,\n file=%s" % \ (value, self.name, file), file=eups.utils.stdwarn) elif key == "version": if not self.version: self.version = value elif self.version != value: if verbosity >= 0: print("Warning: Unexpected version name, %s, for %s in version file; expected %s,\n file=%s" % \ (value, self.name, self.version, file), file=eups.utils.stdwarn) elif key == "flavor": # Now look for flavor-specific blocks flavor = value if flavor not in self.info: self.info[flavor] = {} else: value = re.sub(r"^\"(.*)\"$", r"\1", mat.group(2)) # strip "" if key == "qualifiers": if value: # flavor becomes e.g. Linux:build newflavor = "%s:%s" % (flavor, value) self.info[newflavor] = self.info[flavor] del self.info[flavor] flavor = newflavor else: self.info[flavor][key] = value fd.close()
def addFlavor(self, flavor, installdir = None, tablefile = None, upsdir = None): """ add a flavored version to this file. If an entry for this flavor already exists, it will be modified. @param flavor : the name of the platform flavor to be adding. @param installdir : the installation directory for the new version being added. If None, this package as no install directory. @param tablefile : the path to the table file for this version. If this is relative, then it is assumed to be relative to the upsdir; if upsdir is None, it is assumed to be relative to installdir If None, the product has no tablefile. @param upsdir : the path to the ups directory for this product. If None, a value of "ups" will be assumed. """ if flavor in self.info: # if this flavor already exists, use it to set defaults. info = self.info[flavor] if not installdir and "productDir" in info: installdir = info["productDir"] if not upsdir and "ups_dir" in info: upsdir = info["ups_dir"] if not tablefile and "table_file" in info: tablefile = info["table_file"] info = {} if installdir: installdir = installdir.rstrip('/') info["productDir"] = installdir if tablefile: # regularize upsdir: strip off leading installdir, upsdir if installdir and isRealFilename(installdir) and \ os.path.isabs(tablefile) and \ tablefile.startswith(installdir+'/'): # stripping off installdir tablefile = tablefile[len(installdir)+1:] # look for a ups directory if upsdir != "none": upsdir = os.path.dirname(tablefile) if upsdir: tablefile = os.path.basename(tablefile) else: upsdir = "none" info["table_file"] = tablefile if upsdir: # regularize upsdir: strip off leading installdir upsdir = upsdir.rstrip('/') if installdir and isRealFilename(upsdir) and \ os.path.isabs(upsdir) and upsdir.startswith(installdir+'/'): upsdir = upsdir[len(installdir)+1:] if upsdir is None: upsdir = "none" info["ups_dir"] = upsdir if flavor in self.info: if "declarer" in self.info[flavor]: info["declarer"] = self.info[flavor]["declarer"] if "declared" in self.info[flavor]: info["declared"] = self.info[flavor]["declared"] if "declarer" in info or "declared" in info: # we're modifying info["modifier"] = who info["modified"] = ctimeTZ() else: # we're declaring info["declarer"] = who info["declared"] = ctimeTZ() # now save the info self.info[flavor] = info