def locate_dir(instrument, mode=None): """Locate the instrument specific directory for a reference file.""" if mode is None: mode = config.get_crds_ref_subdir_mode(observatory="hst") else: config.check_crds_ref_subdir_mode(mode) crds_refpath = config.get_crds_refpath("hst") prefix = get_env_prefix(instrument) if mode == "legacy": # Locate cached files at the appropriate CDBS-style iref$ locations try: rootdir = os.environ[prefix] except KeyError: try: rootdir = os.environ[prefix[:-1]] except KeyError: raise KeyError("Reference location not defined for " + repr(instrument) + ". Did you configure " + repr(prefix) + "?") elif mode == "instrument": # use simple names inside CRDS cache. rootdir = os.path.join(crds_refpath, instrument) refdir = os.path.join(crds_refpath, prefix[:-1]) if not os.path.exists(refdir): if config.writable_cache_or_verbose( "Skipping making instrument directory link for", repr(instrument)): log.verbose("Creating legacy cache link", repr(refdir), "-->", repr(rootdir)) utils.ensure_dir_exists(rootdir + "/locate_dir.fits") os.symlink(rootdir, refdir) elif mode == "flat": # use original flat cache structure, all instruments in same directory. rootdir = crds_refpath else: raise ValueError("Unhandled reference file location mode " + repr(mode)) return rootdir
def locate_dir(instrument, mode=None): """Locate the instrument specific directory for a reference file.""" if mode is None: mode = config.get_crds_ref_subdir_mode(observatory="tobs") else: config.check_crds_ref_subdir_mode(mode) crds_refpath = config.get_crds_refpath("tobs") prefix = get_env_prefix(instrument) if mode == "legacy": # Locate cached files at the appropriate CDBS-style iref$ locations try: rootdir = os.environ[prefix] except KeyError: try: rootdir = os.environ[prefix[:-1]] except KeyError: raise KeyError("Reference location not defined for " + repr(instrument) + ". Did you configure " + repr(prefix) + "?") elif mode == "instrument": # use simple names inside CRDS cache. rootdir = os.path.join(crds_refpath, instrument) refdir = os.path.join(crds_refpath, prefix[:-1]) if not os.path.exists(refdir): if config.writable_cache_or_verbose("Skipping making instrument directory link for", repr(instrument)): log.verbose("Creating legacy cache link", repr(refdir), "-->", repr(rootdir)) utils.ensure_dir_exists(rootdir + "/locate_dir.fits") os.symlink(rootdir, refdir) elif mode == "flat": # use original flat cache structure, all instruments in same directory. rootdir = crds_refpath else: raise ValueError("Unhandled reference file location mode " + repr(mode)) return rootdir
def remove_dir(self, instrument): """Remove an instrument cache directory and any associated legacy link.""" if config.writable_cache_or_info("Skipping remove instrument", repr(instrument), "directory."): crds_refpath = config.get_crds_refpath(self.observatory) prefix = self.locator.get_env_prefix(instrument) rootdir = os.path.join(crds_refpath, instrument) refdir = os.path.join(crds_refpath, prefix[:-1]) if len(glob.glob(os.path.join(rootdir, "*"))): log.info("Residual files in '{}'. Not removing.".format(rootdir)) return if os.path.exists(refdir): # skip crds:// vs. oref utils.remove(refdir, observatory=self.observatory) utils.remove(rootdir, observatory=self.observatory)
def locate_file(refname, mode=None): """Given a valid reffilename in CDBS or CRDS format, return a cache path for the file. The aspect of this which is complicated is determining instrument and an instrument specific sub-directory for it based on the filename alone, not the file contents. """ if mode is None: mode = config.get_crds_ref_subdir_mode(observatory="jwst") if mode == "instrument": instrument = utils.file_to_instrument(refname) rootdir = locate_dir(instrument, mode) elif mode == "flat": rootdir = config.get_crds_refpath("jwst") else: raise ValueError("Unhandled reference file location mode " + repr(mode)) return os.path.join(rootdir, os.path.basename(refname))
def locate_dir(instrument, mode=None): """Locate the instrument specific directory for a reference file.""" if mode is None: mode = config.get_crds_ref_subdir_mode(observatory="jwst") else: config.check_crds_ref_subdir_mode(mode) crds_refpath = config.get_crds_refpath("jwst") if mode == "instrument": # use simple names inside CRDS cache. rootdir = os.path.join(crds_refpath, instrument.lower()) if not os.path.exists(rootdir): utils.ensure_dir_exists(rootdir + "/locate_dir.fits") elif mode == "flat": # use original flat cache structure, all instruments in same directory. rootdir = crds_refpath else: raise ValueError("Unhandled reference file location mode " + repr(mode)) return rootdir
def remove(rmpath, observatory): """Wipe out directory at 'rmpath' somewhere in cache for `observatory`.""" if config.writable_cache_or_verbose("Skipped removing", repr(rmpath)): with log.error_on_exception("Failed removing", repr(rmpath)): abs_path = os.path.abspath(rmpath) abs_cache = os.path.abspath(config.get_crds_path()) abs_config = os.path.abspath(config.get_crds_cfgpath(observatory)) abs_references = os.path.abspath(config.get_crds_refpath(observatory)) abs_mappings = os.path.abspath(config.get_crds_mappath(observatory)) abs_pickles = os.path.abspath(config.get_crds_picklepath(observatory)) assert abs_path.startswith((abs_cache, abs_config, abs_references, abs_mappings, abs_pickles)), \ "remove() only works on files in CRDS cache. not: " + repr(rmpath) log.verbose("CACHE removing:", repr(rmpath)) if os.path.isfile(rmpath): os.remove(rmpath) else: pysh.sh("rm -rf ${rmpath}", raise_on_error=True)