Commit 6c4ae64a authored by Mantas Zimnickas's avatar Mantas Zimnickas

Script to list whole manifest schema

parent f7672b0c
Pipeline #95364249 passed with stage
in 2 minutes and 52 seconds
#!/usr/bin/env python
import click
from spinta import commands
from spinta import components
from spinta.config import create_context
@click.option('--option', '-o', multiple=True, help='Set configuration option, example: `-o`.')
def main(option):
context = create_context(cli_args=option)
store = context.get('store')
manifest = store.manifests['default']
def _traverse_namespaces(ns: components.Namespace, level: int = 0):
if level > 0:
_list_properties(ns, level)
for name in ns.names.values():
print(' ' * level, name.title + '/')
_traverse_namespaces(name, level + 1)
def _list_properties(ns: components.Namespace, level: int):
props = {}
for model in (ns.models or {}).values():
for prop in ( or {}).values():
if not in props:
props[] = {}
specifier = model.model_specifier()
if specifier not in props[]:
props[][specifier] = []
for prop, models in props.items():
types = ' | '.join(set( for model in models.values() for p in model))
model = 'yes' if '' in models else 'no'
datasets = sum(1 for x in models if x)
prop = ' ' * level + ' - ' + prop
ref = _get_ref_object(models)
print(f'{prop:42} model={model:<3} datasets={datasets:<2} type={types}{ref}')
def _get_ref_object(models):
for model in models.values():
for p in model:
if in ('ref', 'backref') and p.dtype.object:
return f' ref={p.dtype.object}'
return ''
def _load_manifest(context: components.Context) -> None:
rc = context.get('config.raw')
config = context.set('config', components.Config())
store = context.set('store', components.Store())
commands.load(context, config, rc)
commands.check(context, config)
commands.load(context, store, rc)
commands.check(context, store)
if __name__ == "__main__":
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment