Example #1
0
def get_all_app_info(tag, user, nms_url, catalog_url):
    if tag not in ["release", "beta", "dev"]:
        raise ValueError("tag must be one of 'release', 'beta', or 'dev'")
    nms = NarrativeMethodStore(nms_url)
    catalog = Catalog(catalog_url)
    apps = nms.list_methods({"tag": tag})
    app_infos = {}
    module_versions = {}
    for a in apps:
        # ignore empty apps or apps in IGNORE_CATEGORIES
        if not a or not set(a.get('categories')).isdisjoint(IGNORE_CATEGORIES):
            continue
        # add short version of input/output types
        for target_type in ['input_types', 'output_types']:
            a['short_{}'.format(target_type)] = _shorten_types(
                a.get(target_type))
        app_infos[a["id"].lower()] = {"info": a}
        if "module_name" in a:
            module_versions[a["module_name"].lower()] = a.get("ver")

    favorites = catalog.list_favorites(user)

    for fav in favorites:
        app_id = fav["module_name_lc"] + "/" + fav["id"]
        if app_id in app_infos:
            app_infos[app_id]["favorite"] = fav["timestamp"]

    return {"module_versions": module_versions, "app_infos": app_infos}
    def _get_app_metadata(self, nb, nms_url: str) -> dict:
        """
        Returns a structure containing app metadata and citations.
        {
            meta: str,
            citations: [{
                heading: "Released Apps" (some readable str, not just "dev"),
                app_list: {
                    app_name_1: [{
                        link: 'some link',
                        display_text: 'publication_text'
                    }],
                    app_name_2: [{
                        link: 'some other link',
                        display_text: 'other publication'
                    }]
                }
            }]
        }
        """
        # will be tag -> app_id
        apps = defaultdict(set)
        for cell in nb.cells:
            if 'kbase' in cell.metadata:
                kb_meta = cell.metadata.get('kbase', {})
                if kb_meta.get('type') == 'app' and "app" in kb_meta:
                    apps[kb_meta["app"].get("tag",
                                            "dev")].add(kb_meta["app"]["id"])

        citations = defaultdict(dict)
        app_names = set()  # the "metadata" is just a list of unique app names.
        nms = NarrativeMethodStore(url=nms_url)
        for tag in apps:
            nms_inputs = {"ids": list(apps[tag]), "tag": tag}

            try:
                app_infos = nms.get_method_full_info(nms_inputs)
            except Exception as e:
                app_infos = []
            for info in app_infos:
                app_names.add(info["name"])
                if "publications" in info:
                    citations[tag][info["name"]] = info["publications"]

        parsed_citations = list()
        tag_map = {
            "release": "Released Apps",
            "beta": "Apps in Beta",
            "dev": "Apps in development"
        }
        for tag in ["release", "beta", "dev"]:
            if tag in citations:
                parsed_citations.append({
                    "heading": tag_map[tag],
                    "app_list": citations[tag]
                })
        return {
            "citations": parsed_citations,
            "meta": ", ".join(sorted(app_names))
        }
Example #3
0
    def _fetchNarrativeObjects(self, workspaceName, cells, parameters,
                               includeIntroCell, title):
        if not cells:
            cells = []
        if not title:
            title = 'Untitled'

        # fetchSpecs
        appSpecIds = []
        methodSpecIds = []
        specMapping = {'apps': {}, 'methods': {}}
        for cell in cells:
            if 'app' in cell:
                appSpecIds.append(cell['app'])
            elif 'method' in cell:
                methodSpecIds.append(cell['method'])
        nms = NarrativeMethodStore(self.narrativeMethodStoreURL)
        if len(appSpecIds) > 0:
            appSpecs = nms.get_app_spec({'ids': appSpecIds})
            for spec in appSpecs:
                spec_id = spec['info']['id']
                specMapping['apps'][spec_id] = spec
        if len(methodSpecIds) > 0:
            methodSpecs = nms.get_method_spec({'ids': methodSpecIds})
            for spec in methodSpecs:
                spec_id = spec['info']['id']
                specMapping['methods'][spec_id] = spec
        # end of fetchSpecs

        metadata = {
            'job_ids': {
                'methods': [],
                'apps': [],
                'job_usage': {
                    'queue_time': 0,
                    'run_time': 0
                }
            },
            'format': 'ipynb',
            'creator': self.user_id,
            'ws_name': workspaceName,
            'name': title,
            'type': 'KBaseNarrative.Narrative',
            'description': '',
            'data_dependencies': []
        }
        cellData = self._gatherCellData(cells, specMapping, parameters,
                                        includeIntroCell)
        narrativeObject = {
            'nbformat_minor': 0,
            'cells': cellData,
            'metadata': metadata,
            'nbformat': 4
        }
        metadataExternal = {}
        for key in metadata:
            value = metadata[key]
            if isinstance(value, str):
                metadataExternal[key] = value
            else:
                metadataExternal[key] = json.dumps(value)
        return [narrativeObject, metadataExternal]