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
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]) _validate_schema(schema) return schema
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 # merge common models into app models common_models = schema['commonModels'] app_models = schema['model'] for model_Name in common_models: if model_Name not in app_models: app_models[model_Name] = common_models[model_Name] for model_field_name in common_models[model_Name]: if model_field_name not in app_models[model_Name]: app_models[model_Name][model_field_name] = common_models[ model_Name][model_field_name] # merge common enums into app models common_enums = schema['commonEnums'] app_enums = schema['enum'] for enum_Name in common_enums: if enum_Name not in app_enums: app_enums[enum_Name] = common_enums[enum_Name] # merge common views into app views - since these can be deeply nested, for now merge only # the title, basic fields, and top level of advanced fields common_views = schema['commonViews'] app_views = schema['view'] for view_Name in common_views: if view_Name not in app_views: app_views[view_Name] = common_views[view_Name] if 'title' not in app_views[view_Name] and 'title' in common_views[ view_Name]: app_views[view_Name]['title'] = common_views[view_Name]['title'] if 'basic' not in app_views[view_Name] and 'basic' in common_views[ view_Name]: for basic_field in common_views[view_Name]['basic']: if basic_field not in app_views[view_Name]['basic']: app_views[view_Name]['basic'][basic_field] = basic_field if 'advanced' in common_views[view_Name]: for advanced_field in common_views[view_Name]['advanced']: # ignore arrays if isinstance( advanced_field, basestring ) and advanced_field not in app_views[view_Name]['advanced']: app_views[view_Name]['advanced'].append(advanced_field) return schema
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 return schema
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 return schema
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 # merge common local routes into app local routes util.merge_dicts(schema['commonLocalRoutes'], schema['localRoutes'], 2) if 'appModes' not in schema: schema['appModes'] = {} util.merge_dicts(schema['commonAppModes'], schema['appModes'], 1) # merge common models into app models util.merge_dicts(schema['commonModels'], schema['model'], 2) # merge common enums into app models util.merge_dicts(schema['commonEnums'], schema['enum'], 1) # merge common views into app views - since these can be deeply nested, for now merge only # the title, basic fields, and top level of advanced fields common_views = schema['commonViews'] app_views = schema['view'] util.merge_dicts(common_views, app_views, 1) for view_Name in common_views: if 'title' not in app_views[view_Name] and 'title' in common_views[ view_Name]: app_views[view_Name]['title'] = common_views[view_Name]['title'] if 'basic' not in app_views[view_Name] and 'basic' in common_views[ view_Name]: for basic_field in common_views[view_Name]['basic']: if basic_field not in app_views[view_Name]['basic']: app_views[view_Name]['basic'][basic_field] = basic_field if 'advanced' in common_views[view_Name]: for advanced_field in common_views[view_Name]['advanced']: # ignore arrays if isinstance( advanced_field, basestring ) and advanced_field not in app_views[view_Name]['advanced']: app_views[view_Name]['advanced'].append(advanced_field) _validate_schema(schema) return schema
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]) _validate_schema(schema) return schema