def client(config, message, to_server): with open(config) as f: config = YAML().load(f) if not to_server in config.keys(): print("You are trying to send to a server that does not exit.") sys.exit(1) socket = ClientObjectSocket.get_cosclient(config[to_server]["port"]) socket.send_object(Message(message, 666, to_server))
def load_config(): """ Load engine.vars values from 'config.yaml'. If the value is not defined, the default values are used instead. For info about the variables that can be modified see the docs inside the config.yaml file. """ data = YAML().load(engine.vars.CONFIG_PATH) if data is None: return for key in data.keys(): if key == 'program_name': engine.vars.PROGRAM_NAME = data[key] elif key == 'screen_size': engine.vars.SCREEN_SIZE = data[key] elif key == 'flush_color': engine.vars.FLUSH_COLOR = data[key] elif key == 'frame_rate': engine.vars.FRAME_RATE = data[key] elif key == 'first_scene': engine.vars.FIRST_SCENE = data[key] else: raise ValueError(f'Invalid key {key} in config file')
def generate_cbr_process_collection( cbr_process_config: Dict[str, str], common_config: Dict[str, str], build_params: Dict[str, str], ) -> Tuple[Tuple[str, str]]: r""" Build the collection of CBR Process Schemas. Generates and writes into files the CBR Process Schemas from a collection of CBP files, which are under the directory specified by the :code:`cbr_process.cbp_dir` property from the build configuration file. The routes to the JSON Schema definitions of the different :code:`type`\ s referred by the CBP documents are detailed in the configuration file under the path given by the :code:`cbr_process.types_path` property. :param cbr_process_config: The :code:`cbr_process` configuration block. :type cbr_process_config: Dict[str, str] :param common_config: The :code:`common` configuration block. :type common_config: Dict[str, str] :param build_params: The :code:`build_params` configuration block. :type build_params: Dict[str, str] :return: A tuple of tuples that represent the collection of CBR Process Schemas. Each sub-tuple has two elements: a rendered JSON Schema representing either the CBR Process Schema as first element, and the path where the schema is to be located as second element. :rtype: Tuple[Tuple[str, str]] """ def build_ref(type_entry): if type_entry["ns"] == "common": defs_path = common_config["defs_path"] elif type_entry["ns"] == "cbr_process": defs_path = cbr_process_config["defs_path"] return uritools.urijoin( _build_rel_path( os.path.join(cbr_process_config["cbr_process_collection_dir"], "dummy"), defs_path, build_params["root_build_dir"], ), f"#{type_entry['def']}", ) with open(cbr_process_config["types_path"]) as file: types = YAML().load(file) defs = {i: build_ref(types[i]) for i in types.keys()} cbp_filenames = tuple( filter( lambda filename: os.path.splitext(filename)[1] == ".cbp", os.listdir(cbr_process_config["cbp_dir"]), )) cbr_processes = {} for cbp_filename in cbp_filenames: with open(os.path.join(cbr_process_config["cbp_dir"], cbp_filename)) as file: cbp = json.load(file, object_pairs_hook=OrderedDict) if cbp["data"]["processType"] == "generic": cbr_processes[os.path.join( cbr_process_config["cbr_process_collection_dir"], cbp_filename.rsplit("-", 1)[0] + ".json", )] = cbp return tuple(( generate_cbr_process_collection_item( cbp, defs, common_config["json_schema_uri"], _build_abs_schema_uri(schema_path, common_config["cb_schemas_base_url"]), ), os.path.join( uritools.urisplit(build_params["root_build_dir"]).path, schema_path), ) for schema_path, cbp in cbr_processes.items())