def load_table_info(): """ Load tables from the config/tableConfig.json file. """ table_sections = [] data = read_contents_from_file(TABLE_CONFIG_FILE) for table_info in data.get("tableParts"): table_sections.append( TableSection(int(table_info.get("id")), int(table_info.get("type")), tuple(table_info.get("startPosition")))) return table_sections
def load_table_info(): """ Load tables from the config/tableConfig.json file. """ table_connection_ids = {} table_sections = [] data = read_contents_from_file(TABLE_CONFIG_FILE) for table_info in data.get("tableParts"): for side, connection_id in table_info.get("connections").iteritems(): table_connection_ids[connection_id] = { "table_id": table_info.get("id"), "side": Side.str_to_enum(side) } table_sections.append( TableSection(int(table_info.get("id")), int(table_info.get("type")))) return table_sections, table_connection_ids
def load_module_info(): """ Read and return modules from the config/moduleConfig.json file. """ data = read_contents_from_file(MODULE_CONFIG_FILE) modules = [] # Load all configuration types config_types = [ ModuleConfigurationType( # id, name, min_value, max_value, role, voltage config["id"], config["name"], config["min"], config["max"], Roles.str_to_enum(config["role"]), Voltages.str_to_enum(config["voltage"])) for config in data["configTypes"] ] for c in config_types: log('config', c) # Load default modules for module in data["modules"]: # Create a list of module configurations module_configs = [ ModuleConfiguration( # config_type, value next((t for t in config_types if t.id == mc["type"])), mc["value"]) for mc in module["configurations"] ] # Create the module module = DefaultModule( # id, name, voltage, configurations module["id"], module["name"], Voltages.str_to_enum(module["voltage"]), module_configs) modules.append(module) # Load transformer modules for module in data["transformers"]: # Get linked transformer linked = next((m for m in modules if m.id == module["linked"]), None) # Create the module module = TransformerModule( # id, name, voltage, linked module module["id"], module["name"], Voltages.str_to_enum(module["voltage"]), linked) modules.append(module) # Load transformer modules for module in data["wireModules"]: # Get linked transformer linked = next((m for m in modules if m.id == module["linked"]), None) # Create the module module = WireModule( # id, name, voltage, linked module module["id"], module["name"], Voltages.str_to_enum(module["voltage"]), linked) modules.append(module) # Load transformer modules for module in data["importModules"]: # Create the module module = ImportExportModule( # id, name, voltage module["id"], module["name"], Voltages.str_to_enum(module["voltage"])) modules.append(module) [log('loaded module:', module) for module in modules] return modules