Exemplo n.º 1
0
def get_schema(sim_type):
    if sim_type in _SCHEMA_CACHE:
        return _SCHEMA_CACHE[sim_type]
    schema = read_json(
        STATIC_FOLDER.join('json/{}-schema'.format(sim_type)))

    pkcollections.mapping_merge(schema, SCHEMA_COMMON)
    pkcollections.mapping_merge(
        schema,
        {'feature_config': feature_config.for_sim_type(sim_type)},
    )
    schema.simulationType = sim_type
    _SCHEMA_CACHE[sim_type] = schema

    #TODO(mvk): improve merging common and local schema
    _merge_dicts(schema.common.dynamicFiles, schema.dynamicFiles)
    schema.dynamicModules = _files_in_schema(schema.dynamicFiles)

    for item in ['appModes', 'constants', 'cookies', 'enum', 'notifications', 'localRoutes', 'model', 'view']:
        if item not in schema:
            schema[item] = pkcollections.Dict()
        _merge_dicts(schema.common[item], schema[item])
        _merge_subclasses(schema, item)
    srschema.validate(schema)
    return schema
Exemplo n.º 2
0
def get_schema(sim_type):
    """Get the schema for `sim_type`

    If sim_type is None, it will return the schema for the first sim_type
    in `feature_config.cfg().sim_types`

    Args:
        sim_type (str): must be valid
    Returns:
        dict: Shared schem

    """
    t = sirepo.template.assert_sim_type(sim_type) if sim_type is not None \
        else list(feature_config.cfg().sim_types)[0]
    if t in _SCHEMA_CACHE:
        return _SCHEMA_CACHE[t]
    schema = read_json(
        STATIC_FOLDER.join('json/{}-schema'.format(t)))
    schema.update(SCHEMA_COMMON)
    schema.update(
        feature_config=feature_config.for_sim_type(t)
    )
    schema.feature_config = feature_config.for_sim_type(t)
    schema.simulationType = t
    _SCHEMA_CACHE[t] = schema

    #TODO(mvk): improve merging common and local schema
    _merge_dicts(schema.common.dynamicFiles, schema.dynamicFiles)
    schema.dynamicModules = _files_in_schema(schema.dynamicFiles)

    for item in [
            'appDefaults',
            'appModes',
            'constants',
            'cookies',
            'enum',
            'notifications',
            'localRoutes',
            'model',
            'strings',
            'view',
    ]:
        if item not in schema:
            schema[item] = PKDict()
        _merge_dicts(schema.common[item], schema[item])
        _merge_subclasses(schema, item)
    srschema.validate(schema)
    return schema