def locate_file(self, filename): """Return the full path for `filename` implementing default CRDS file cache location behavior, and verifying that the resulting path is safe. """ path = config.locate_file(filename, self.observatory) config.check_path(path) # check_path returns abspath, bad for listsings. return path
def locate_file(self, filename): """Locate file defines how members of the self.args.files list are located. The default behavior is to locate CRDS cached files, either references or mappings. This is inappropriate for datasets so in some cases locate_file needs to be overridden. Symbolic context names, e.g. hst-operatonal, resolved to literal contexts, e.g. hst_0320.pmap """ filename = config.pop_crds_uri(filename) # nominally crds:// return config.locate_file(self.resolve_context(filename), observatory=self.observatory)
def locate_file(self, filename): """Locate file defines how members of the self.args.files list are located. The default behavior is to locate CRDS cached files, either references or mappings. This is inappropriate for datasets so in some cases locate_file needs to be overridden. Symbolic context names, e.g. hst-operatonal, resolved to literal contexts, e.g. hst_0320.pmap """ filename = config.pop_crds_uri(filename) # nominally crds:// return config.locate_file(self.resolve_context(filename), observatory=self.observatory)
def locate_file(self, filename): """Return the full path for `filename` implementing default CRDS file cache location behavior, and verifying that the resulting path is safe. """ path = config.locate_file(filename, self.observatory) config.check_path( path) # check_path returns abspath, bad for listsings. return path
def locate_file_outside_cache(self, filename): """This is essentially normal filename syntax, except crds:// is interpreted to mean locate filename inside the CRDS cache. symbolic context names are also resolved to literal context filenames. """ filename2 = config.pop_crds_uri(filename) # nominally crds:// filename2 = self.resolve_context(filename2) # e.g. hst-operational --> hst_0320.pmap if filename != filename2: # Had crds:// or was date based copnt return config.locate_file(filename2, self.observatory) else: return os.path.abspath(filename2)
def locate_file_outside_cache(self, filename): """This is essentially normal filename syntax, except crds:// is interpreted to mean locate filename inside the CRDS cache. symbolic context names are also resolved to literal context filenames. """ filename2 = config.pop_crds_uri(filename) # nominally crds:// filename2 = self.resolve_context(filename2) # e.g. hst-operational --> hst_0320.pmap if filename != filename2: # Had crds:// or was date based copnt return config.locate_file(filename2, self.observatory) else: return os.path.abspath(filename2)
def test_sync_contexts(self): self.run_script("crds.sync --contexts hst_cos.imap") for name in crds.get_cached_mapping("hst_cos.imap").mapping_names(): self.assert_crds_exists(name) self.run_script("crds.sync --contexts hst_cos_deadtab.rmap --fetch-references") for name in crds.get_cached_mapping("hst_cos_deadtab.rmap").reference_names(): self.assert_crds_exists(name) with open(config.locate_file(name, "hst"), "w+") as handle: handle.write("foo") self.run_script("crds.sync --contexts hst_cos_deadtab.rmap --fetch-references --check-files", 2) self.run_script("crds.sync --contexts hst_cos_deadtab.rmap --fetch-references --check-files --repair-files", 2) self.run_script("crds.sync --contexts hst_cos_deadtab.rmap --fetch-references --check-files --repair-files") self.run_script("crds.sync --contexts hst_cos_deadtab.rmap --fetch-references --check-files --repair-files --check-sha1sum")
def get_cache_path(context, reftype, error_on_missing=True): """ Fetch the full path to the single reference file of reftype. """ context = rmap.asmapping(context) imap = context.get_imap(SYNPHOT_INSTRUMENT) mapping = imap.get_rmap(reftype) filenames = mapping.reference_names() if len(filenames) == 0 and not error_on_missing: return None if len(filenames) != 1: raise RuntimeError( "Expected '{}' rmap to contain one reference file".format(reftype)) filename = filenames[0] return config.locate_file(filename, observatory="hst")
def _build_compname_to_path(self, reftype, delivered_files): """ Build a map of component names to filesystem paths, using freshly delivered files by preference. """ result = {} for file in delivered_files: with fits.open(file) as hdul: # A significant minority of existing files have uppercase COMPNAME, # enough that it's not worthwhile to redeliver them all. result[hdul[0].header["COMPNAME"].lower()] = file mapping = self.imap.get_rmap(reftype) # This is a tad brittle, in that it assumes that the COMPNAME parkey # will occupy the first position. for key, filename in mapping.selector.todict()["selections"]: compname = key[0].lower() if not compname in result: result[compname] = config.locate_file(filename, "hst") return result
def assert_crds_not_exists(self, filename, observatory="hst"): self.assertFalse(os.path.exists(config.locate_file(filename, observatory)))
def locate(self, name): """Return the standard CRDS cache location for file `name`.""" return config.locate_file(name, observatory=self.observatory)
def assert_crds_not_exists(self, filename, observatory="hst"): self.assertFalse( os.path.exists(config.locate_file(filename, observatory)))
def get_file_properties(observatory, filename): """Return instrument,filekind fields associated with filename.""" path = config.locate_file(filename, observatory) return get_locator_module(observatory).get_file_properties(path)