def get_update_map(old_pipeline, updated_rmaps): """Given the name of a pipeline context, `old_pipeline`, and a list of new rmap names, `updated_rmaps`, return the mapping: { imap_name : [ updates_for_that_imap, ... ], ... } Updated rmaps can be rmap names or strings of the form: <instrument>_<filekind>_"n/a" e.g. miri_dflat_n/a """ pctx = crds.get_pickled_mapping(old_pipeline) # reviewed updates = {} for update in sorted(updated_rmaps): if update.endswith(("_n/a", "_N/A")): instrument, _filekind, na = update.split("_") else: # should be an rmap name instrument, _filekind = utils.get_file_properties( pctx.observatory, update) imap_name = pctx.get_imap(instrument).filename if imap_name not in updates: updates[imap_name] = [] assert update not in updates[ imap_name], "Duplicate update for " + repr(update) updates[imap_name].append(update) return updates
def get_affected(self): """Examine the diffs between `old_pmap` and `new_pmap` and return sorted lists of affected instruments and types. Returns { affected_instrument : { affected_type, ... } } """ instrs = defaultdict(set) diffs = self.mapping_diffs() diffs = remove_boring(diffs) for diff in diffs: for step in diff: # Walking down the diff steps 1-by-1 eventually hits an rmap comparison which # will define both instrument and type. pmaps and imaps leave at least one blank. if len(step) == 2 and config.is_mapping(step[0]): instrument, filekind = utils.get_file_properties(self.observatory, step[0]) # This is inefficient since diff doesn't vary by step, but set logic cleans up the redundancy # New rmaps imply reprocessing the entire type. elif isinstance(diff[-1],str) and diff[-1].startswith(("added","deleted")) and \ diff[-1].endswith(".rmap'"): rmap_name = diff[-1].split()[-1].replace("'","") rmapping = rmap.fetch_mapping(rmap_name, ignore_checksum=True) instrument, filekind = rmapping.instrument, rmapping.filekind if instrument.strip() and filekind.strip(): if filekind not in instrs[instrument]: log.verbose("Affected", (instrument, filekind), "based on diff", diff, verbosity=20) instrs[instrument].add(filekind) return { key:list(val) for (key, val) in instrs.items() }
def get_affected(self): """Examine the diffs between `old_pmap` and `new_pmap` and return sorted lists of affected instruments and types. Returns { affected_instrument : { affected_type, ... } } """ instrs = defaultdict(set) diffs = self.mapping_diffs() diffs = remove_boring(diffs) for diff in diffs: for step in diff: # Walking down the diff steps 1-by-1 eventually hits an rmap comparison which # will define both instrument and type. pmaps and imaps leave at least one blank. if len(step) == 2 and rmap.is_mapping(step[0]): instrument, filekind = utils.get_file_properties(self.observatory, step[0]) # This is inefficient since diff doesn't vary by step, but set logic cleans up the redundancy # New rmaps imply reprocessing the entire type. elif isinstance(diff[-1],str) and diff[-1].startswith(("added","deleted")) and \ diff[-1].endswith(".rmap'"): rmap_name = diff[-1].split()[-1].replace("'","") rmapping = rmap.fetch_mapping(rmap_name, ignore_checksum=True) instrument, filekind = rmapping.instrument, rmapping.filekind if instrument.strip() and filekind.strip(): if filekind not in instrs[instrument]: log.verbose("Affected", (instrument, filekind), "based on diff", diff, verbosity=20) instrs[instrument].add(filekind) return { key:list(val) for (key, val) in instrs.items() }
def get_update_map(old_pipeline, updated_rmaps): """Given the name of a pipeline context, `old_pipeline`, and a list of new rmap names, `updated_rmaps`, return the mapping: { imap_name : [ updates_for_that_imap, ... ], ... } Updated rmaps can be rmap names or strings of the form: <instrument>_<filekind>_"n/a" e.g. miri_dflat_n/a """ pctx = crds.get_pickled_mapping(old_pipeline) # reviewed updates = {} for update in sorted(updated_rmaps): if update.endswith(("_n/a","_N/A")): instrument, _filekind, na = update.split("_") else: # should be an rmap name instrument, _filekind = utils.get_file_properties(pctx.observatory, update) imap_name = pctx.get_imap(instrument).filename if imap_name not in updates: updates[imap_name] = [] assert update not in updates[imap_name], "Duplicate update for " + repr(update) updates[imap_name].append(update) return updates
def instrument_filekind(self, filename): """Return the instrument and filekind of `filename` as a space separated string.""" instrument, filekind = utils.get_file_properties(self.observatory, filename) return instrument + " " + filekind