Пример #1
0
def _list(_org_label, _prj_label, deprecated, _from, size, search, _json,
          pretty):
    _org_label = utils.get_organization_label(_org_label)
    _prj_label = utils.get_project_label(_prj_label)
    nxs = utils.get_nexus_client()
    try:
        response = nxs.schemas.list(org_label=_org_label,
                                    project_label=_prj_label,
                                    pagination_from=_from,
                                    pagination_size=size,
                                    deprecated=deprecated,
                                    full_text_search_query=search)
        if _json:
            utils.print_json(response, colorize=pretty)
        else:
            columns = [
                'Id', 'Types', 'Label', 'Imports', 'NodeShapes',
                'PropertyShapes', 'Revision', 'Deprecated'
            ]
            table = PrettyTable(columns)
            for c in columns:
                table.align[c] = "l"

            for r in response["_results"]:
                types = utils.format_json_field(r, "@type")

                # Get extra info from the schema itself
                schema = nxs.schemas.fetch(org_label=_org_label,
                                           project_label=_prj_label,
                                           schema_id=r["@id"])
                imports = utils.format_json_field(schema, "imports")
                node_shapes = get_shapes_id_by_node_kind(
                    schema, ["sh:NodeShape", "NodeShape"])
                property_shapes = get_shapes_id_by_node_kind(
                    schema, ["sh:PropertyShapes", "PropertyShapes"])
                dummy_payload = {
                    "nodes": node_shapes,
                    "properties": property_shapes
                }
                nodes = utils.format_json_field(dummy_payload, "nodes")
                properties = utils.format_json_field(dummy_payload,
                                                     "properties")
                label = ""
                if "label" in schema:
                    label = schema["label"]

                table.add_row([
                    r["@id"], types, label, imports, nodes, properties,
                    r["_rev"], r["_deprecated"]
                ])
            print(table)
    except nxs.HTTPError as e:
        utils.print_json(e.response.json(), colorize=True)
        utils.error(str(e))
Пример #2
0
def _list(_org_label, _prj_label, deprecated, _from, size, _type, _json,
          pretty):
    _org_label = utils.get_organization_label(_org_label)
    _prj_label = utils.get_project_label(_prj_label)
    nxs = utils.get_nexus_client()
    try:
        response = nxs.views.list(org_label=_org_label,
                                  project_label=_prj_label,
                                  pagination_from=_from,
                                  pagination_size=size,
                                  deprecated=deprecated,
                                  type=_type)
        if _json:
            utils.print_json(response, colorize=pretty)
        else:
            table = PrettyTable(['Id', 'Type', 'Revision', 'Deprecated'])
            table.align["Id"] = "l"
            table.align["Type"] = "l"
            table.align["Revision"] = "l"
            table.align["Deprecated"] = "l"
            for r in response["_results"]:
                types = utils.format_json_field(r, "@type")
                table.add_row([r["@id"], types, r["_rev"], r["_deprecated"]])
            print(table)
    except nxs.HTTPError as e:
        utils.error(str(e))
        utils.print_json(e.response.json(), colorize=True)