def output(json_schema_repo, output_path, result_path, output_type, output_panel_id): """Generate outputs based on calculation result""" result_json_data = json.decode_file(result_path) json_schema_repo.validate('opcut://result.yaml#', result_json_data) result = common.json_data_to_result(result_json_data) output_bytes = opcut.output.generate_output(result, output_type, output_panel_id) with open(output_path, 'wb') as f: f.write(output_bytes)
def main(): aio.init_asyncio() args = _create_parser().parse_args() conf = json.decode_file(args.conf) common.json_schema_repo.validate('hat://monitor/main.yaml#', conf) logging.config.dictConfig(conf['log']) with contextlib.suppress(asyncio.CancelledError): aio.run_asyncio(async_main(conf, args.ui_path))
def calculate(json_schema_repo, params_path, method, result_path, output_path, output_type, output_panel_id): """Calculate result and generate outputs""" params_json_data = json.decode_file(params_path) opcut.json_validator.validate('opcut://params.yaml#', params_json_data) params = common.json_data_to_params(params_json_data) result = opcut.csp.calculate(params, method) result_json_data = common.result_to_json_data(result) json.encode_file(result_json_data, result_path) if output_path: output(json_schema_repo, output_path, result_path, output_type, output_panel_id)
def _ext_get_view(view, json_schema_repo): data = {} view_path = util.parse_env_path(view['view_path']) try: for i in view_path.rglob('*'): if i.is_dir(): continue name = i.relative_to(view_path).as_posix() if i.suffix in {'.js', '.css', '.txt'}: with open(i, encoding='utf-8') as f: content = f.read() elif i.suffix in {'.json', '.yaml', '.yml'}: content = json.decode_file(i) elif i.suffix in {'.xml', '.svg'}: with open(i, encoding='utf-8') as f: content = hat.gui.vt.parse(f) else: with open(i, 'rb') as f: content = f.read() content = base64.b64encode(content).decode('utf-8') data[name] = content except Exception as e: mlog.error('error loading view data %s', e, exc_info=e) raise conf = None if view['conf_path'] is not None: conf_path = util.parse_env_path(view['conf_path']) conf = json.decode_file(conf_path) schema = util.first(v for k, v in data.items() if k in {'schema.json', 'schema.yaml', 'schema.yml'}) if schema: repo = json.SchemaRepository(json_schema_repo, schema) repo.validate(schema['id'], conf) return View(name=view['name'], conf=conf, data=data)
def main(): """Main""" aio.init_asyncio() args = create_parser().parse_args() conf = json.decode_file(args.conf) json_schema_repo = json.SchemaRepository( hat.gui.common.json_schema_repo, *args.additional_json_schemas_paths) json_schema_repo.validate('hat://gui/main.yaml#', conf) for adapter_conf in conf['adapters']: module = importlib.import_module(adapter_conf['module']) json_schema_id = module.json_schema_id if json_schema_id: json_schema_repo.validate(json_schema_id, adapter_conf) logging.config.dictConfig(conf['log']) with contextlib.suppress(asyncio.CancelledError): aio.run_asyncio(async_main(conf, args.ui_path, json_schema_repo))
def from_json(data): """Create new repository from content exported as json serializable data. Creates a new repository from content of another repository that was exported by using :meth:`Repository.to_json`. Args: data (Union[pathlib.PurePath,Data]): repository data Returns: Repository """ if isinstance(data, pathlib.PurePath): data = json.decode_file(data) repo = Repository() repo._modules = [parser.module_from_json(i) for i in data] repo._refs = evaluator.evaluate_modules(repo._modules) return repo
def main(): """Main""" aio.init_asyncio() args = _create_parser().parse_args() conf = json.decode_file(args.conf) json_schema_repo = json.SchemaRepository( hat.event.common.json_schema_repo, *args.additional_json_schemas_paths) json_schema_repo.validate('hat://event/main.yaml#', conf) sub_confs = ([conf['backend_engine']['backend']] + conf['module_engine']['modules']) for sub_conf in sub_confs: module = importlib.import_module(sub_conf['module']) json_schema_id = module.json_schema_id if json_schema_id: json_schema_repo.validate(json_schema_id, sub_conf) logging.config.dictConfig(conf['log']) with contextlib.suppress(asyncio.CancelledError): aio.run_asyncio(async_main(conf))
def main(): """Application main entry point""" args = _create_parser().parse_args() json_schema_repo = json.SchemaRepository(json.default_schemas_json_path, args.schemas_json_path) if args.log_conf_path: log_conf = json.decode_file(args.log_conf_path) json_schema_repo.validate('hat://logging.yaml#', log_conf) logging.config.dictConfig(log_conf) if args.action == 'calculate': calculate(json_schema_repo, args.params_path, args.method, args.result_path, args.output_path, args.output_type, args.output_panel_id, args.output_path) elif args.action == 'output': output(json_schema_repo, args.output_path, args.result_path, args.output_type, args.output_panel_id, args.output_path) else: server(json_schema_repo, args.addr, args.pem_path, args.ui_path)