Пример #1
0
    def _dump_and_vet_mappings(self, mappings):
        """Ensure all mapping files listed in `mappings` are in the CRDS cache.

        Returns  (list(useable_contexts), list(mappings_closures))
        """
        log.verbose("Getting and checking specified mappings.", verbosity=55)

        # Based on the specified mappings,  identify the  mappings they refer to
        mapping_closure = set()
        for mapping in mappings:
            with log.warn_on_exception("Failed loading context", repr(mapping)):
                try:
                    loadable = rmap.get_cached_mapping(mapping)
                    loadable_names = loadable.mapping_names()
                except Exception as exc:
                    log.verbose("Failed loading", repr(mapping),
                                "using API call to get mapping names", str(exc))
                    loadable_names = api.get_mapping_names(mapping)
                mapping_closure |= set(loadable_names)

        # Dump all missing files in one call
        with log.verbose_warning_on_exception("Mapping closure download failed"):
            self.dump_files(self.default_context, mapping_closure)

        # After attempting to sync,  identify which mappings are actually loadable now.
        useable_contexts = []
        for mapping in mappings:
            with log.warn_on_exception("Failed loading", repr(mapping)):
                _loaded = rmap.get_cached_mapping(mapping)
                useable_contexts.append(mapping)

        return sorted(useable_contexts), sorted(mapping_closure)
Пример #2
0
def mapping_names(context):
    """Return the full set of mapping names associated with `context`,  compute locally if possible,
    else consult server.
    """
    try:
        mapping = get_symbolic_mapping(context)
        contained_mappings = mapping.mapping_names()
    except Exception:
        contained_mappings = api.get_mapping_names(context)
    return set(contained_mappings)
Пример #3
0
def mapping_names(context):
    """Return the full set of mapping names associated with `context`,  compute locally if possible,
    else consult server.
    """
    try:
        mapping = crds.get_cached_mapping(context)
        contained_mappings = mapping.mapping_names()
    except IOError:
        contained_mappings = api.get_mapping_names(context)
    return set(contained_mappings)
Пример #4
0
    def get_context_mappings(self):
        """Return the set of mappings which are pointed to by the mappings
        in `self.contexts`.
        """
        files = set()
        useable_contexts = []
        if not self.contexts:
            return []
        log.verbose("Getting all mappings for specified contexts.",
                    verbosity=55)
        if self.args.all:
            files = self._list_mappings("*.*map")
            pmaps = self._list_mappings("*.pmap")
            useable_contexts = []
            if pmaps and files:
                with log.warn_on_exception("Failed dumping mappings for",
                                           repr(self.contexts)):
                    self.dump_files(pmaps[-1], files)
            for context in self.contexts:
                with log.warn_on_exception("Failed loading context",
                                           repr(context)):
                    pmap = rmap.get_cached_mapping(context)
                    useable_contexts.append(context)
        else:
            for context in self.contexts:
                with log.warn_on_exception("Failed listing mappings for",
                                           repr(context)):
                    try:
                        pmap = rmap.get_cached_mapping(context)
                        files |= set(pmap.mapping_names())
                    except Exception:
                        files |= set(api.get_mapping_names(context))
                    useable_contexts.append(context)
            useable_contexts = sorted(useable_contexts)
            if useable_contexts and files:
                with log.warn_on_exception("Failed dumping mappings for",
                                           repr(self.contexts)):
                    self.dump_files(useable_contexts[-1], files)

        self.contexts = useable_contexts  # XXXX reset self.contexts
        files = sorted(files)
        log.verbose("Got mappings from specified (usable) contexts: ",
                    files,
                    verbosity=55)
        return files
Пример #5
0
    def get_context_mappings(self):
        """Return the set of mappings which are pointed to by the mappings
        in `self.contexts`.
        """
        files = set()
        useable_contexts = []
        if not self.contexts:
            return []
        log.verbose("Getting all mappings for specified contexts.", verbosity=55)
        if self.args.all:
            files = self._list_mappings("*.*map")
            pmaps = self._list_mappings("*.pmap")
            useable_contexts = []
            if pmaps and files:
                with log.warn_on_exception("Failed dumping mappings for", repr(self.contexts)):
                    self.dump_files(pmaps[-1], files)
            for context in self.contexts:
                with log.warn_on_exception("Failed loading context", repr(context)):
                    pmap = crds.get_cached_mapping(context)
                    useable_contexts.append(context)
        else:
            for context in self.contexts:
                with log.warn_on_exception("Failed listing mappings for", repr(context)):
                    try:
                        pmap = crds.get_cached_mapping(context)
                        files |= set(pmap.mapping_names())
                    except Exception:
                        files |= set(api.get_mapping_names(context))
                    useable_contexts.append(context)
            useable_contexts = sorted(useable_contexts)
            if useable_contexts and files:
                with log.warn_on_exception("Failed dumping mappings for", repr(self.contexts)):
                    self.dump_files(useable_contexts[-1], files)

        self.contexts = useable_contexts  # XXXX reset self.contexts
        files = sorted(files)
        log.verbose("Got mappings from specified (usable) contexts: ", files, verbosity=55)
        return files